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 // TODO(jianli): include needed for obsolete methods that are going to be |
| 14 // removed soon. |
13 #include "chrome/browser/services/gcm/gcm_driver.h" | 15 #include "chrome/browser/services/gcm/gcm_driver.h" |
14 #include "components/keyed_service/core/keyed_service.h" | 16 #include "components/keyed_service/core/keyed_service.h" |
15 | 17 |
16 class Profile; | 18 class Profile; |
17 | 19 |
18 namespace user_prefs { | 20 namespace user_prefs { |
19 class PrefRegistrySyncable; | 21 class PrefRegistrySyncable; |
20 } | 22 } |
21 | 23 |
22 namespace gcm { | 24 namespace gcm { |
23 | 25 |
24 // A specialization of GCMDriver that is tied to a Profile. | 26 class GCMClientFactory; |
25 class GCMProfileService : public GCMDriver, public KeyedService { | 27 class GCMDriver; |
| 28 |
| 29 // Providing GCM service, via GCMDriver, to a profile. |
| 30 class GCMProfileService : public KeyedService { |
26 public: | 31 public: |
27 // Any change made to this enum should have corresponding change in the | 32 // Any change made to this enum should have corresponding change in the |
28 // GetGCMEnabledStateString(...) function. | 33 // GetGCMEnabledStateString(...) function. |
29 enum GCMEnabledState { | 34 enum GCMEnabledState { |
30 // GCM is always enabled. GCMClient will always load and connect with GCM. | 35 // GCM is always enabled. GCMClient will always load and connect with GCM. |
31 ALWAYS_ENABLED, | 36 ALWAYS_ENABLED, |
32 // GCM is only enabled for apps. GCMClient will start to load and connect | 37 // GCM is only enabled for apps. GCMClient will start to load and connect |
33 // with GCM only when GCM API is used. | 38 // with GCM only when GCM API is used. |
34 ENABLED_FOR_APPS, | 39 ENABLED_FOR_APPS, |
35 // GCM is always disabled. GCMClient will never load and connect with GCM. | 40 // GCM is always disabled. GCMClient will never load and connect with GCM. |
36 ALWAYS_DISABLED | 41 ALWAYS_DISABLED |
37 }; | 42 }; |
38 | 43 |
39 // Returns the GCM enabled state. | 44 // Returns the GCM enabled state. |
40 static GCMEnabledState GetGCMEnabledState(Profile* profile); | 45 static GCMEnabledState GetGCMEnabledState(Profile* profile); |
41 | 46 |
42 // Returns text representation of a GCMEnabledState enum entry. | 47 // Returns text representation of a GCMEnabledState enum entry. |
43 static std::string GetGCMEnabledStateString(GCMEnabledState state); | 48 static std::string GetGCMEnabledStateString(GCMEnabledState state); |
44 | 49 |
45 // Register profile-specific prefs for GCM. | 50 // Register profile-specific prefs for GCM. |
46 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 51 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
47 | 52 |
48 explicit GCMProfileService(Profile* profile); | 53 GCMProfileService(Profile* profile, |
| 54 scoped_ptr<GCMClientFactory> gcm_client_factory); |
49 virtual ~GCMProfileService(); | 55 virtual ~GCMProfileService(); |
50 | 56 |
| 57 // TODO(jianli): obsolete methods that are going to be removed soon. |
| 58 void AddAppHandler(const std::string& app_id, GCMAppHandler* handler); |
| 59 void RemoveAppHandler(const std::string& app_id); |
| 60 void Register(const std::string& app_id, |
| 61 const std::vector<std::string>& sender_ids, |
| 62 const GCMDriver::RegisterCallback& callback); |
| 63 |
51 // KeyedService: | 64 // KeyedService: |
52 virtual void Shutdown() OVERRIDE; | 65 virtual void Shutdown() OVERRIDE; |
53 | 66 |
54 // Returns the user name if the profile is signed in. | 67 // For testing purpose. |
55 std::string SignedInUserName() const; | 68 void SetDriverForTesting(GCMDriver* driver); |
| 69 |
| 70 GCMDriver* driver() const { return driver_.get(); } |
56 | 71 |
57 protected: | 72 protected: |
58 // Overridden from GCMDriver: | 73 // Used for constructing fake GCMProfileService for testing purpose. |
59 virtual bool ShouldStartAutomatically() const OVERRIDE; | 74 GCMProfileService(); |
60 virtual base::FilePath GetStorePath() const OVERRIDE; | |
61 virtual scoped_refptr<net::URLRequestContextGetter> | |
62 GetURLRequestContextGetter() const OVERRIDE; | |
63 | 75 |
64 private: | 76 private: |
65 // The profile which owns this object. | 77 // The profile which owns this object. |
66 Profile* profile_; | 78 Profile* profile_; |
67 | 79 |
| 80 scoped_ptr<GCMDriver> driver_; |
| 81 |
68 DISALLOW_COPY_AND_ASSIGN(GCMProfileService); | 82 DISALLOW_COPY_AND_ASSIGN(GCMProfileService); |
69 }; | 83 }; |
70 | 84 |
71 } // namespace gcm | 85 } // namespace gcm |
72 | 86 |
73 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ | 87 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ |
OLD | NEW |