blob: f73eb9c39bddcf72729129991d39e0deab618066 [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"
Xinglong Luan321e8672024-06-12 04:29:5520#include "components/manta/provider_params.h"
Jeffrey Younga35ef422023-10-16 20:48:5821#include "components/signin/public/identity_manager/identity_manager.h"
Xinglong Luanacb2f9b2023-09-05 23:47:1322#include "services/network/public/cpp/shared_url_loader_factory.h"
23#include "url/gurl.h"
24
Xinglong Luanacb2f9b2023-09-05 23:47:1325namespace manta {
26
Xinglong Luanacb2f9b2023-09-05 23:47:1327// The Orca provider for the Manta project. Provides a method for clients to
28// call the relevant google API, handling OAuth and http fetching.
Jeffrey Younga35ef422023-10-16 20:48:5829// IMPORTANT: This class depends on `IdentityManager`.
30// `OrcaProvider::Call` will return an empty response after `IdentityManager`
31// destruction.
Xinglong Luanbb0b0b12024-03-14 10:32:5332class COMPONENT_EXPORT(MANTA) OrcaProvider : virtual public BaseProvider {
Xinglong Luanacb2f9b2023-09-05 23:47:1333 public:
34 // Returns a `OrcaProvider` instance tied to the profile of the passed
35 // arguments.
36 OrcaProvider(
37 scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
Xinglong Luan013939e2024-04-02 05:06:1038 signin::IdentityManager* identity_manager,
Xinglong Luan321e8672024-06-12 04:29:5539 const ProviderParams& provider_params);
Xinglong Luanacb2f9b2023-09-05 23:47:1340
41 OrcaProvider(const OrcaProvider&) = delete;
42 OrcaProvider& operator=(const OrcaProvider&) = delete;
43
Jeffrey Younga35ef422023-10-16 20:48:5844 ~OrcaProvider() override;
Xinglong Luanacb2f9b2023-09-05 23:47:1345
46 // Calls the google service endpoint with the http POST request payload
47 // populated with the `input` parameters.
Xinglong Luan34146832023-09-20 23:59:4248 // The fetched response is processed and returned to the caller via an
49 // `MantaGenericCallback` callback.
Xinglong Luan013939e2024-04-02 05:06:1050 // In demo mode, it uses the Google API key for authentication, otherwise uses
51 // `IdentityManager`, in this case it will give an empty response if
52 // `IdentityManager` is no longer valid.
Xinglong Luanacb2f9b2023-09-05 23:47:1353 void Call(const std::map<std::string, std::string>& input,
Xinglong Luan34146832023-09-20 23:59:4254 MantaGenericCallback done_callback);
Xinglong Luanacb2f9b2023-09-05 23:47:1355
56 private:
57 friend class FakeOrcaProvider;
58
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_