| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // Get GCM client internal states and statistics. If it has not been created | 128 // Get GCM client internal states and statistics. If it has not been created |
| 129 // then stats won't be modified. | 129 // then stats won't be modified. |
| 130 void RequestGCMStatistics(RequestGCMStatisticsCallback callback); | 130 void RequestGCMStatistics(RequestGCMStatisticsCallback callback); |
| 131 | 131 |
| 132 private: | 132 private: |
| 133 friend class GCMProfileServiceTestConsumer; | 133 friend class GCMProfileServiceTestConsumer; |
| 134 | 134 |
| 135 class DelayedTaskController; | 135 class DelayedTaskController; |
| 136 class IOWorker; | 136 class IOWorker; |
| 137 | 137 |
| 138 struct RegistrationInfo { | |
| 139 RegistrationInfo(); | |
| 140 ~RegistrationInfo(); | |
| 141 bool IsValid() const; | |
| 142 | |
| 143 std::vector<std::string> sender_ids; | |
| 144 std::string registration_id; | |
| 145 }; | |
| 146 | |
| 147 typedef std::map<std::string, GCMAppHandler*> GCMAppHandlerMap; | 138 typedef std::map<std::string, GCMAppHandler*> GCMAppHandlerMap; |
| 148 | 139 |
| 149 // Overridden from content::NotificationObserver: | 140 // Overridden from content::NotificationObserver: |
| 150 virtual void Observe(int type, | 141 virtual void Observe(int type, |
| 151 const content::NotificationSource& source, | 142 const content::NotificationSource& source, |
| 152 const content::NotificationDetails& details) OVERRIDE; | 143 const content::NotificationDetails& details) OVERRIDE; |
| 153 | 144 |
| 154 // Overridden from SigninManagerBase::Observer: | 145 // Overridden from SigninManagerBase::Observer: |
| 155 virtual void GoogleSigninSucceeded(const std::string& username, | 146 virtual void GoogleSigninSucceeded(const std::string& username, |
| 156 const std::string& password) OVERRIDE; | 147 const std::string& password) OVERRIDE; |
| 157 virtual void GoogleSignedOut(const std::string& username) OVERRIDE; | 148 virtual void GoogleSignedOut(const std::string& username) OVERRIDE; |
| 158 | 149 |
| 159 // Ensures that the GCMClient is loaded and the GCM check-in is done when | 150 // Ensures that the GCMClient is loaded and the GCM check-in is done when |
| 160 // the profile was signed in. | 151 // the profile was signed in. |
| 161 void EnsureLoaded(); | 152 void EnsureLoaded(); |
| 162 | 153 |
| 163 // Remove cached or persisted data when GCM service is stopped. | 154 // Remove cached data when GCM service is stopped. |
| 164 void RemoveCachedData(); | 155 void RemoveCachedData(); |
| 165 void RemovePersistedData(); | |
| 166 | 156 |
| 167 // Checks out of GCM when the profile has been signed out. This will erase | 157 // Checks out of GCM when the profile has been signed out. This will erase |
| 168 // all the cached and persisted data. | 158 // all the cached and persisted data. |
| 169 void CheckOut(); | 159 void CheckOut(); |
| 170 | 160 |
| 171 // Resets the GCMClient instance. This is called when the profile is being | 161 // Resets the GCMClient instance. This is called when the profile is being |
| 172 // destroyed. | 162 // destroyed. |
| 173 void ResetGCMClient(); | 163 void ResetGCMClient(); |
| 174 | 164 |
| 175 // Ensures that the app is ready for GCM functions and events. | 165 // Ensures that the app is ready for GCM functions and events. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 197 void MessageReceived(const std::string& app_id, | 187 void MessageReceived(const std::string& app_id, |
| 198 GCMClient::IncomingMessage message); | 188 GCMClient::IncomingMessage message); |
| 199 void MessagesDeleted(const std::string& app_id); | 189 void MessagesDeleted(const std::string& app_id); |
| 200 void MessageSendError(const std::string& app_id, | 190 void MessageSendError(const std::string& app_id, |
| 201 const GCMClient::SendErrorDetails& send_error_details); | 191 const GCMClient::SendErrorDetails& send_error_details); |
| 202 void GCMClientReady(); | 192 void GCMClientReady(); |
| 203 | 193 |
| 204 // Returns the handler for the given app. | 194 // Returns the handler for the given app. |
| 205 GCMAppHandler* GetAppHandler(const std::string& app_id); | 195 GCMAppHandler* GetAppHandler(const std::string& app_id); |
| 206 | 196 |
| 207 // Used to persist the IDs of registered apps. | |
| 208 void ReadRegisteredAppIDs(); | |
| 209 void WriteRegisteredAppIDs(); | |
| 210 | |
| 211 // Used to persist registration info into the app's state store. | |
| 212 void DeleteRegistrationInfo(const std::string& app_id); | |
| 213 void WriteRegistrationInfo(const std::string& app_id); | |
| 214 void ReadRegistrationInfo(const std::string& app_id); | |
| 215 void ReadRegistrationInfoFinished(const std::string& app_id, | |
| 216 scoped_ptr<base::Value> value); | |
| 217 bool ParsePersistedRegistrationInfo(scoped_ptr<base::Value> value, | |
| 218 RegistrationInfo* registration_info); | |
| 219 void RequestGCMStatisticsFinished(GCMClient::GCMStatistics stats); | 197 void RequestGCMStatisticsFinished(GCMClient::GCMStatistics stats); |
| 220 | 198 |
| 221 // Returns the key used to identify the registration info saved into the | |
| 222 // app's state store. Used for testing purpose. | |
| 223 static const char* GetPersistentRegisterKeyForTesting(); | |
| 224 | |
| 225 // The profile which owns this object. | 199 // The profile which owns this object. |
| 226 Profile* profile_; | 200 Profile* profile_; |
| 227 | 201 |
| 228 // Flag to indicate if GCMClient is ready. | 202 // Flag to indicate if GCMClient is ready. |
| 229 bool gcm_client_ready_; | 203 bool gcm_client_ready_; |
| 230 | 204 |
| 231 // The username of the signed-in profile. | 205 // The username of the signed-in profile. |
| 232 std::string username_; | 206 std::string username_; |
| 233 | 207 |
| 234 content::NotificationRegistrar registrar_; | 208 content::NotificationRegistrar registrar_; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 250 | 224 |
| 251 // Callback map (from app_id to callback) for Unregister. | 225 // Callback map (from app_id to callback) for Unregister. |
| 252 std::map<std::string, UnregisterCallback> unregister_callbacks_; | 226 std::map<std::string, UnregisterCallback> unregister_callbacks_; |
| 253 | 227 |
| 254 // Callback map (from <app_id, message_id> to callback) for Send. | 228 // Callback map (from <app_id, message_id> to callback) for Send. |
| 255 std::map<std::pair<std::string, std::string>, SendCallback> send_callbacks_; | 229 std::map<std::pair<std::string, std::string>, SendCallback> send_callbacks_; |
| 256 | 230 |
| 257 // Callback for RequestGCMStatistics. | 231 // Callback for RequestGCMStatistics. |
| 258 RequestGCMStatisticsCallback request_gcm_statistics_callback_; | 232 RequestGCMStatisticsCallback request_gcm_statistics_callback_; |
| 259 | 233 |
| 260 // Map from app_id to registration info (sender ids & registration ID). | |
| 261 typedef std::map<std::string, RegistrationInfo> RegistrationInfoMap; | |
| 262 RegistrationInfoMap registration_info_map_; | |
| 263 | |
| 264 // Used to pass a weak pointer to the IO worker. | 234 // Used to pass a weak pointer to the IO worker. |
| 265 base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_; | 235 base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_; |
| 266 | 236 |
| 267 DISALLOW_COPY_AND_ASSIGN(GCMProfileService); | 237 DISALLOW_COPY_AND_ASSIGN(GCMProfileService); |
| 268 }; | 238 }; |
| 269 | 239 |
| 270 } // namespace gcm | 240 } // namespace gcm |
| 271 | 241 |
| 272 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ | 242 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ |
| OLD | NEW |