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 <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 class GCMProfileServiceTestConsumer; | 39 class GCMProfileServiceTestConsumer; |
40 | 40 |
41 // Acts as a bridge between GCM API and GCMClient layer. It is profile based. | 41 // Acts as a bridge between GCM API and GCMClient layer. It is profile based. |
42 class GCMProfileService : public BrowserContextKeyedService, | 42 class GCMProfileService : public BrowserContextKeyedService, |
43 public content::NotificationObserver { | 43 public content::NotificationObserver { |
44 public: | 44 public: |
45 typedef base::Callback<void(const std::string& registration_id, | 45 typedef base::Callback<void(const std::string& registration_id, |
46 GCMClient::Result result)> RegisterCallback; | 46 GCMClient::Result result)> RegisterCallback; |
47 typedef base::Callback<void(const std::string& message_id, | 47 typedef base::Callback<void(const std::string& message_id, |
48 GCMClient::Result result)> SendCallback; | 48 GCMClient::Result result)> SendCallback; |
| 49 typedef base::Callback<void(const GCMClient::GCMStatistics& stats)> |
| 50 RequestGCMStatisticsCallback; |
49 | 51 |
50 // For testing purpose. | 52 // For testing purpose. |
51 class TestingDelegate { | 53 class TestingDelegate { |
52 public: | 54 public: |
53 virtual GCMEventRouter* GetEventRouter() const = 0; | 55 virtual GCMEventRouter* GetEventRouter() const = 0; |
54 }; | 56 }; |
55 | 57 |
56 // Returns true if the GCM support is enabled. | 58 // Returns true if the GCM support is enabled. |
57 static bool IsGCMEnabled(Profile* profile); | 59 static bool IsGCMEnabled(Profile* profile); |
58 | 60 |
(...skipping 26 matching lines...) Expand all Loading... |
85 virtual void Send(const std::string& app_id, | 87 virtual void Send(const std::string& app_id, |
86 const std::string& receiver_id, | 88 const std::string& receiver_id, |
87 const GCMClient::OutgoingMessage& message, | 89 const GCMClient::OutgoingMessage& message, |
88 SendCallback callback); | 90 SendCallback callback); |
89 | 91 |
90 // For testing purpose. | 92 // For testing purpose. |
91 void set_testing_delegate(TestingDelegate* testing_delegate) { | 93 void set_testing_delegate(TestingDelegate* testing_delegate) { |
92 testing_delegate_ = testing_delegate; | 94 testing_delegate_ = testing_delegate; |
93 } | 95 } |
94 | 96 |
| 97 // Returns true if the profile is signed in. |
| 98 bool IsSignedIn() const; |
| 99 |
| 100 // Returns true if the gcm client instance has been created. |
| 101 bool IsGCMClientCreated() const; |
| 102 |
| 103 // Returns true if the gcm client is ready. |
| 104 bool IsGCMClientReady() const; |
| 105 |
| 106 // Get GCM client internal states and statistics. If it has not been created |
| 107 // then stats won't be modified. |
| 108 void RequestGCMStatistics(RequestGCMStatisticsCallback callback); |
| 109 |
95 protected: | 110 protected: |
96 // Flag that could be set by the testing code to enable GCM. Otherwise, | 111 // Flag that could be set by the testing code to enable GCM. Otherwise, |
97 // tests from official build will fail. | 112 // tests from official build will fail. |
98 static bool enable_gcm_for_testing_; | 113 static bool enable_gcm_for_testing_; |
99 | 114 |
100 private: | 115 private: |
101 friend class GCMProfileServiceTestConsumer; | 116 friend class GCMProfileServiceTestConsumer; |
102 | 117 |
103 class DelayedTaskController; | 118 class DelayedTaskController; |
104 class IOWorker; | 119 class IOWorker; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 void WriteRegisteredAppIDs(); | 181 void WriteRegisteredAppIDs(); |
167 | 182 |
168 // Used to persist registration info into the app's state store. | 183 // Used to persist registration info into the app's state store. |
169 void DeleteRegistrationInfo(const std::string& app_id); | 184 void DeleteRegistrationInfo(const std::string& app_id); |
170 void WriteRegistrationInfo(const std::string& app_id); | 185 void WriteRegistrationInfo(const std::string& app_id); |
171 void ReadRegistrationInfo(const std::string& app_id); | 186 void ReadRegistrationInfo(const std::string& app_id); |
172 void ReadRegistrationInfoFinished(const std::string& app_id, | 187 void ReadRegistrationInfoFinished(const std::string& app_id, |
173 scoped_ptr<base::Value> value); | 188 scoped_ptr<base::Value> value); |
174 bool ParsePersistedRegistrationInfo(scoped_ptr<base::Value> value, | 189 bool ParsePersistedRegistrationInfo(scoped_ptr<base::Value> value, |
175 RegistrationInfo* registration_info); | 190 RegistrationInfo* registration_info); |
| 191 void RequestGCMStatisticsFinished(GCMClient::GCMStatistics stats); |
176 | 192 |
177 // Returns the key used to identify the registration info saved into the | 193 // Returns the key used to identify the registration info saved into the |
178 // app's state store. Used for testing purpose. | 194 // app's state store. Used for testing purpose. |
179 static const char* GetPersistentRegisterKeyForTesting(); | 195 static const char* GetPersistentRegisterKeyForTesting(); |
180 | 196 |
181 // The profile which owns this object. | 197 // The profile which owns this object. |
182 Profile* profile_; | 198 Profile* profile_; |
183 | 199 |
184 // Used to creat the GCMClient instance. | 200 // Used to creat the GCMClient instance. |
185 scoped_ptr<GCMClientFactory> gcm_client_factory_; | 201 scoped_ptr<GCMClientFactory> gcm_client_factory_; |
(...skipping 10 matching lines...) Expand all Loading... |
196 | 212 |
197 // For all the work occured in IO thread. | 213 // For all the work occured in IO thread. |
198 scoped_refptr<IOWorker> io_worker_; | 214 scoped_refptr<IOWorker> io_worker_; |
199 | 215 |
200 // Callback map (from app_id to callback) for Register. | 216 // Callback map (from app_id to callback) for Register. |
201 std::map<std::string, RegisterCallback> register_callbacks_; | 217 std::map<std::string, RegisterCallback> register_callbacks_; |
202 | 218 |
203 // Callback map (from <app_id, message_id> to callback) for Send. | 219 // Callback map (from <app_id, message_id> to callback) for Send. |
204 std::map<std::pair<std::string, std::string>, SendCallback> send_callbacks_; | 220 std::map<std::pair<std::string, std::string>, SendCallback> send_callbacks_; |
205 | 221 |
| 222 // Callback for RequestGCMStatistics. |
| 223 RequestGCMStatisticsCallback request_gcm_statistics_callback_; |
| 224 |
206 // Map from app_id to registration info (sender ids & registration ID). | 225 // Map from app_id to registration info (sender ids & registration ID). |
207 typedef std::map<std::string, RegistrationInfo> RegistrationInfoMap; | 226 typedef std::map<std::string, RegistrationInfo> RegistrationInfoMap; |
208 RegistrationInfoMap registration_info_map_; | 227 RegistrationInfoMap registration_info_map_; |
209 | 228 |
210 // Event router to talk with JS API. | 229 // Event router to talk with JS API. |
211 #if !defined(OS_ANDROID) | 230 #if !defined(OS_ANDROID) |
212 scoped_ptr<GCMEventRouter> js_event_router_; | 231 scoped_ptr<GCMEventRouter> js_event_router_; |
213 #endif | 232 #endif |
214 | 233 |
215 // For testing purpose. | 234 // For testing purpose. |
216 TestingDelegate* testing_delegate_; | 235 TestingDelegate* testing_delegate_; |
217 | 236 |
218 // Used to pass a weak pointer to the IO worker. | 237 // Used to pass a weak pointer to the IO worker. |
219 base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_; | 238 base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_; |
220 | 239 |
221 DISALLOW_COPY_AND_ASSIGN(GCMProfileService); | 240 DISALLOW_COPY_AND_ASSIGN(GCMProfileService); |
222 }; | 241 }; |
223 | 242 |
224 } // namespace gcm | 243 } // namespace gcm |
225 | 244 |
226 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ | 245 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ |
OLD | NEW |