Xinglong Luan | acb2f9b | 2023-09-05 23:47:13 | [diff] [blame] | 1 | // 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 Young | 4613fef30 | 2023-10-10 17:27:32 | [diff] [blame] | 5 | #ifndef COMPONENTS_MANTA_ORCA_PROVIDER_H_ |
| 6 | #define COMPONENTS_MANTA_ORCA_PROVIDER_H_ |
Xinglong Luan | acb2f9b | 2023-09-05 23:47:13 | [diff] [blame] | 7 | |
| 8 | #include <map> |
| 9 | #include <memory> |
| 10 | #include <string> |
| 11 | #include <vector> |
| 12 | |
Jeffrey Young | 4613fef30 | 2023-10-10 17:27:32 | [diff] [blame] | 13 | #include "base/component_export.h" |
Xinglong Luan | acb2f9b | 2023-09-05 23:47:13 | [diff] [blame] | 14 | #include "base/memory/scoped_refptr.h" |
| 15 | #include "base/memory/weak_ptr.h" |
Jeffrey Young | a35ef42 | 2023-10-16 20:48:58 | [diff] [blame] | 16 | #include "base/scoped_observation.h" |
Xinglong Luan | acb2f9b | 2023-09-05 23:47:13 | [diff] [blame] | 17 | #include "components/endpoint_fetcher/endpoint_fetcher.h" |
Xinglong Luan | bb0b0b1 | 2024-03-14 10:32:53 | [diff] [blame] | 18 | #include "components/manta/base_provider.h" |
Jeffrey Young | 4613fef30 | 2023-10-10 17:27:32 | [diff] [blame] | 19 | #include "components/manta/manta_service_callbacks.h" |
Xinglong Luan | 321e867 | 2024-06-12 04:29:55 | [diff] [blame] | 20 | #include "components/manta/provider_params.h" |
Jeffrey Young | a35ef42 | 2023-10-16 20:48:58 | [diff] [blame] | 21 | #include "components/signin/public/identity_manager/identity_manager.h" |
Xinglong Luan | acb2f9b | 2023-09-05 23:47:13 | [diff] [blame] | 22 | #include "services/network/public/cpp/shared_url_loader_factory.h" |
| 23 | #include "url/gurl.h" |
| 24 | |
Xinglong Luan | acb2f9b | 2023-09-05 23:47:13 | [diff] [blame] | 25 | namespace manta { |
| 26 | |
Xinglong Luan | acb2f9b | 2023-09-05 23:47:13 | [diff] [blame] | 27 | // 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 Young | a35ef42 | 2023-10-16 20:48:58 | [diff] [blame] | 29 | // IMPORTANT: This class depends on `IdentityManager`. |
| 30 | // `OrcaProvider::Call` will return an empty response after `IdentityManager` |
| 31 | // destruction. |
Xinglong Luan | bb0b0b1 | 2024-03-14 10:32:53 | [diff] [blame] | 32 | class COMPONENT_EXPORT(MANTA) OrcaProvider : virtual public BaseProvider { |
Xinglong Luan | acb2f9b | 2023-09-05 23:47:13 | [diff] [blame] | 33 | 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 Luan | 013939e | 2024-04-02 05:06:10 | [diff] [blame] | 38 | signin::IdentityManager* identity_manager, |
Xinglong Luan | 321e867 | 2024-06-12 04:29:55 | [diff] [blame] | 39 | const ProviderParams& provider_params); |
Xinglong Luan | acb2f9b | 2023-09-05 23:47:13 | [diff] [blame] | 40 | |
| 41 | OrcaProvider(const OrcaProvider&) = delete; |
| 42 | OrcaProvider& operator=(const OrcaProvider&) = delete; |
| 43 | |
Jeffrey Young | a35ef42 | 2023-10-16 20:48:58 | [diff] [blame] | 44 | ~OrcaProvider() override; |
Xinglong Luan | acb2f9b | 2023-09-05 23:47:13 | [diff] [blame] | 45 | |
| 46 | // Calls the google service endpoint with the http POST request payload |
| 47 | // populated with the `input` parameters. |
Xinglong Luan | 3414683 | 2023-09-20 23:59:42 | [diff] [blame] | 48 | // The fetched response is processed and returned to the caller via an |
| 49 | // `MantaGenericCallback` callback. |
Xinglong Luan | 013939e | 2024-04-02 05:06:10 | [diff] [blame] | 50 | // 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 Luan | acb2f9b | 2023-09-05 23:47:13 | [diff] [blame] | 53 | void Call(const std::map<std::string, std::string>& input, |
Xinglong Luan | 3414683 | 2023-09-20 23:59:42 | [diff] [blame] | 54 | MantaGenericCallback done_callback); |
Xinglong Luan | acb2f9b | 2023-09-05 23:47:13 | [diff] [blame] | 55 | |
| 56 | private: |
| 57 | friend class FakeOrcaProvider; |
| 58 | |
Xinglong Luan | acb2f9b | 2023-09-05 23:47:13 | [diff] [blame] | 59 | base::WeakPtrFactory<OrcaProvider> weak_ptr_factory_{this}; |
| 60 | }; |
| 61 | |
| 62 | } // namespace manta |
| 63 | |
Jeffrey Young | 4613fef30 | 2023-10-10 17:27:32 | [diff] [blame] | 64 | #endif // COMPONENTS_MANTA_ORCA_PROVIDER_H_ |