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