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" |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 16 | #include "build/build_config.h" |
Scott Violet | 9ae8289 | 2018-03-01 18:38:12 | [diff] [blame] | 17 | #include "components/gcm_driver/gcm_buildflags.h" |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 18 | #include "components/keyed_service/core/keyed_service.h" |
Colin Blundell | f878993 | 2018-05-22 11:35:56 | [diff] [blame] | 19 | #include "components/signin/core/browser/profile_oauth2_token_service.h" |
Colin Blundell | dee2d72a | 2018-05-07 10:46:52 | [diff] [blame] | 20 | #include "components/signin/core/browser/signin_manager.h" |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 21 | #include "components/version_info/version_info.h" |
| 22 | |
| 23 | class PrefService; |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 24 | |
| 25 | namespace base { |
| 26 | class SequencedTaskRunner; |
| 27 | } |
| 28 | |
| 29 | namespace net { |
| 30 | class URLRequestContextGetter; |
| 31 | } |
| 32 | |
Mark Pilgrim | 7634f5b5 | 2018-06-27 19:53:27 | [diff] [blame^] | 33 | namespace network { |
| 34 | class SharedURLLoaderFactory; |
| 35 | } |
| 36 | |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 37 | namespace gcm { |
| 38 | |
| 39 | class GCMClientFactory; |
| 40 | class GCMDriver; |
| 41 | |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 42 | // Providing GCM service, via GCMDriver. |
| 43 | class GCMProfileService : public KeyedService { |
| 44 | public: |
ralphnathan | ed5c0e0 | 2017-06-14 20:54:56 | [diff] [blame] | 45 | #if BUILDFLAG(USE_GCM_FROM_PLATFORM) |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 46 | GCMProfileService( |
| 47 | base::FilePath path, |
| 48 | scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner); |
| 49 | #else |
| 50 | GCMProfileService( |
| 51 | PrefService* prefs, |
| 52 | base::FilePath path, |
| 53 | net::URLRequestContextGetter* request_context, |
Mark Pilgrim | 7634f5b5 | 2018-06-27 19:53:27 | [diff] [blame^] | 54 | scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 55 | version_info::Channel channel, |
johnme | 627dc8c7 | 2016-08-19 21:49:39 | [diff] [blame] | 56 | const std::string& product_category_for_subtypes, |
Colin Blundell | dee2d72a | 2018-05-07 10:46:52 | [diff] [blame] | 57 | SigninManagerBase* signin_manager, |
Colin Blundell | f878993 | 2018-05-22 11:35:56 | [diff] [blame] | 58 | ProfileOAuth2TokenService* token_service, |
dcheng | a77e28eb | 2016-04-21 21:34:37 | [diff] [blame] | 59 | std::unique_ptr<GCMClientFactory> gcm_client_factory, |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 60 | const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner, |
| 61 | const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, |
| 62 | scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner); |
| 63 | #endif |
| 64 | ~GCMProfileService() override; |
| 65 | |
| 66 | // Returns whether GCM is enabled. |
| 67 | static bool IsGCMEnabled(PrefService* prefs); |
| 68 | |
| 69 | // KeyedService: |
| 70 | void Shutdown() override; |
| 71 | |
Peter Beverloo | 3413946 | 2018-04-10 14:18:06 | [diff] [blame] | 72 | // For testing purposes. |
| 73 | void SetDriverForTesting(std::unique_ptr<GCMDriver> driver); |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 74 | |
| 75 | GCMDriver* driver() const { return driver_.get(); } |
| 76 | |
| 77 | protected: |
| 78 | // Used for constructing fake GCMProfileService for testing purpose. |
| 79 | GCMProfileService(); |
| 80 | |
| 81 | private: |
dcheng | a77e28eb | 2016-04-21 21:34:37 | [diff] [blame] | 82 | std::unique_ptr<GCMDriver> driver_; |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 83 | |
ralphnathan | ed5c0e0 | 2017-06-14 20:54:56 | [diff] [blame] | 84 | #if !BUILDFLAG(USE_GCM_FROM_PLATFORM) |
Colin Blundell | dee2d72a | 2018-05-07 10:46:52 | [diff] [blame] | 85 | SigninManagerBase* signin_manager_; |
Colin Blundell | f878993 | 2018-05-22 11:35:56 | [diff] [blame] | 86 | ProfileOAuth2TokenService* token_service_; |
| 87 | |
pkasting | d3b1a71 | 2016-05-20 21:20:12 | [diff] [blame] | 88 | net::URLRequestContextGetter* request_context_ = nullptr; |
| 89 | |
| 90 | // Used for both account tracker and GCM.UserSignedIn UMA. |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 91 | class IdentityObserver; |
dcheng | a77e28eb | 2016-04-21 21:34:37 | [diff] [blame] | 92 | std::unique_ptr<IdentityObserver> identity_observer_; |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 93 | #endif |
| 94 | |
| 95 | DISALLOW_COPY_AND_ASSIGN(GCMProfileService); |
| 96 | }; |
| 97 | |
| 98 | } // namespace gcm |
| 99 | |
| 100 | #endif // COMPONENTS_GCM_DRIVER_GCM_PROFILE_SERVICE_H_ |
| 101 | |