Avi Drissman | 8ba1bad | 2022-09-13 19:22:36 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef COMPONENTS_GCM_DRIVER_GCM_PROFILE_SERVICE_H_ |
| 6 | #define COMPONENTS_GCM_DRIVER_GCM_PROFILE_SERVICE_H_ |
| 7 | |
dcheng | a77e28eb | 2016-04-21 21:34:37 | [diff] [blame] | 8 | #include <memory> |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 9 | #include <string> |
| 10 | |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 11 | #include "base/compiler_specific.h" |
| 12 | #include "base/files/file_path.h" |
Avi Drissman | 12be031 | 2023-01-11 09:16:09 | [diff] [blame] | 13 | #include "base/functional/callback_forward.h" |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 14 | #include "base/memory/raw_ptr.h" |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 15 | #include "base/memory/ref_counted.h" |
Helen Li | 5f3d96a | 2018-08-10 20:37:24 | [diff] [blame] | 16 | #include "base/memory/weak_ptr.h" |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 17 | #include "build/build_config.h" |
Scott Violet | 9ae8289 | 2018-03-01 18:38:12 | [diff] [blame] | 18 | #include "components/gcm_driver/gcm_buildflags.h" |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 19 | #include "components/keyed_service/core/keyed_service.h" |
Takuto Ikuta | 35b64c8 | 2023-10-25 09:54:17 | [diff] [blame] | 20 | #include "components/version_info/channel.h" |
Julie Jeongeun Kim | 17b2adf1 | 2019-10-29 10:24:48 | [diff] [blame] | 21 | #include "mojo/public/cpp/bindings/pending_receiver.h" |
Helen Li | 5f3d96a | 2018-08-10 20:37:24 | [diff] [blame] | 22 | #include "services/network/public/mojom/proxy_resolving_socket.mojom.h" |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 23 | |
| 24 | class PrefService; |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 25 | |
| 26 | namespace base { |
| 27 | class SequencedTaskRunner; |
| 28 | } |
| 29 | |
Miyoung Shin | 23737f6 | 2019-07-23 15:43:31 | [diff] [blame] | 30 | namespace signin { |
Colin Blundell | 354f221 | 2018-07-16 14:45:08 | [diff] [blame] | 31 | class IdentityManager; |
| 32 | } |
| 33 | |
Mark Pilgrim | 7634f5b5 | 2018-06-27 19:53:27 | [diff] [blame] | 34 | namespace network { |
Robbie McElrath | b0149933 | 2018-09-25 00:53:13 | [diff] [blame] | 35 | class NetworkConnectionTracker; |
Mark Pilgrim | 7634f5b5 | 2018-06-27 19:53:27 | [diff] [blame] | 36 | class SharedURLLoaderFactory; |
| 37 | } |
| 38 | |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 39 | namespace gcm { |
| 40 | |
Rushan Suleymanov | b8013dd | 2023-10-12 12:38:41 | [diff] [blame] | 41 | class GCMAccountTracker; |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 42 | class GCMClientFactory; |
| 43 | class GCMDriver; |
| 44 | |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 45 | // Providing GCM service, via GCMDriver. |
| 46 | class GCMProfileService : public KeyedService { |
| 47 | public: |
Helen Li | 5f3d96a | 2018-08-10 20:37:24 | [diff] [blame] | 48 | using GetProxyResolvingFactoryCallback = base::RepeatingCallback<void( |
Julie Jeongeun Kim | 17b2adf1 | 2019-10-29 10:24:48 | [diff] [blame] | 49 | mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)>; |
Helen Li | 5f3d96a | 2018-08-10 20:37:24 | [diff] [blame] | 50 | |
ralphnathan | ed5c0e0 | 2017-06-14 20:54:56 | [diff] [blame] | 51 | #if BUILDFLAG(USE_GCM_FROM_PLATFORM) |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 52 | GCMProfileService( |
| 53 | base::FilePath path, |
Alex Chau | da2073d6 | 2020-01-29 11:26:08 | [diff] [blame] | 54 | scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner); |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 55 | #else |
| 56 | GCMProfileService( |
| 57 | PrefService* prefs, |
| 58 | base::FilePath path, |
Julie Jeongeun Kim | 17b2adf1 | 2019-10-29 10:24:48 | [diff] [blame] | 59 | base::RepeatingCallback<void( |
| 60 | base::WeakPtr<GCMProfileService>, |
| 61 | mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>)> |
Helen Li | 5f3d96a | 2018-08-10 20:37:24 | [diff] [blame] | 62 | get_socket_factory_callback, |
Mark Pilgrim | 7634f5b5 | 2018-06-27 19:53:27 | [diff] [blame] | 63 | scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, |
Robbie McElrath | b0149933 | 2018-09-25 00:53:13 | [diff] [blame] | 64 | network::NetworkConnectionTracker* network_connection_tracker, |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 65 | version_info::Channel channel, |
johnme | 627dc8c7 | 2016-08-19 21:49:39 | [diff] [blame] | 66 | const std::string& product_category_for_subtypes, |
Miyoung Shin | 23737f6 | 2019-07-23 15:43:31 | [diff] [blame] | 67 | signin::IdentityManager* identity_manager, |
dcheng | a77e28eb | 2016-04-21 21:34:37 | [diff] [blame] | 68 | std::unique_ptr<GCMClientFactory> gcm_client_factory, |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 69 | const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner, |
| 70 | const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, |
| 71 | scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner); |
| 72 | #endif |
Peter Boström | 09c0182 | 2021-09-20 22:43:27 | [diff] [blame] | 73 | |
| 74 | GCMProfileService(const GCMProfileService&) = delete; |
| 75 | GCMProfileService& operator=(const GCMProfileService&) = delete; |
| 76 | |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 77 | ~GCMProfileService() override; |
| 78 | |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 79 | // KeyedService: |
| 80 | void Shutdown() override; |
| 81 | |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 82 | GCMDriver* driver() const { return driver_.get(); } |
| 83 | |
| 84 | protected: |
| 85 | // Used for constructing fake GCMProfileService for testing purpose. |
Rushan Suleymanov | 79aba4e | 2023-01-23 18:14:16 | [diff] [blame] | 86 | explicit GCMProfileService(std::unique_ptr<GCMDriver> driver); |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 87 | |
| 88 | private: |
dcheng | a77e28eb | 2016-04-21 21:34:37 | [diff] [blame] | 89 | std::unique_ptr<GCMDriver> driver_; |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 90 | |
ralphnathan | ed5c0e0 | 2017-06-14 20:54:56 | [diff] [blame] | 91 | #if !BUILDFLAG(USE_GCM_FROM_PLATFORM) |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 92 | raw_ptr<signin::IdentityManager> identity_manager_; |
Colin Blundell | f878993 | 2018-05-22 11:35:56 | [diff] [blame] | 93 | |
Maks Orlovich | 8db7d0d6 | 2018-08-16 19:22:27 | [diff] [blame] | 94 | scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_; |
pkasting | d3b1a71 | 2016-05-20 21:20:12 | [diff] [blame] | 95 | |
Rushan Suleymanov | b8013dd | 2023-10-12 12:38:41 | [diff] [blame] | 96 | std::unique_ptr<GCMAccountTracker> gcm_account_tracker_; |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 97 | #endif |
| 98 | |
Helen Li | 5f3d96a | 2018-08-10 20:37:24 | [diff] [blame] | 99 | GetProxyResolvingFactoryCallback get_socket_factory_callback_; |
| 100 | |
| 101 | // WeakPtr generated by the factory must be dereferenced on the UI thread. |
| 102 | base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_{this}; |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | } // namespace gcm |
| 106 | |
| 107 | #endif // COMPONENTS_GCM_DRIVER_GCM_PROFILE_SERVICE_H_ |