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/push_messaging_service_impl.h" | 13 #include "chrome/browser/services/gcm/push_messaging_service_impl.h" |
14 // TODO(jianli): include needed for obsolete methods that are going to be | 14 // TODO(jianli): include needed for obsolete methods that are going to be |
15 // removed soon. | 15 // removed soon. |
16 #include "components/gcm_driver/gcm_driver.h" | 16 #include "components/gcm_driver/gcm_driver.h" |
17 #include "components/keyed_service/core/keyed_service.h" | 17 #include "components/keyed_service/core/keyed_service.h" |
18 | 18 |
19 #if !defined(OS_ANDROID) | |
20 #include "google_apis/gaia/identity_provider.h" | |
21 #endif | |
22 | |
19 class Profile; | 23 class Profile; |
20 | 24 |
21 namespace user_prefs { | 25 namespace user_prefs { |
22 class PrefRegistrySyncable; | 26 class PrefRegistrySyncable; |
23 } | 27 } |
24 | 28 |
25 namespace gcm { | 29 namespace gcm { |
26 | 30 |
27 class GCMClientFactory; | 31 class GCMClientFactory; |
28 class GCMDriver; | 32 class GCMDriver; |
29 | 33 |
30 // Providing GCM service, via GCMDriver, to a profile. | 34 // Providing GCM service, via GCMDriver, to a profile. |
35 #if defined(OS_ANDROID) | |
31 class GCMProfileService : public KeyedService { | 36 class GCMProfileService : public KeyedService { |
37 #else | |
38 class GCMProfileService : public KeyedService, | |
Nicolas Zea
2014/06/13 19:49:31
Agree with Filip, I think it would be cleaner to n
jianli
2014/06/13 21:58:04
Per discussion, I added inner class IdentityObserv
| |
39 public IdentityProvider::Observer { | |
40 #endif | |
32 public: | 41 public: |
33 // Returns whether GCM is enabled for |profile|. | 42 // Returns whether GCM is enabled for |profile|. |
34 static bool IsGCMEnabled(Profile* profile); | 43 static bool IsGCMEnabled(Profile* profile); |
35 | 44 |
36 // Register profile-specific prefs for GCM. | 45 // Register profile-specific prefs for GCM. |
37 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 46 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
38 | 47 |
39 #if defined(OS_ANDROID) | 48 #if defined(OS_ANDROID) |
40 explicit GCMProfileService(Profile* profile); | 49 explicit GCMProfileService(Profile* profile); |
41 #else | 50 #else |
42 GCMProfileService(Profile* profile, | 51 GCMProfileService(Profile* profile, |
43 scoped_ptr<GCMClientFactory> gcm_client_factory); | 52 scoped_ptr<GCMClientFactory> gcm_client_factory); |
44 #endif | 53 #endif |
45 virtual ~GCMProfileService(); | 54 virtual ~GCMProfileService(); |
46 | 55 |
47 // TODO(jianli): obsolete methods that are going to be removed soon. | 56 // TODO(jianli): obsolete methods that are going to be removed soon. |
48 void AddAppHandler(const std::string& app_id, GCMAppHandler* handler); | 57 void AddAppHandler(const std::string& app_id, GCMAppHandler* handler); |
49 void RemoveAppHandler(const std::string& app_id); | 58 void RemoveAppHandler(const std::string& app_id); |
50 void Register(const std::string& app_id, | 59 void Register(const std::string& app_id, |
51 const std::vector<std::string>& sender_ids, | 60 const std::vector<std::string>& sender_ids, |
52 const GCMDriver::RegisterCallback& callback); | 61 const GCMDriver::RegisterCallback& callback); |
53 | 62 |
54 // KeyedService: | 63 // KeyedService: |
55 virtual void Shutdown() OVERRIDE; | 64 virtual void Shutdown() OVERRIDE; |
56 | 65 |
66 #if !defined(OS_ANDROID) | |
67 // IdentityProvider::Observer: | |
68 virtual void OnActiveAccountLogin() OVERRIDE; | |
69 virtual void OnActiveAccountLogout() OVERRIDE; | |
70 #endif | |
71 | |
72 // Returns the user name if the profile is signed in or an empty string | |
73 // otherwise. | |
74 std::string SignedInUserName() const; | |
75 | |
57 // For testing purpose. | 76 // For testing purpose. |
58 void SetDriverForTesting(GCMDriver* driver); | 77 void SetDriverForTesting(GCMDriver* driver); |
59 | 78 |
60 GCMDriver* driver() const { return driver_.get(); } | 79 GCMDriver* driver() const { return driver_.get(); } |
61 | 80 |
62 content::PushMessagingService* push_messaging_service() { | 81 content::PushMessagingService* push_messaging_service() { |
63 return &push_messaging_service_; | 82 return &push_messaging_service_; |
64 } | 83 } |
65 | 84 |
66 protected: | 85 protected: |
67 // Used for constructing fake GCMProfileService for testing purpose. | 86 // Used for constructing fake GCMProfileService for testing purpose. |
68 GCMProfileService(); | 87 GCMProfileService(); |
69 | 88 |
70 private: | 89 private: |
71 // The profile which owns this object. | 90 // The profile which owns this object. |
72 Profile* profile_; | 91 Profile* profile_; |
73 | 92 |
74 scoped_ptr<GCMDriver> driver_; | 93 scoped_ptr<GCMDriver> driver_; |
75 | 94 |
76 // Implementation of content::PushMessagingService using GCMProfileService. | 95 // Implementation of content::PushMessagingService using GCMProfileService. |
77 PushMessagingServiceImpl push_messaging_service_; | 96 PushMessagingServiceImpl push_messaging_service_; |
78 | 97 |
98 #if !defined(OS_ANDROID) | |
99 scoped_ptr<IdentityProvider> identity_provider_; | |
100 | |
101 // The account ID that this service is responsible for. Empty when the service | |
102 // is not running. | |
103 std::string account_id_; | |
104 #endif | |
105 | |
79 DISALLOW_COPY_AND_ASSIGN(GCMProfileService); | 106 DISALLOW_COPY_AND_ASSIGN(GCMProfileService); |
80 }; | 107 }; |
81 | 108 |
82 } // namespace gcm | 109 } // namespace gcm |
83 | 110 |
84 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ | 111 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ |
OLD | NEW |