| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_ | 6 #define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // TODO(jkarlin): Create a background sync scheduler to actually run the | 38 // TODO(jkarlin): Create a background sync scheduler to actually run the |
| 39 // registered events. | 39 // registered events. |
| 40 // TODO(jkarlin): Keep the browser alive if "Let Google Chrome Run in the | 40 // TODO(jkarlin): Keep the browser alive if "Let Google Chrome Run in the |
| 41 // Background" is true and a sync is registered. | 41 // Background" is true and a sync is registered. |
| 42 class CONTENT_EXPORT BackgroundSyncManager | 42 class CONTENT_EXPORT BackgroundSyncManager |
| 43 : NON_EXPORTED_BASE(public ServiceWorkerContextObserver) { | 43 : NON_EXPORTED_BASE(public ServiceWorkerContextObserver) { |
| 44 public: | 44 public: |
| 45 enum ErrorType { | 45 enum ErrorType { |
| 46 ERROR_TYPE_OK = 0, | 46 ERROR_TYPE_OK = 0, |
| 47 ERROR_TYPE_STORAGE, | 47 ERROR_TYPE_STORAGE, |
| 48 ERROR_TYPE_NOT_FOUND | 48 ERROR_TYPE_NOT_FOUND, |
| 49 ERROR_TYPE_NO_SERVICE_WORKER |
| 49 }; | 50 }; |
| 50 | 51 |
| 51 // TODO(jkarlin): Remove this and use the struct from IPC messages once it | 52 // TODO(jkarlin): Remove this and use the struct from IPC messages once it |
| 52 // lands. | 53 // lands. |
| 53 struct CONTENT_EXPORT BackgroundSyncRegistration { | 54 struct CONTENT_EXPORT BackgroundSyncRegistration { |
| 54 using RegistrationId = int64; | 55 using RegistrationId = int64; |
| 55 static const RegistrationId kInvalidRegistrationId; | 56 static const RegistrationId kInvalidRegistrationId; |
| 56 static const RegistrationId kInitialId; | 57 static const RegistrationId kInitialId; |
| 57 BackgroundSyncRegistration() {} | 58 BackgroundSyncRegistration() {} |
| 58 | 59 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 78 static scoped_ptr<BackgroundSyncManager> Create( | 79 static scoped_ptr<BackgroundSyncManager> Create( |
| 79 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context); | 80 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context); |
| 80 ~BackgroundSyncManager() override; | 81 ~BackgroundSyncManager() override; |
| 81 | 82 |
| 82 // Stores the given background sync registration and adds it to the scheduling | 83 // Stores the given background sync registration and adds it to the scheduling |
| 83 // queue. It will overwrite an existing registration with the same tag and | 84 // queue. It will overwrite an existing registration with the same tag and |
| 84 // periodicity unless they're identical (save for the id). Calls |callback| | 85 // periodicity unless they're identical (save for the id). Calls |callback| |
| 85 // with ErrorTypeOK and the accepted registration on success. The accepted | 86 // with ErrorTypeOK and the accepted registration on success. The accepted |
| 86 // registration will have a unique id. It may also have altered parameters if | 87 // registration will have a unique id. It may also have altered parameters if |
| 87 // the user or UA chose different parameters than those supplied. | 88 // the user or UA chose different parameters than those supplied. |
| 88 void Register(const GURL& origin, | 89 void Register(int64 sw_registration_id, |
| 89 int64 sw_registration_id, | |
| 90 const BackgroundSyncRegistration& sync_registration, | 90 const BackgroundSyncRegistration& sync_registration, |
| 91 const StatusAndRegistrationCallback& callback); | 91 const StatusAndRegistrationCallback& callback); |
| 92 | 92 |
| 93 // Removes the background sync with tag |sync_registration_tag|, periodicity | 93 // Removes the background sync with tag |sync_registration_tag|, periodicity |
| 94 // |periodicity|, and id |sync_registration_id|. Calls |callback| with | 94 // |periodicity|, and id |sync_registration_id|. Calls |callback| with |
| 95 // ErrorTypeNotFound if no match is found. Calls |callback| with ErrorTypeOK | 95 // ErrorTypeNotFound if no match is found. Calls |callback| with ErrorTypeOK |
| 96 // on success. | 96 // on success. |
| 97 void Unregister( | 97 void Unregister( |
| 98 const GURL& origin, | |
| 99 int64 sw_registration_id, | 98 int64 sw_registration_id, |
| 100 const std::string& sync_registration_tag, | 99 const std::string& sync_registration_tag, |
| 101 SyncPeriodicity periodicity, | 100 SyncPeriodicity periodicity, |
| 102 BackgroundSyncRegistration::RegistrationId sync_registration_id, | 101 BackgroundSyncRegistration::RegistrationId sync_registration_id, |
| 103 const StatusCallback& callback); | 102 const StatusCallback& callback); |
| 104 | 103 |
| 105 // Finds the background sync registration associated with | 104 // Finds the background sync registration associated with |
| 106 // |sw_registration_id| with periodicity |periodicity|. Calls | 105 // |sw_registration_id| with periodicity |periodicity|. Calls |
| 107 // |callback| with ErrorTypeNotFound if it doesn't exist. Calls |callback| | 106 // |callback| with ErrorTypeNotFound if it doesn't exist. Calls |callback| |
| 108 // with ErrorTypeOK on success. | 107 // with ErrorTypeOK on success. |
| 109 void GetRegistration(const GURL& origin, | 108 void GetRegistration(int64 sw_registration_id, |
| 110 int64 sw_registration_id, | |
| 111 const std::string sync_registration_tag, | 109 const std::string sync_registration_tag, |
| 112 SyncPeriodicity periodicity, | 110 SyncPeriodicity periodicity, |
| 113 const StatusAndRegistrationCallback& callback); | 111 const StatusAndRegistrationCallback& callback); |
| 114 | 112 |
| 115 // ServiceWorkerContextObserver overrides. | 113 // ServiceWorkerContextObserver overrides. |
| 116 void OnRegistrationDeleted(int64 registration_id, | 114 void OnRegistrationDeleted(int64 registration_id, |
| 117 const GURL& pattern) override; | 115 const GURL& pattern) override; |
| 118 void OnStorageWiped() override; | 116 void OnStorageWiped() override; |
| 119 | 117 |
| 120 protected: | 118 protected: |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 const GURL& origin, | 197 const GURL& origin, |
| 200 const BackgroundSyncRegistration& sync_registration); | 198 const BackgroundSyncRegistration& sync_registration); |
| 201 | 199 |
| 202 void InitImpl(const base::Closure& callback); | 200 void InitImpl(const base::Closure& callback); |
| 203 void InitDidGetDataFromBackend( | 201 void InitDidGetDataFromBackend( |
| 204 const base::Closure& callback, | 202 const base::Closure& callback, |
| 205 const std::vector<std::pair<int64, std::string>>& user_data, | 203 const std::vector<std::pair<int64, std::string>>& user_data, |
| 206 ServiceWorkerStatusCode status); | 204 ServiceWorkerStatusCode status); |
| 207 | 205 |
| 208 // Register callbacks | 206 // Register callbacks |
| 209 void RegisterImpl(const GURL& origin, | 207 void RegisterImpl(int64 sw_registration_id, |
| 210 int64 sw_registration_id, | |
| 211 const BackgroundSyncRegistration& sync_registration, | 208 const BackgroundSyncRegistration& sync_registration, |
| 212 const StatusAndRegistrationCallback& callback); | 209 const StatusAndRegistrationCallback& callback); |
| 213 void RegisterDidStore(int64 sw_registration_id, | 210 void RegisterDidStore(int64 sw_registration_id, |
| 214 const BackgroundSyncRegistration& sync_registration, | 211 const BackgroundSyncRegistration& sync_registration, |
| 215 const StatusAndRegistrationCallback& callback, | 212 const StatusAndRegistrationCallback& callback, |
| 216 ServiceWorkerStatusCode status); | 213 ServiceWorkerStatusCode status); |
| 217 | 214 |
| 218 // Unregister callbacks | 215 // Unregister callbacks |
| 219 void UnregisterImpl( | 216 void UnregisterImpl( |
| 220 const GURL& origin, | |
| 221 int64 sw_registration_id, | 217 int64 sw_registration_id, |
| 222 const RegistrationKey& registration_key, | 218 const RegistrationKey& registration_key, |
| 223 BackgroundSyncRegistration::RegistrationId sync_registration_id, | 219 BackgroundSyncRegistration::RegistrationId sync_registration_id, |
| 224 const StatusCallback& callback); | 220 const StatusCallback& callback); |
| 225 void UnregisterDidStore( | 221 void UnregisterDidStore( |
| 226 int64 sw_registration_id, | 222 int64 sw_registration_id, |
| 227 const StatusCallback& callback, | 223 const StatusCallback& callback, |
| 228 ServiceWorkerStatusCode status); | 224 ServiceWorkerStatusCode status); |
| 229 | 225 |
| 230 // GetRegistration callbacks | 226 // GetRegistration callbacks |
| 231 void GetRegistrationImpl(const GURL& origin, | 227 void GetRegistrationImpl(int64 sw_registration_id, |
| 232 int64 sw_registration_id, | |
| 233 const RegistrationKey& registration_key, | 228 const RegistrationKey& registration_key, |
| 234 const StatusAndRegistrationCallback& callback); | 229 const StatusAndRegistrationCallback& callback); |
| 235 | 230 |
| 236 // OnRegistrationDeleted callbacks | 231 // OnRegistrationDeleted callbacks |
| 237 void OnRegistrationDeletedImpl(int64 registration_id, | 232 void OnRegistrationDeletedImpl(int64 registration_id, |
| 238 const base::Closure& callback); | 233 const base::Closure& callback); |
| 239 | 234 |
| 240 // OnStorageWiped callbacks | 235 // OnStorageWiped callbacks |
| 241 void OnStorageWipedImpl(const base::Closure& callback); | 236 void OnStorageWipedImpl(const base::Closure& callback); |
| 242 | 237 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 264 scoped_ptr<BackgroundSyncNetworkObserver> network_observer_; | 259 scoped_ptr<BackgroundSyncNetworkObserver> network_observer_; |
| 265 | 260 |
| 266 base::WeakPtrFactory<BackgroundSyncManager> weak_ptr_factory_; | 261 base::WeakPtrFactory<BackgroundSyncManager> weak_ptr_factory_; |
| 267 | 262 |
| 268 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncManager); | 263 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncManager); |
| 269 }; | 264 }; |
| 270 | 265 |
| 271 } // namespace content | 266 } // namespace content |
| 272 | 267 |
| 273 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_ | 268 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_ |
| OLD | NEW |