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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 base::Callback<void(BackgroundSyncStatus, BackgroundSyncState)>; | 57 base::Callback<void(BackgroundSyncStatus, BackgroundSyncState)>; |
58 using StatusAndRegistrationsCallback = base::Callback<void( | 58 using StatusAndRegistrationsCallback = base::Callback<void( |
59 BackgroundSyncStatus, | 59 BackgroundSyncStatus, |
60 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>>)>; | 60 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>>)>; |
61 | 61 |
62 static scoped_ptr<BackgroundSyncManager> Create( | 62 static scoped_ptr<BackgroundSyncManager> Create( |
63 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context); | 63 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context); |
64 ~BackgroundSyncManager() override; | 64 ~BackgroundSyncManager() override; |
65 | 65 |
66 // Stores the given background sync registration and adds it to the scheduling | 66 // Stores the given background sync registration and adds it to the scheduling |
67 // queue. It will overwrite an existing registration with the same tag and | 67 // queue. It will overwrite an existing registration with the same tag unless |
68 // periodicity unless they're identical (save for the id). Calls |callback| | 68 // they're identical (save for the id). Calls |callback| with |
69 // with BACKGROUND_SYNC_STATUS_OK and the accepted registration on success. | 69 // BACKGROUND_SYNC_STATUS_OK and the accepted registration on success. |
70 // The accepted registration will have a unique id. It may also have altered | 70 // The accepted registration will have a unique id. It may also have altered |
71 // parameters if the user or UA chose different parameters than those | 71 // parameters if the user or UA chose different parameters than those |
72 // supplied. | 72 // supplied. |
73 void Register(int64_t sw_registration_id, | 73 void Register(int64_t sw_registration_id, |
74 const BackgroundSyncRegistrationOptions& options, | 74 const BackgroundSyncRegistrationOptions& options, |
75 bool requested_from_service_worker, | 75 bool requested_from_service_worker, |
76 const StatusAndRegistrationCallback& callback); | 76 const StatusAndRegistrationCallback& callback); |
77 | 77 |
78 // Finds the background sync registration associated with | 78 // Finds the background sync registration associated with |
79 // |sw_registration_id|, periodicity |periodicity|, and tag | 79 // |sw_registration_id|, and tag |sync_registration_tag|. Calls |callback| |
80 // |sync_registration_tag|. Calls |callback| with | 80 // with |
iclelland
2016/01/22 19:20:41
Re-wrap
jkarlin
2016/01/22 19:45:46
Done.
| |
81 // BACKGROUND_SYNC_STATUS_NOT_FOUND if it doesn't exist. Calls |callback| with | 81 // BACKGROUND_SYNC_STATUS_NOT_FOUND if it doesn't exist. Calls |callback| with |
82 // BACKGROUND_SYNC_STATUS_OK on success. If the callback's status | 82 // BACKGROUND_SYNC_STATUS_OK on success. If the callback's status |
83 // is not BACKGROUND_SYNC_STATUS_OK then the callback's RegistrationHandle | 83 // is not BACKGROUND_SYNC_STATUS_OK then the callback's RegistrationHandle |
84 // will be nullptr. | 84 // will be nullptr. |
85 void GetRegistration(int64_t sw_registration_id, | 85 void GetRegistration(int64_t sw_registration_id, |
86 const std::string& sync_registration_tag, | 86 const std::string& sync_registration_tag, |
87 SyncPeriodicity periodicity, | |
88 const StatusAndRegistrationCallback& callback); | 87 const StatusAndRegistrationCallback& callback); |
89 | 88 |
90 // Finds the background sync registrations associated with | 89 // Finds the background sync registrations associated with |
91 // |sw_registration_id| and periodicity |periodicity|. Calls | 90 // |sw_registration_id|. Calls |
iclelland
2016/01/22 19:20:41
Re-wrap
jkarlin
2016/01/22 19:45:46
Done.
| |
92 // |callback| with BACKGROUND_SYNC_STATUS_OK on success. | 91 // |callback| with BACKGROUND_SYNC_STATUS_OK on success. |
93 void GetRegistrations(int64_t sw_registration_id, | 92 void GetRegistrations(int64_t sw_registration_id, |
94 SyncPeriodicity periodicity, | |
95 const StatusAndRegistrationsCallback& callback); | 93 const StatusAndRegistrationsCallback& callback); |
96 | 94 |
97 // Given a HandleId |handle_id|, return a new handle for the same | 95 // Given a HandleId |handle_id|, return a new handle for the same |
98 // registration. | 96 // registration. |
99 scoped_ptr<BackgroundSyncRegistrationHandle> DuplicateRegistrationHandle( | 97 scoped_ptr<BackgroundSyncRegistrationHandle> DuplicateRegistrationHandle( |
100 BackgroundSyncRegistrationHandle::HandleId handle_id); | 98 BackgroundSyncRegistrationHandle::HandleId handle_id); |
101 | 99 |
102 // ServiceWorkerContextObserver overrides. | 100 // ServiceWorkerContextObserver overrides. |
103 void OnRegistrationDeleted(int64_t sw_registration_id, | 101 void OnRegistrationDeleted(int64_t sw_registration_id, |
104 const GURL& pattern) override; | 102 const GURL& pattern) override; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 | 153 |
156 private: | 154 private: |
157 friend class TestBackgroundSyncManager; | 155 friend class TestBackgroundSyncManager; |
158 friend class BackgroundSyncManagerTest; | 156 friend class BackgroundSyncManagerTest; |
159 friend class BackgroundSyncRegistrationHandle; | 157 friend class BackgroundSyncRegistrationHandle; |
160 | 158 |
161 class RegistrationKey { | 159 class RegistrationKey { |
162 public: | 160 public: |
163 explicit RegistrationKey(const BackgroundSyncRegistration& registration); | 161 explicit RegistrationKey(const BackgroundSyncRegistration& registration); |
164 explicit RegistrationKey(const BackgroundSyncRegistrationOptions& options); | 162 explicit RegistrationKey(const BackgroundSyncRegistrationOptions& options); |
165 RegistrationKey(const std::string& tag, SyncPeriodicity periodicity); | 163 RegistrationKey(const std::string& tag); |
166 RegistrationKey(const RegistrationKey& other) = default; | 164 RegistrationKey(const RegistrationKey& other) = default; |
167 RegistrationKey& operator=(const RegistrationKey& other) = default; | 165 RegistrationKey& operator=(const RegistrationKey& other) = default; |
168 | 166 |
169 bool operator<(const RegistrationKey& rhs) const { | 167 bool operator<(const RegistrationKey& rhs) const { |
170 return value_ < rhs.value_; | 168 return value_ < rhs.value_; |
171 } | 169 } |
172 | 170 |
173 private: | 171 private: |
174 std::string value_; | 172 std::string value_; |
175 }; | 173 }; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 bool has_main_frame_client); | 257 bool has_main_frame_client); |
260 void RegisterImpl(int64_t sw_registration_id, | 258 void RegisterImpl(int64_t sw_registration_id, |
261 const BackgroundSyncRegistrationOptions& options, | 259 const BackgroundSyncRegistrationOptions& options, |
262 const StatusAndRegistrationCallback& callback); | 260 const StatusAndRegistrationCallback& callback); |
263 void RegisterDidStore( | 261 void RegisterDidStore( |
264 int64_t sw_registration_id, | 262 int64_t sw_registration_id, |
265 const scoped_refptr<RefCountedRegistration>& new_registration_ref, | 263 const scoped_refptr<RefCountedRegistration>& new_registration_ref, |
266 const StatusAndRegistrationCallback& callback, | 264 const StatusAndRegistrationCallback& callback, |
267 ServiceWorkerStatusCode status); | 265 ServiceWorkerStatusCode status); |
268 | 266 |
269 // Removes the background sync with periodicity |periodicity| and id | 267 // Removes the background sync with id |sync_registration_id|. Calls |
270 // |sync_registration_id|. Calls |callback| with | 268 // |callback| with BACKGROUND_SYNC_STATUS_NOT_FOUND if no match is found. |
271 // BACKGROUND_SYNC_STATUS_NOT_FOUND if no match is found. Calls |callback| | 269 // Calls |callback| with BACKGROUND_SYNC_STATUS_OK on success. |
272 // with BACKGROUND_SYNC_STATUS_OK on success. | |
273 void Unregister(int64_t sw_registration_id, | 270 void Unregister(int64_t sw_registration_id, |
274 BackgroundSyncRegistrationHandle::HandleId handle_id, | 271 BackgroundSyncRegistrationHandle::HandleId handle_id, |
275 const StatusCallback& callback); | 272 const StatusCallback& callback); |
276 void UnregisterImpl( | 273 void UnregisterImpl( |
277 int64_t sw_registration_id, | 274 int64_t sw_registration_id, |
278 const RegistrationKey& key, | 275 const RegistrationKey& key, |
279 BackgroundSyncRegistration::RegistrationId sync_registration_id, | 276 BackgroundSyncRegistration::RegistrationId sync_registration_id, |
280 SyncPeriodicity periodicity, | |
281 const StatusCallback& callback); | 277 const StatusCallback& callback); |
282 void UnregisterDidStore(int64_t sw_registration_id, | 278 void UnregisterDidStore(int64_t sw_registration_id, |
283 SyncPeriodicity periodicity, | |
284 const StatusCallback& callback, | 279 const StatusCallback& callback, |
285 ServiceWorkerStatusCode status); | 280 ServiceWorkerStatusCode status); |
286 | 281 |
287 // NotifyWhenFinished and its callbacks. See | 282 // NotifyWhenFinished and its callbacks. See |
288 // BackgroundSyncRegistrationHandle::NotifyWhenFinished for detailed | 283 // BackgroundSyncRegistrationHandle::NotifyWhenFinished for detailed |
289 // documentation. | 284 // documentation. |
290 void NotifyWhenFinished(BackgroundSyncRegistrationHandle::HandleId handle_id, | 285 void NotifyWhenFinished(BackgroundSyncRegistrationHandle::HandleId handle_id, |
291 const StatusAndStateCallback& callback); | 286 const StatusAndStateCallback& callback); |
292 void NotifyWhenFinishedImpl( | 287 void NotifyWhenFinishedImpl( |
293 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle, | 288 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle, |
294 const StatusAndStateCallback& callback); | 289 const StatusAndStateCallback& callback); |
295 void NotifyWhenFinishedInvokeCallback(const StatusAndStateCallback& callback, | 290 void NotifyWhenFinishedInvokeCallback(const StatusAndStateCallback& callback, |
296 BackgroundSyncState status); | 291 BackgroundSyncState status); |
297 | 292 |
298 // GetRegistration callbacks | 293 // GetRegistration callbacks |
299 void GetRegistrationImpl(int64_t sw_registration_id, | 294 void GetRegistrationImpl(int64_t sw_registration_id, |
300 const RegistrationKey& registration_key, | 295 const RegistrationKey& registration_key, |
301 const StatusAndRegistrationCallback& callback); | 296 const StatusAndRegistrationCallback& callback); |
302 | 297 |
303 // GetRegistrations callbacks | 298 // GetRegistrations callbacks |
304 void GetRegistrationsImpl(int64_t sw_registration_id, | 299 void GetRegistrationsImpl(int64_t sw_registration_id, |
305 SyncPeriodicity periodicity, | |
306 const StatusAndRegistrationsCallback& callback); | 300 const StatusAndRegistrationsCallback& callback); |
307 | 301 |
308 bool AreOptionConditionsMet(const BackgroundSyncRegistrationOptions& options); | 302 bool AreOptionConditionsMet(const BackgroundSyncRegistrationOptions& options); |
309 bool IsRegistrationReadyToFire( | 303 bool IsRegistrationReadyToFire( |
310 const BackgroundSyncRegistration& registration); | 304 const BackgroundSyncRegistration& registration); |
311 | 305 |
312 // Determines if the browser needs to be able to run in the background (e.g., | 306 // Determines if the browser needs to be able to run in the background (e.g., |
313 // to run a pending registration or verify that a firing registration | 307 // to run a pending registration or verify that a firing registration |
314 // completed). If background processing is required it calls out to the | 308 // completed). If background processing is required it calls out to the |
315 // BackgroundSyncController to enable it. | 309 // BackgroundSyncController to enable it. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 scoped_ptr<base::Clock> clock_; | 405 scoped_ptr<base::Clock> clock_; |
412 | 406 |
413 base::WeakPtrFactory<BackgroundSyncManager> weak_ptr_factory_; | 407 base::WeakPtrFactory<BackgroundSyncManager> weak_ptr_factory_; |
414 | 408 |
415 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncManager); | 409 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncManager); |
416 }; | 410 }; |
417 | 411 |
418 } // namespace content | 412 } // namespace content |
419 | 413 |
420 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_ | 414 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_ |
OLD | NEW |