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" |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 17 | #include "components/keyed_service/core/keyed_service.h" |
| 18 | #include "components/signin/core/browser/profile_identity_provider.h" |
| 19 | #include "components/version_info/version_info.h" |
| 20 | |
| 21 | class PrefService; |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 22 | |
| 23 | namespace base { |
| 24 | class SequencedTaskRunner; |
| 25 | } |
| 26 | |
| 27 | namespace net { |
| 28 | class URLRequestContextGetter; |
| 29 | } |
| 30 | |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 31 | namespace gcm { |
| 32 | |
| 33 | class GCMClientFactory; |
| 34 | class GCMDriver; |
| 35 | |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 36 | // Providing GCM service, via GCMDriver. |
| 37 | class GCMProfileService : public KeyedService { |
| 38 | public: |
| 39 | #if defined(OS_ANDROID) |
| 40 | GCMProfileService( |
| 41 | base::FilePath path, |
| 42 | scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner); |
| 43 | #else |
| 44 | GCMProfileService( |
| 45 | PrefService* prefs, |
| 46 | base::FilePath path, |
| 47 | net::URLRequestContextGetter* request_context, |
| 48 | version_info::Channel channel, |
johnme | 627dc8c7 | 2016-08-19 21:49:39 | [diff] [blame] | 49 | const std::string& product_category_for_subtypes, |
dcheng | a77e28eb | 2016-04-21 21:34:37 | [diff] [blame] | 50 | std::unique_ptr<ProfileIdentityProvider> identity_provider, |
| 51 | std::unique_ptr<GCMClientFactory> gcm_client_factory, |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 52 | const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner, |
| 53 | const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, |
| 54 | scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner); |
| 55 | #endif |
| 56 | ~GCMProfileService() override; |
| 57 | |
| 58 | // Returns whether GCM is enabled. |
| 59 | static bool IsGCMEnabled(PrefService* prefs); |
| 60 | |
| 61 | // KeyedService: |
| 62 | void Shutdown() override; |
| 63 | |
| 64 | // For testing purpose. |
peter | c5634e8f | 2015-12-02 15:34:59 | [diff] [blame] | 65 | void SetDriverForTesting(GCMDriver* driver); |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 66 | |
| 67 | GCMDriver* driver() const { return driver_.get(); } |
| 68 | |
| 69 | protected: |
| 70 | // Used for constructing fake GCMProfileService for testing purpose. |
| 71 | GCMProfileService(); |
| 72 | |
| 73 | private: |
dcheng | a77e28eb | 2016-04-21 21:34:37 | [diff] [blame] | 74 | std::unique_ptr<ProfileIdentityProvider> profile_identity_provider_; |
dcheng | a77e28eb | 2016-04-21 21:34:37 | [diff] [blame] | 75 | std::unique_ptr<GCMDriver> driver_; |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 76 | |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 77 | #if !defined(OS_ANDROID) |
pkasting | d3b1a71 | 2016-05-20 21:20:12 | [diff] [blame] | 78 | net::URLRequestContextGetter* request_context_ = nullptr; |
| 79 | |
| 80 | // Used for both account tracker and GCM.UserSignedIn UMA. |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 81 | class IdentityObserver; |
dcheng | a77e28eb | 2016-04-21 21:34:37 | [diff] [blame] | 82 | std::unique_ptr<IdentityObserver> identity_observer_; |
jitendra.ks | 7554194 | 2015-11-03 20:17:51 | [diff] [blame] | 83 | #endif |
| 84 | |
| 85 | DISALLOW_COPY_AND_ASSIGN(GCMProfileService); |
| 86 | }; |
| 87 | |
| 88 | } // namespace gcm |
| 89 | |
| 90 | #endif // COMPONENTS_GCM_DRIVER_GCM_PROFILE_SERVICE_H_ |
| 91 | |