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 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 class GCMProfileService : public KeyedService, | 41 class GCMProfileService : public KeyedService, |
42 public content::NotificationObserver, | 42 public content::NotificationObserver, |
43 public SigninManagerBase::Observer { | 43 public SigninManagerBase::Observer { |
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(GCMClient::Result result)> UnregisterCallback; | 49 typedef base::Callback<void(GCMClient::Result result)> UnregisterCallback; |
50 typedef base::Callback<void(const GCMClient::GCMStatistics& stats)> | 50 typedef base::Callback<void(const GCMClient::GCMStatistics& stats)> |
51 RequestGCMStatisticsCallback; | 51 GetGCMStatisticsCallback; |
52 | 52 |
53 // Any change made to this enum should have corresponding change in the | 53 // Any change made to this enum should have corresponding change in the |
54 // GetGCMEnabledStateString(...) function. | 54 // GetGCMEnabledStateString(...) function. |
55 enum GCMEnabledState { | 55 enum GCMEnabledState { |
56 // GCM is always enabled. GCMClient will always load and connect with GCM. | 56 // GCM is always enabled. GCMClient will always load and connect with GCM. |
57 ALWAYS_ENABLED, | 57 ALWAYS_ENABLED, |
58 // GCM is only enabled for apps. GCMClient will start to load and connect | 58 // GCM is only enabled for apps. GCMClient will start to load and connect |
59 // with GCM only when GCM API is used. | 59 // with GCM only when GCM API is used. |
60 ENABLED_FOR_APPS, | 60 ENABLED_FOR_APPS, |
61 // GCM is always disabled. GCMClient will never load and connect with GCM. | 61 // GCM is always disabled. GCMClient will never load and connect with GCM. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 | 118 |
119 // For testing purpose. | 119 // For testing purpose. |
120 GCMClient* GetGCMClientForTesting() const; | 120 GCMClient* GetGCMClientForTesting() const; |
121 | 121 |
122 // Returns the user name if the profile is signed in. | 122 // Returns the user name if the profile is signed in. |
123 std::string SignedInUserName() const; | 123 std::string SignedInUserName() const; |
124 | 124 |
125 // Returns true if the gcm client is ready. | 125 // Returns true if the gcm client is ready. |
126 bool IsGCMClientReady() const; | 126 bool IsGCMClientReady() const; |
127 | 127 |
128 // Get GCM client internal states and statistics. If it has not been created | 128 // Get GCM client internal states and statistics. |
129 // then stats won't be modified. | 129 // If clear_logs is true then activity logs will be cleared before the stats |
130 void RequestGCMStatistics(RequestGCMStatisticsCallback callback); | 130 // are returned. |
| 131 void GetGCMStatistics(GetGCMStatisticsCallback callback, |
| 132 bool clear_logs); |
| 133 |
| 134 // Enables/disables GCM activity recording, and then returns the stats. |
| 135 void SetGCMRecording(GetGCMStatisticsCallback callback, bool recording); |
131 | 136 |
132 private: | 137 private: |
133 friend class GCMProfileServiceTestConsumer; | 138 friend class GCMProfileServiceTestConsumer; |
134 | 139 |
135 class DelayedTaskController; | 140 class DelayedTaskController; |
136 class IOWorker; | 141 class IOWorker; |
137 | 142 |
138 typedef std::map<std::string, GCMAppHandler*> GCMAppHandlerMap; | 143 typedef std::map<std::string, GCMAppHandler*> GCMAppHandlerMap; |
139 | 144 |
140 // Overridden from content::NotificationObserver: | 145 // Overridden from content::NotificationObserver: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 void MessageReceived(const std::string& app_id, | 192 void MessageReceived(const std::string& app_id, |
188 GCMClient::IncomingMessage message); | 193 GCMClient::IncomingMessage message); |
189 void MessagesDeleted(const std::string& app_id); | 194 void MessagesDeleted(const std::string& app_id); |
190 void MessageSendError(const std::string& app_id, | 195 void MessageSendError(const std::string& app_id, |
191 const GCMClient::SendErrorDetails& send_error_details); | 196 const GCMClient::SendErrorDetails& send_error_details); |
192 void GCMClientReady(); | 197 void GCMClientReady(); |
193 | 198 |
194 // Returns the handler for the given app. | 199 // Returns the handler for the given app. |
195 GCMAppHandler* GetAppHandler(const std::string& app_id); | 200 GCMAppHandler* GetAppHandler(const std::string& app_id); |
196 | 201 |
197 void RequestGCMStatisticsFinished(GCMClient::GCMStatistics stats); | 202 void GetGCMStatisticsFinished(GCMClient::GCMStatistics stats); |
198 | 203 |
199 // The profile which owns this object. | 204 // The profile which owns this object. |
200 Profile* profile_; | 205 Profile* profile_; |
201 | 206 |
202 // Flag to indicate if GCMClient is ready. | 207 // Flag to indicate if GCMClient is ready. |
203 bool gcm_client_ready_; | 208 bool gcm_client_ready_; |
204 | 209 |
205 // The username of the signed-in profile. | 210 // The username of the signed-in profile. |
206 std::string username_; | 211 std::string username_; |
207 | 212 |
(...skipping 13 matching lines...) Expand all Loading... |
221 | 226 |
222 // Callback map (from app_id to callback) for Register. | 227 // Callback map (from app_id to callback) for Register. |
223 std::map<std::string, RegisterCallback> register_callbacks_; | 228 std::map<std::string, RegisterCallback> register_callbacks_; |
224 | 229 |
225 // Callback map (from app_id to callback) for Unregister. | 230 // Callback map (from app_id to callback) for Unregister. |
226 std::map<std::string, UnregisterCallback> unregister_callbacks_; | 231 std::map<std::string, UnregisterCallback> unregister_callbacks_; |
227 | 232 |
228 // Callback map (from <app_id, message_id> to callback) for Send. | 233 // Callback map (from <app_id, message_id> to callback) for Send. |
229 std::map<std::pair<std::string, std::string>, SendCallback> send_callbacks_; | 234 std::map<std::pair<std::string, std::string>, SendCallback> send_callbacks_; |
230 | 235 |
231 // Callback for RequestGCMStatistics. | 236 // Callback for GetGCMStatistics. |
232 RequestGCMStatisticsCallback request_gcm_statistics_callback_; | 237 GetGCMStatisticsCallback request_gcm_statistics_callback_; |
233 | 238 |
234 // Used to pass a weak pointer to the IO worker. | 239 // Used to pass a weak pointer to the IO worker. |
235 base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_; | 240 base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_; |
236 | 241 |
237 DISALLOW_COPY_AND_ASSIGN(GCMProfileService); | 242 DISALLOW_COPY_AND_ASSIGN(GCMProfileService); |
238 }; | 243 }; |
239 | 244 |
240 } // namespace gcm | 245 } // namespace gcm |
241 | 246 |
242 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ | 247 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ |
OLD | NEW |