OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ |
6 #define CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ | 6 #define CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "chrome/browser/services/gcm/gcm_driver.h" | |
14 #include "components/keyed_service/core/keyed_service.h" | 13 #include "components/keyed_service/core/keyed_service.h" |
15 | 14 |
16 class Profile; | 15 class Profile; |
17 | 16 |
18 namespace user_prefs { | 17 namespace user_prefs { |
19 class PrefRegistrySyncable; | 18 class PrefRegistrySyncable; |
20 } | 19 } |
21 | 20 |
22 namespace gcm { | 21 namespace gcm { |
23 | 22 |
24 // A specialization of GCMDriver that is tied to a Profile. | 23 class GCMClientFactory; |
25 class GCMProfileService : public GCMDriver, public KeyedService { | 24 class GCMDriver; |
25 | |
26 // Providing GCM service, via GCMDriver, to a profile. | |
27 class GCMProfileService : public KeyedService { | |
26 public: | 28 public: |
27 // Any change made to this enum should have corresponding change in the | 29 // Any change made to this enum should have corresponding change in the |
28 // GetGCMEnabledStateString(...) function. | 30 // GetGCMEnabledStateString(...) function. |
29 enum GCMEnabledState { | 31 enum GCMEnabledState { |
30 // GCM is always enabled. GCMClient will always load and connect with GCM. | 32 // GCM is always enabled. GCMClient will always load and connect with GCM. |
31 ALWAYS_ENABLED, | 33 ALWAYS_ENABLED, |
32 // GCM is only enabled for apps. GCMClient will start to load and connect | 34 // GCM is only enabled for apps. GCMClient will start to load and connect |
33 // with GCM only when GCM API is used. | 35 // with GCM only when GCM API is used. |
34 ENABLED_FOR_APPS, | 36 ENABLED_FOR_APPS, |
35 // GCM is always disabled. GCMClient will never load and connect with GCM. | 37 // GCM is always disabled. GCMClient will never load and connect with GCM. |
36 ALWAYS_DISABLED | 38 ALWAYS_DISABLED |
37 }; | 39 }; |
38 | 40 |
39 // Returns the GCM enabled state. | 41 // Returns the GCM enabled state. |
40 static GCMEnabledState GetGCMEnabledState(Profile* profile); | 42 static GCMEnabledState GetGCMEnabledState(Profile* profile); |
41 | 43 |
42 // Returns text representation of a GCMEnabledState enum entry. | 44 // Returns text representation of a GCMEnabledState enum entry. |
43 static std::string GetGCMEnabledStateString(GCMEnabledState state); | 45 static std::string GetGCMEnabledStateString(GCMEnabledState state); |
44 | 46 |
45 // Register profile-specific prefs for GCM. | 47 // Register profile-specific prefs for GCM. |
46 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 48 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
47 | 49 |
48 explicit GCMProfileService(Profile* profile); | 50 explicit GCMProfileService(Profile* profile); |
49 virtual ~GCMProfileService(); | 51 virtual ~GCMProfileService(); |
50 | 52 |
53 void Initialize(scoped_ptr<GCMClientFactory> gcm_client_factory); | |
54 | |
51 // KeyedService: | 55 // KeyedService: |
52 virtual void Shutdown() OVERRIDE; | 56 virtual void Shutdown() OVERRIDE; |
53 | 57 |
54 // Returns the user name if the profile is signed in. | 58 // For testing purpose. |
55 std::string SignedInUserName() const; | 59 void SetDriverForTesting(GCMDriver* driver); |
56 | 60 |
57 protected: | 61 GCMDriver* driver() const { return driver_.get(); } |
Nicolas Zea
2014/05/19 21:04:06
I'm a bit concerned about the possibility of other
jianli
2014/05/19 23:03:48
Moved Initialize logic into constructor.
| |
58 // Overridden from GCMDriver: | |
59 virtual bool ShouldStartAutomatically() const OVERRIDE; | |
60 virtual base::FilePath GetStorePath() const OVERRIDE; | |
61 virtual scoped_refptr<net::URLRequestContextGetter> | |
62 GetURLRequestContextGetter() const OVERRIDE; | |
63 | 62 |
64 private: | 63 private: |
65 // The profile which owns this object. | 64 // The profile which owns this object. |
66 Profile* profile_; | 65 Profile* profile_; |
67 | 66 |
67 scoped_ptr<GCMDriver> driver_; | |
68 | |
68 DISALLOW_COPY_AND_ASSIGN(GCMProfileService); | 69 DISALLOW_COPY_AND_ASSIGN(GCMProfileService); |
69 }; | 70 }; |
70 | 71 |
71 } // namespace gcm | 72 } // namespace gcm |
72 | 73 |
73 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ | 74 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ |
OLD | NEW |