jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 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 | |
| 11 | #include "base/callback_forward.h" |
| 12 | #include "base/compiler_specific.h" |
| 13 | #include "base/files/file_path.h" |
| 14 | #include "base/macros.h" |
| 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" |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 20 | #include "components/version_info/version_info.h" |
Helen Li | 5f3d96a | 2018-08-10 20:37:24 | [diff] [blame] | 21 | #include "services/network/public/mojom/proxy_resolving_socket.mojom.h" |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 22 | |
| 23 | class PrefService; |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 24 | |
| 25 | namespace base { |
| 26 | class SequencedTaskRunner; |
| 27 | } |
| 28 | |
Colin Blundell | 354f221 | 2018-07-16 14:45:08 | [diff] [blame] | 29 | namespace identity { |
| 30 | class IdentityManager; |
| 31 | } |
| 32 | |
Mark Pilgrim | 7634f5b5 | 2018-06-27 19:53:27 | [diff] [blame] | 33 | namespace network { |
Robbie McElrath | b0149933 | 2018-09-25 00:53:13 | [diff] [blame^] | 34 | class NetworkConnectionTracker; |
Mark Pilgrim | 7634f5b5 | 2018-06-27 19:53:27 | [diff] [blame] | 35 | class SharedURLLoaderFactory; |
| 36 | } |
| 37 | |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 38 | namespace gcm { |
| 39 | |
| 40 | class GCMClientFactory; |
| 41 | class GCMDriver; |
| 42 | |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 43 | // Providing GCM service, via GCMDriver. |
| 44 | class GCMProfileService : public KeyedService { |
| 45 | public: |
Helen Li | 5f3d96a | 2018-08-10 20:37:24 | [diff] [blame] | 46 | using GetProxyResolvingFactoryCallback = base::RepeatingCallback<void( |
| 47 | network::mojom::ProxyResolvingSocketFactoryRequest)>; |
| 48 | |
ralphnathan | ed5c0e0 | 2017-06-14 20:54:56 | [diff] [blame] | 49 | #if BUILDFLAG(USE_GCM_FROM_PLATFORM) |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 50 | GCMProfileService( |
| 51 | base::FilePath path, |
| 52 | scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner); |
| 53 | #else |
| 54 | GCMProfileService( |
| 55 | PrefService* prefs, |
| 56 | base::FilePath path, |
Helen Li | 5f3d96a | 2018-08-10 20:37:24 | [diff] [blame] | 57 | base::RepeatingCallback< |
| 58 | void(base::WeakPtr<GCMProfileService>, |
| 59 | network::mojom::ProxyResolvingSocketFactoryRequest)> |
| 60 | get_socket_factory_callback, |
Mark Pilgrim | 7634f5b5 | 2018-06-27 19:53:27 | [diff] [blame] | 61 | scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, |
Robbie McElrath | b0149933 | 2018-09-25 00:53:13 | [diff] [blame^] | 62 | network::NetworkConnectionTracker* network_connection_tracker, |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 63 | version_info::Channel channel, |
johnme | 627dc8c7 | 2016-08-19 21:49:39 | [diff] [blame] | 64 | const std::string& product_category_for_subtypes, |
Colin Blundell | 354f221 | 2018-07-16 14:45:08 | [diff] [blame] | 65 | identity::IdentityManager* identity_manager, |
dcheng | a77e28eb | 2016-04-21 21:34:37 | [diff] [blame] | 66 | std::unique_ptr<GCMClientFactory> gcm_client_factory, |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 67 | const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner, |
| 68 | const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, |
| 69 | scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner); |
| 70 | #endif |
| 71 | ~GCMProfileService() override; |
| 72 | |
| 73 | // Returns whether GCM is enabled. |
| 74 | static bool IsGCMEnabled(PrefService* prefs); |
| 75 | |
| 76 | // KeyedService: |
| 77 | void Shutdown() override; |
| 78 | |
Peter Beverloo | 3413946 | 2018-04-10 14:18:06 | [diff] [blame] | 79 | // For testing purposes. |
| 80 | void SetDriverForTesting(std::unique_ptr<GCMDriver> driver); |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 81 | |
| 82 | GCMDriver* driver() const { return driver_.get(); } |
| 83 | |
| 84 | protected: |
| 85 | // Used for constructing fake GCMProfileService for testing purpose. |
| 86 | GCMProfileService(); |
| 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) |
Colin Blundell | 354f221 | 2018-07-16 14:45:08 | [diff] [blame] | 92 | identity::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 | |
| 96 | // Used for both account tracker and GCM.UserSignedIn UMA. |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 97 | class IdentityObserver; |
dcheng | a77e28eb | 2016-04-21 21:34:37 | [diff] [blame] | 98 | std::unique_ptr<IdentityObserver> identity_observer_; |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 99 | #endif |
| 100 | |
Helen Li | 5f3d96a | 2018-08-10 20:37:24 | [diff] [blame] | 101 | GetProxyResolvingFactoryCallback get_socket_factory_callback_; |
| 102 | |
| 103 | // WeakPtr generated by the factory must be dereferenced on the UI thread. |
| 104 | base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_{this}; |
| 105 | |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 106 | DISALLOW_COPY_AND_ASSIGN(GCMProfileService); |
| 107 | }; |
| 108 | |
| 109 | } // namespace gcm |
| 110 | |
| 111 | #endif // COMPONENTS_GCM_DRIVER_GCM_PROFILE_SERVICE_H_ |
| 112 | |