blob: a95c1ef60461b9cd084c78ad41d28d55c99d68d7 [file] [log] [blame]
Xinglong Luanacb2f9b2023-09-05 23:47:131// Copyright 2023 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Jeffrey Young4613fef302023-10-10 17:27:325#ifndef COMPONENTS_MANTA_ORCA_PROVIDER_H_
6#define COMPONENTS_MANTA_ORCA_PROVIDER_H_
Xinglong Luanacb2f9b2023-09-05 23:47:137
8#include <map>
9#include <memory>
10#include <string>
11#include <vector>
12
Jeffrey Young4613fef302023-10-10 17:27:3213#include "base/component_export.h"
Xinglong Luanacb2f9b2023-09-05 23:47:1314#include "base/memory/scoped_refptr.h"
15#include "base/memory/weak_ptr.h"
Jeffrey Younga35ef422023-10-16 20:48:5816#include "base/scoped_observation.h"
Xinglong Luanacb2f9b2023-09-05 23:47:1317#include "components/endpoint_fetcher/endpoint_fetcher.h"
Xinglong Luanbb0b0b12024-03-14 10:32:5318#include "components/manta/base_provider.h"
Jeffrey Young4613fef302023-10-10 17:27:3219#include "components/manta/manta_service_callbacks.h"
Jeffrey Younga35ef422023-10-16 20:48:5820#include "components/signin/public/identity_manager/identity_manager.h"
Xinglong Luanacb2f9b2023-09-05 23:47:1321#include "services/network/public/cpp/shared_url_loader_factory.h"
22#include "url/gurl.h"
23
Xinglong Luanacb2f9b2023-09-05 23:47:1324namespace manta {
25
Xinglong Luanacb2f9b2023-09-05 23:47:1326// The Orca provider for the Manta project. Provides a method for clients to
27// call the relevant google API, handling OAuth and http fetching.
Jeffrey Younga35ef422023-10-16 20:48:5828// IMPORTANT: This class depends on `IdentityManager`.
29// `OrcaProvider::Call` will return an empty response after `IdentityManager`
30// destruction.
Xinglong Luanbb0b0b12024-03-14 10:32:5331class COMPONENT_EXPORT(MANTA) OrcaProvider : virtual public BaseProvider {
Xinglong Luanacb2f9b2023-09-05 23:47:1332 public:
33 // Returns a `OrcaProvider` instance tied to the profile of the passed
34 // arguments.
35 OrcaProvider(
36 scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
Xinglong Luan013939e2024-04-02 05:06:1037 signin::IdentityManager* identity_manager,
38 bool is_demo_mode);
Xinglong Luanacb2f9b2023-09-05 23:47:1339
40 OrcaProvider(const OrcaProvider&) = delete;
41 OrcaProvider& operator=(const OrcaProvider&) = delete;
42
Jeffrey Younga35ef422023-10-16 20:48:5843 ~OrcaProvider() override;
Xinglong Luanacb2f9b2023-09-05 23:47:1344
45 // Calls the google service endpoint with the http POST request payload
46 // populated with the `input` parameters.
Xinglong Luan34146832023-09-20 23:59:4247 // The fetched response is processed and returned to the caller via an
48 // `MantaGenericCallback` callback.
Xinglong Luan013939e2024-04-02 05:06:1049 // In demo mode, it uses the Google API key for authentication, otherwise uses
50 // `IdentityManager`, in this case it will give an empty response if
51 // `IdentityManager` is no longer valid.
Xinglong Luanacb2f9b2023-09-05 23:47:1352 void Call(const std::map<std::string, std::string>& input,
Xinglong Luan34146832023-09-20 23:59:4253 MantaGenericCallback done_callback);
Xinglong Luanacb2f9b2023-09-05 23:47:1354
55 private:
56 friend class FakeOrcaProvider;
57
Xinglong Luan013939e2024-04-02 05:06:1058 const bool is_demo_mode_;
Xinglong Luanacb2f9b2023-09-05 23:47:1359 base::WeakPtrFactory<OrcaProvider> weak_ptr_factory_{this};
60};
61
62} // namespace manta
63
Jeffrey Young4613fef302023-10-10 17:27:3264#endif // COMPONENTS_MANTA_ORCA_PROVIDER_H_