| 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 <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 // BackgroundSyncManager manages and stores the set of background sync | 38 // BackgroundSyncManager manages and stores the set of background sync |
| 39 // registrations across all registered service workers for a profile. | 39 // registrations across all registered service workers for a profile. |
| 40 // Registrations are stored along with their associated Service Worker | 40 // Registrations are stored along with their associated Service Worker |
| 41 // registration in ServiceWorkerStorage. If the ServiceWorker is unregistered, | 41 // registration in ServiceWorkerStorage. If the ServiceWorker is unregistered, |
| 42 // the sync registrations are removed. This class must be run on the IO | 42 // the sync registrations are removed. This class must be run on the IO |
| 43 // thread. The asynchronous methods are executed sequentially. | 43 // thread. The asynchronous methods are executed sequentially. |
| 44 class CONTENT_EXPORT BackgroundSyncManager | 44 class CONTENT_EXPORT BackgroundSyncManager |
| 45 : NON_EXPORTED_BASE(public ServiceWorkerContextObserver) { | 45 : NON_EXPORTED_BASE(public ServiceWorkerContextObserver) { |
| 46 public: | 46 public: |
| 47 using BoolCallback = base::Callback<void(bool)>; |
| 47 using StatusCallback = base::Callback<void(BackgroundSyncStatus)>; | 48 using StatusCallback = base::Callback<void(BackgroundSyncStatus)>; |
| 48 using StatusAndRegistrationCallback = | 49 using StatusAndRegistrationCallback = |
| 49 base::Callback<void(BackgroundSyncStatus, | 50 base::Callback<void(BackgroundSyncStatus, |
| 50 scoped_ptr<BackgroundSyncRegistrationHandle>)>; | 51 scoped_ptr<BackgroundSyncRegistrationHandle>)>; |
| 51 using StatusAndStateCallback = | 52 using StatusAndStateCallback = |
| 52 base::Callback<void(BackgroundSyncStatus, BackgroundSyncState)>; | 53 base::Callback<void(BackgroundSyncStatus, BackgroundSyncState)>; |
| 53 using StatusAndRegistrationsCallback = base::Callback<void( | 54 using StatusAndRegistrationsCallback = base::Callback<void( |
| 54 BackgroundSyncStatus, | 55 BackgroundSyncStatus, |
| 55 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>>)>; | 56 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>>)>; |
| 56 | 57 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 const std::string& backend_key, | 140 const std::string& backend_key, |
| 140 const ServiceWorkerStorage::GetUserDataForAllRegistrationsCallback& | 141 const ServiceWorkerStorage::GetUserDataForAllRegistrationsCallback& |
| 141 callback); | 142 callback); |
| 142 virtual void FireOneShotSync( | 143 virtual void FireOneShotSync( |
| 143 BackgroundSyncRegistrationHandle::HandleId handle_id, | 144 BackgroundSyncRegistrationHandle::HandleId handle_id, |
| 144 const scoped_refptr<ServiceWorkerVersion>& active_version, | 145 const scoped_refptr<ServiceWorkerVersion>& active_version, |
| 145 BackgroundSyncEventLastChance last_chance, | 146 BackgroundSyncEventLastChance last_chance, |
| 146 const ServiceWorkerVersion::StatusCallback& callback); | 147 const ServiceWorkerVersion::StatusCallback& callback); |
| 147 virtual void ScheduleDelayedTask(const base::Closure& callback, | 148 virtual void ScheduleDelayedTask(const base::Closure& callback, |
| 148 base::TimeDelta delay); | 149 base::TimeDelta delay); |
| 150 virtual void HasMainFrameProviderHost(const GURL& origin, |
| 151 const BoolCallback& callback); |
| 149 | 152 |
| 150 private: | 153 private: |
| 151 friend class BackgroundSyncManagerTest; | 154 friend class BackgroundSyncManagerTest; |
| 152 friend class BackgroundSyncRegistrationHandle; | 155 friend class BackgroundSyncRegistrationHandle; |
| 153 | 156 |
| 154 class RegistrationKey { | 157 class RegistrationKey { |
| 155 public: | 158 public: |
| 156 explicit RegistrationKey(const BackgroundSyncRegistration& registration); | 159 explicit RegistrationKey(const BackgroundSyncRegistration& registration); |
| 157 explicit RegistrationKey(const BackgroundSyncRegistrationOptions& options); | 160 explicit RegistrationKey(const BackgroundSyncRegistrationOptions& options); |
| 158 RegistrationKey(const std::string& tag, SyncPeriodicity periodicity); | 161 RegistrationKey(const std::string& tag, SyncPeriodicity periodicity); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 const GURL& origin, | 234 const GURL& origin, |
| 232 const scoped_refptr<RefCountedRegistration>& sync_registration); | 235 const scoped_refptr<RefCountedRegistration>& sync_registration); |
| 233 | 236 |
| 234 void InitImpl(const base::Closure& callback); | 237 void InitImpl(const base::Closure& callback); |
| 235 void InitDidGetDataFromBackend( | 238 void InitDidGetDataFromBackend( |
| 236 const base::Closure& callback, | 239 const base::Closure& callback, |
| 237 const std::vector<std::pair<int64, std::string>>& user_data, | 240 const std::vector<std::pair<int64, std::string>>& user_data, |
| 238 ServiceWorkerStatusCode status); | 241 ServiceWorkerStatusCode status); |
| 239 | 242 |
| 240 // Register callbacks | 243 // Register callbacks |
| 244 void RegisterCheckIfHasMainFrame( |
| 245 int64 sw_registration_id, |
| 246 const BackgroundSyncRegistrationOptions& options, |
| 247 const StatusAndRegistrationCallback& callback); |
| 248 void RegisterDidCheckIfMainFrame( |
| 249 int64 sw_registration_id, |
| 250 const BackgroundSyncRegistrationOptions& options, |
| 251 const StatusAndRegistrationCallback& callback, |
| 252 bool has_main_frame_client); |
| 241 void RegisterImpl(int64 sw_registration_id, | 253 void RegisterImpl(int64 sw_registration_id, |
| 242 const BackgroundSyncRegistrationOptions& options, | 254 const BackgroundSyncRegistrationOptions& options, |
| 243 bool requested_from_service_worker, | |
| 244 const StatusAndRegistrationCallback& callback); | 255 const StatusAndRegistrationCallback& callback); |
| 245 void RegisterDidStore( | 256 void RegisterDidStore( |
| 246 int64 sw_registration_id, | 257 int64 sw_registration_id, |
| 247 const scoped_refptr<RefCountedRegistration>& new_registration_ref, | 258 const scoped_refptr<RefCountedRegistration>& new_registration_ref, |
| 248 const StatusAndRegistrationCallback& callback, | 259 const StatusAndRegistrationCallback& callback, |
| 249 ServiceWorkerStatusCode status); | 260 ServiceWorkerStatusCode status); |
| 250 | 261 |
| 251 // Removes the background sync with periodicity |periodicity| and id | 262 // Removes the background sync with periodicity |periodicity| and id |
| 252 // |sync_registration_id|. Calls |callback| with | 263 // |sync_registration_id|. Calls |callback| with |
| 253 // BACKGROUND_SYNC_STATUS_NOT_FOUND if no match is found. Calls |callback| | 264 // BACKGROUND_SYNC_STATUS_NOT_FOUND if no match is found. Calls |callback| |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 scoped_ptr<base::Clock> clock_; | 396 scoped_ptr<base::Clock> clock_; |
| 386 | 397 |
| 387 base::WeakPtrFactory<BackgroundSyncManager> weak_ptr_factory_; | 398 base::WeakPtrFactory<BackgroundSyncManager> weak_ptr_factory_; |
| 388 | 399 |
| 389 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncManager); | 400 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncManager); |
| 390 }; | 401 }; |
| 391 | 402 |
| 392 } // namespace content | 403 } // namespace content |
| 393 | 404 |
| 394 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_ | 405 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_ |
| OLD | NEW |