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 |
11 #include <map> | 11 #include <map> |
12 #include <string> | 12 #include <string> |
13 #include <utility> | 13 #include <utility> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/callback_forward.h" | 16 #include "base/callback_forward.h" |
17 #include "base/cancelable_callback.h" | 17 #include "base/cancelable_callback.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
20 #include "base/memory/scoped_vector.h" | 20 #include "base/memory/scoped_vector.h" |
21 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
22 #include "base/time/clock.h" | 22 #include "base/time/clock.h" |
23 #include "content/browser/background_sync/background_sync.pb.h" | 23 #include "content/browser/background_sync/background_sync.pb.h" |
24 #include "content/browser/background_sync/background_sync_registration.h" | 24 #include "content/browser/background_sync/background_sync_registration.h" |
25 #include "content/browser/background_sync/background_sync_registration_handle.h" | |
26 #include "content/browser/background_sync/background_sync_status.h" | 25 #include "content/browser/background_sync/background_sync_status.h" |
27 #include "content/browser/cache_storage/cache_storage_scheduler.h" | 26 #include "content/browser/cache_storage/cache_storage_scheduler.h" |
28 #include "content/browser/service_worker/service_worker_context_observer.h" | 27 #include "content/browser/service_worker/service_worker_context_observer.h" |
29 #include "content/browser/service_worker/service_worker_storage.h" | 28 #include "content/browser/service_worker/service_worker_storage.h" |
30 #include "content/common/background_sync_service.mojom.h" | 29 #include "content/common/background_sync_service.mojom.h" |
31 #include "content/common/content_export.h" | 30 #include "content/common/content_export.h" |
32 #include "content/common/service_worker/service_worker_status_code.h" | 31 #include "content/common/service_worker/service_worker_status_code.h" |
33 #include "content/public/browser/background_sync_parameters.h" | 32 #include "content/public/browser/background_sync_parameters.h" |
34 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
35 #include "url/gurl.h" | 34 #include "url/gurl.h" |
36 | 35 |
37 namespace content { | 36 namespace content { |
38 | 37 |
39 class BackgroundSyncNetworkObserver; | 38 class BackgroundSyncNetworkObserver; |
40 class ServiceWorkerContextWrapper; | 39 class ServiceWorkerContextWrapper; |
41 | 40 |
42 // BackgroundSyncManager manages and stores the set of background sync | 41 // BackgroundSyncManager manages and stores the set of background sync |
43 // registrations across all registered service workers for a profile. | 42 // registrations across all registered service workers for a profile. |
44 // Registrations are stored along with their associated Service Worker | 43 // Registrations are stored along with their associated Service Worker |
45 // registration in ServiceWorkerStorage. If the ServiceWorker is unregistered, | 44 // registration in ServiceWorkerStorage. If the ServiceWorker is unregistered, |
46 // the sync registrations are removed. This class must be run on the IO | 45 // the sync registrations are removed. This class must be run on the IO |
47 // thread. The asynchronous methods are executed sequentially. | 46 // thread. The asynchronous methods are executed sequentially. |
48 class CONTENT_EXPORT BackgroundSyncManager | 47 class CONTENT_EXPORT BackgroundSyncManager |
49 : NON_EXPORTED_BASE(public ServiceWorkerContextObserver) { | 48 : NON_EXPORTED_BASE(public ServiceWorkerContextObserver) { |
50 public: | 49 public: |
51 using BoolCallback = base::Callback<void(bool)>; | 50 using BoolCallback = base::Callback<void(bool)>; |
52 using StatusCallback = base::Callback<void(BackgroundSyncStatus)>; | 51 using StatusCallback = base::Callback<void(BackgroundSyncStatus)>; |
53 using StatusAndRegistrationCallback = | 52 using StatusAndRegistrationCallback = |
54 base::Callback<void(BackgroundSyncStatus, | 53 base::Callback<void(BackgroundSyncStatus, |
55 scoped_ptr<BackgroundSyncRegistrationHandle>)>; | 54 scoped_ptr<BackgroundSyncRegistration>)>; |
56 using StatusAndRegistrationsCallback = base::Callback<void( | 55 using StatusAndRegistrationsCallback = base::Callback<void( |
57 BackgroundSyncStatus, | 56 BackgroundSyncStatus, |
58 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>>)>; | 57 scoped_ptr<ScopedVector<BackgroundSyncRegistration>>)>; |
59 | 58 |
60 static scoped_ptr<BackgroundSyncManager> Create( | 59 static scoped_ptr<BackgroundSyncManager> Create( |
61 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context); | 60 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context); |
62 ~BackgroundSyncManager() override; | 61 ~BackgroundSyncManager() override; |
63 | 62 |
64 // Stores the given background sync registration and adds it to the scheduling | 63 // Stores the given background sync registration and adds it to the scheduling |
65 // queue. It will overwrite an existing registration with the same tag unless | 64 // queue. It will overwrite an existing registration with the same tag unless |
66 // they're identical (save for the id). Calls |callback| with | 65 // they're identical (save for the id). Calls |callback| with |
67 // BACKGROUND_SYNC_STATUS_OK and the accepted registration on success. | 66 // BACKGROUND_SYNC_STATUS_OK and the accepted registration on success. |
68 // The accepted registration will have a unique id. It may also have altered | 67 // The accepted registration will have a unique id. It may also have altered |
69 // parameters if the user or UA chose different parameters than those | 68 // parameters if the user or UA chose different parameters than those |
70 // supplied. | 69 // supplied. |
71 void Register(int64_t sw_registration_id, | 70 void Register(int64_t sw_registration_id, |
72 const BackgroundSyncRegistrationOptions& options, | 71 const BackgroundSyncRegistrationOptions& options, |
73 bool requested_from_service_worker, | 72 bool requested_from_service_worker, |
74 const StatusAndRegistrationCallback& callback); | 73 const StatusAndRegistrationCallback& callback); |
75 | 74 |
76 // Finds the background sync registrations associated with | 75 // Finds the background sync registrations associated with |
77 // |sw_registration_id|. Calls |callback| with BACKGROUND_SYNC_STATUS_OK on | 76 // |sw_registration_id|. Calls |callback| with BACKGROUND_SYNC_STATUS_OK on |
78 // success. | 77 // success. |
79 void GetRegistrations(int64_t sw_registration_id, | 78 void GetRegistrations(int64_t sw_registration_id, |
80 const StatusAndRegistrationsCallback& callback); | 79 const StatusAndRegistrationsCallback& callback); |
81 | 80 |
82 // Given a HandleId |handle_id|, return a new handle for the same | |
83 // registration. | |
84 scoped_ptr<BackgroundSyncRegistrationHandle> DuplicateRegistrationHandle( | |
85 BackgroundSyncRegistrationHandle::HandleId handle_id); | |
86 | |
87 // ServiceWorkerContextObserver overrides. | 81 // ServiceWorkerContextObserver overrides. |
88 void OnRegistrationDeleted(int64_t sw_registration_id, | 82 void OnRegistrationDeleted(int64_t sw_registration_id, |
89 const GURL& pattern) override; | 83 const GURL& pattern) override; |
90 void OnStorageWiped() override; | 84 void OnStorageWiped() override; |
91 | 85 |
92 // Sets the max number of sync attempts after any pending operations have | 86 // Sets the max number of sync attempts after any pending operations have |
93 // completed. | 87 // completed. |
94 void SetMaxSyncAttemptsForTesting(int max_attempts); | 88 void SetMaxSyncAttemptsForTesting(int max_attempts); |
95 | 89 |
96 BackgroundSyncNetworkObserver* GetNetworkObserverForTesting() { | 90 BackgroundSyncNetworkObserver* GetNetworkObserverForTesting() { |
97 return network_observer_.get(); | 91 return network_observer_.get(); |
98 } | 92 } |
99 | 93 |
100 void set_clock(scoped_ptr<base::Clock> clock) { | 94 void set_clock(scoped_ptr<base::Clock> clock) { |
101 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 95 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
102 clock_ = std::move(clock); | 96 clock_ = std::move(clock); |
103 } | 97 } |
104 | 98 |
105 protected: | 99 protected: |
106 // A registration might be referenced by the client longer than | |
107 // the BackgroundSyncManager needs to keep track of it (e.g., the event has | |
108 // finished firing). The BackgroundSyncManager reference counts its | |
109 // registrations internally and every BackgroundSyncRegistrationHandle has a | |
110 // unique handle id which maps to a locally maintained (in | |
111 // client_registration_ids_) scoped_refptr. | |
112 class RefCountedRegistration; | |
113 | |
114 explicit BackgroundSyncManager( | 100 explicit BackgroundSyncManager( |
115 const scoped_refptr<ServiceWorkerContextWrapper>& context); | 101 const scoped_refptr<ServiceWorkerContextWrapper>& context); |
116 | 102 |
117 // Init must be called before any public member function. Only call it once. | 103 // Init must be called before any public member function. Only call it once. |
118 void Init(); | 104 void Init(); |
119 | 105 |
120 // The following methods are virtual for testing. | 106 // The following methods are virtual for testing. |
121 virtual void StoreDataInBackend( | 107 virtual void StoreDataInBackend( |
122 int64_t sw_registration_id, | 108 int64_t sw_registration_id, |
123 const GURL& origin, | 109 const GURL& origin, |
124 const std::string& backend_key, | 110 const std::string& backend_key, |
125 const std::string& data, | 111 const std::string& data, |
126 const ServiceWorkerStorage::StatusCallback& callback); | 112 const ServiceWorkerStorage::StatusCallback& callback); |
127 virtual void GetDataFromBackend( | 113 virtual void GetDataFromBackend( |
128 const std::string& backend_key, | 114 const std::string& backend_key, |
129 const ServiceWorkerStorage::GetUserDataForAllRegistrationsCallback& | 115 const ServiceWorkerStorage::GetUserDataForAllRegistrationsCallback& |
130 callback); | 116 callback); |
131 virtual void DispatchSyncEvent( | 117 virtual void DispatchSyncEvent( |
132 BackgroundSyncRegistrationHandle::HandleId handle_id, | 118 const std::string& tag, |
133 const scoped_refptr<ServiceWorkerVersion>& active_version, | 119 const scoped_refptr<ServiceWorkerVersion>& active_version, |
134 BackgroundSyncEventLastChance last_chance, | 120 BackgroundSyncEventLastChance last_chance, |
135 const ServiceWorkerVersion::StatusCallback& callback); | 121 const ServiceWorkerVersion::StatusCallback& callback); |
136 virtual void ScheduleDelayedTask(const base::Closure& callback, | 122 virtual void ScheduleDelayedTask(const base::Closure& callback, |
137 base::TimeDelta delay); | 123 base::TimeDelta delay); |
138 virtual void HasMainFrameProviderHost(const GURL& origin, | 124 virtual void HasMainFrameProviderHost(const GURL& origin, |
139 const BoolCallback& callback); | 125 const BoolCallback& callback); |
140 | 126 |
141 private: | 127 private: |
142 friend class TestBackgroundSyncManager; | 128 friend class TestBackgroundSyncManager; |
143 friend class BackgroundSyncManagerTest; | 129 friend class BackgroundSyncManagerTest; |
144 friend class BackgroundSyncRegistrationHandle; | |
145 | 130 |
146 class RegistrationKey { | 131 class RegistrationKey { |
147 public: | 132 public: |
148 explicit RegistrationKey(const BackgroundSyncRegistration& registration); | 133 explicit RegistrationKey(const BackgroundSyncRegistration& registration); |
149 explicit RegistrationKey(const BackgroundSyncRegistrationOptions& options); | 134 explicit RegistrationKey(const BackgroundSyncRegistrationOptions& options); |
150 RegistrationKey(const std::string& tag); | 135 RegistrationKey(const std::string& tag); |
151 RegistrationKey(const RegistrationKey& other) = default; | 136 RegistrationKey(const RegistrationKey& other) = default; |
152 RegistrationKey& operator=(const RegistrationKey& other) = default; | 137 RegistrationKey& operator=(const RegistrationKey& other) = default; |
153 | 138 |
154 bool operator<(const RegistrationKey& rhs) const { | 139 bool operator<(const RegistrationKey& rhs) const { |
155 return value_ < rhs.value_; | 140 return value_ < rhs.value_; |
156 } | 141 } |
157 | 142 |
158 private: | 143 private: |
159 std::string value_; | 144 std::string value_; |
160 }; | 145 }; |
161 | 146 |
162 struct BackgroundSyncRegistrations { | 147 struct BackgroundSyncRegistrations { |
163 using RegistrationMap = | 148 using RegistrationMap = |
164 std::map<RegistrationKey, scoped_refptr<RefCountedRegistration>>; | 149 std::map<RegistrationKey, BackgroundSyncRegistration>; |
165 | 150 |
166 BackgroundSyncRegistrations(); | 151 BackgroundSyncRegistrations(); |
167 BackgroundSyncRegistrations(const BackgroundSyncRegistrations& other); | 152 BackgroundSyncRegistrations(const BackgroundSyncRegistrations& other); |
168 ~BackgroundSyncRegistrations(); | 153 ~BackgroundSyncRegistrations(); |
169 | 154 |
170 RegistrationMap registration_map; | 155 RegistrationMap registration_map; |
171 BackgroundSyncRegistration::RegistrationId next_id; | 156 BackgroundSyncRegistration::RegistrationId next_id; |
172 GURL origin; | 157 GURL origin; |
173 }; | 158 }; |
174 | 159 |
175 using PermissionStatusCallback = base::Callback<void(bool)>; | 160 using PermissionStatusCallback = base::Callback<void(bool)>; |
176 using SWIdToRegistrationsMap = std::map<int64_t, BackgroundSyncRegistrations>; | 161 using SWIdToRegistrationsMap = std::map<int64_t, BackgroundSyncRegistrations>; |
177 | 162 |
178 static const size_t kMaxTagLength = 10240; | 163 static const size_t kMaxTagLength = 10240; |
179 | 164 |
180 scoped_ptr<BackgroundSyncRegistrationHandle> CreateRegistrationHandle( | |
181 const scoped_refptr<RefCountedRegistration>& registration); | |
182 | |
183 // Returns the BackgroundSyncRegistration corresponding to |handle_id|. | |
184 // Returns nullptr if the registration is not found. | |
185 BackgroundSyncRegistration* GetRegistrationForHandle( | |
186 BackgroundSyncRegistrationHandle::HandleId handle_id) const; | |
187 | |
188 // The BackgroundSyncManager holds references to registrations that have | |
189 // active Handles. The handles must call this on destruction. | |
190 void ReleaseRegistrationHandle( | |
191 BackgroundSyncRegistrationHandle::HandleId handle_id); | |
192 | |
193 // Disable the manager. Already queued operations will abort once they start | 165 // Disable the manager. Already queued operations will abort once they start |
194 // to run (in their impl methods). Future operations will not queue. | 166 // to run (in their impl methods). Future operations will not queue. |
195 // The list of active registrations is cleared and the backend is also cleared | 167 // The list of active registrations is cleared and the backend is also cleared |
196 // (if it's still functioning). The manager will reenable itself once it | 168 // (if it's still functioning). The manager will reenable itself once it |
197 // receives the OnStorageWiped message or on browser restart. | 169 // receives the OnStorageWiped message or on browser restart. |
198 void DisableAndClearManager(const base::Closure& callback); | 170 void DisableAndClearManager(const base::Closure& callback); |
199 void DisableAndClearDidGetRegistrations( | 171 void DisableAndClearDidGetRegistrations( |
200 const base::Closure& callback, | 172 const base::Closure& callback, |
201 const std::vector<std::pair<int64_t, std::string>>& user_data, | 173 const std::vector<std::pair<int64_t, std::string>>& user_data, |
202 ServiceWorkerStatusCode status); | 174 ServiceWorkerStatusCode status); |
203 void DisableAndClearManagerClearedOne(const base::Closure& barrier_closure, | 175 void DisableAndClearManagerClearedOne(const base::Closure& barrier_closure, |
204 ServiceWorkerStatusCode status); | 176 ServiceWorkerStatusCode status); |
205 | 177 |
206 // Returns the existing registration or nullptr if it cannot be found. | 178 // Returns the existing registration or nullptr if it cannot be found. |
207 RefCountedRegistration* LookupActiveRegistration( | 179 BackgroundSyncRegistration* LookupActiveRegistration( |
208 int64_t sw_registration_id, | 180 int64_t sw_registration_id, |
209 const RegistrationKey& registration_key); | 181 const RegistrationKey& registration_key); |
210 | 182 |
211 // Write all registrations for a given |sw_registration_id| to persistent | 183 // Write all registrations for a given |sw_registration_id| to persistent |
212 // storage. | 184 // storage. |
213 void StoreRegistrations(int64_t sw_registration_id, | 185 void StoreRegistrations(int64_t sw_registration_id, |
214 const ServiceWorkerStorage::StatusCallback& callback); | 186 const ServiceWorkerStorage::StatusCallback& callback); |
215 | 187 |
216 // Removes the active registration if it is in the map. | 188 // Removes the active registration if it is in the map. |
217 void RemoveActiveRegistration(int64_t sw_registration_id, | 189 void RemoveActiveRegistration(int64_t sw_registration_id, |
218 const RegistrationKey& registration_key); | 190 const RegistrationKey& registration_key); |
219 | 191 |
220 void AddActiveRegistration( | 192 void AddActiveRegistration( |
221 int64_t sw_registration_id, | 193 int64_t sw_registration_id, |
222 const GURL& origin, | 194 const GURL& origin, |
223 const scoped_refptr<RefCountedRegistration>& sync_registration); | 195 const BackgroundSyncRegistration& sync_registration); |
224 | 196 |
225 void InitImpl(const base::Closure& callback); | 197 void InitImpl(const base::Closure& callback); |
226 void InitDidGetControllerParameters( | 198 void InitDidGetControllerParameters( |
227 const base::Closure& callback, | 199 const base::Closure& callback, |
228 scoped_ptr<BackgroundSyncParameters> parameters); | 200 scoped_ptr<BackgroundSyncParameters> parameters); |
229 void InitDidGetDataFromBackend( | 201 void InitDidGetDataFromBackend( |
230 const base::Closure& callback, | 202 const base::Closure& callback, |
231 const std::vector<std::pair<int64_t, std::string>>& user_data, | 203 const std::vector<std::pair<int64_t, std::string>>& user_data, |
232 ServiceWorkerStatusCode status); | 204 ServiceWorkerStatusCode status); |
233 | 205 |
234 // Register callbacks | 206 // Register callbacks |
235 void RegisterCheckIfHasMainFrame( | 207 void RegisterCheckIfHasMainFrame( |
236 int64_t sw_registration_id, | 208 int64_t sw_registration_id, |
237 const BackgroundSyncRegistrationOptions& options, | 209 const BackgroundSyncRegistrationOptions& options, |
238 const StatusAndRegistrationCallback& callback); | 210 const StatusAndRegistrationCallback& callback); |
239 void RegisterDidCheckIfMainFrame( | 211 void RegisterDidCheckIfMainFrame( |
240 int64_t sw_registration_id, | 212 int64_t sw_registration_id, |
241 const BackgroundSyncRegistrationOptions& options, | 213 const BackgroundSyncRegistrationOptions& options, |
242 const StatusAndRegistrationCallback& callback, | 214 const StatusAndRegistrationCallback& callback, |
243 bool has_main_frame_client); | 215 bool has_main_frame_client); |
244 void RegisterImpl(int64_t sw_registration_id, | 216 void RegisterImpl(int64_t sw_registration_id, |
245 const BackgroundSyncRegistrationOptions& options, | 217 const BackgroundSyncRegistrationOptions& options, |
246 const StatusAndRegistrationCallback& callback); | 218 const StatusAndRegistrationCallback& callback); |
247 void RegisterDidStore( | 219 void RegisterDidStore(int64_t sw_registration_id, |
248 int64_t sw_registration_id, | 220 const BackgroundSyncRegistration& new_registration, |
249 const scoped_refptr<RefCountedRegistration>& new_registration_ref, | 221 const StatusAndRegistrationCallback& callback, |
250 const StatusAndRegistrationCallback& callback, | 222 ServiceWorkerStatusCode status); |
251 ServiceWorkerStatusCode status); | |
252 | 223 |
253 // GetRegistrations callbacks | 224 // GetRegistrations callbacks |
254 void GetRegistrationsImpl(int64_t sw_registration_id, | 225 void GetRegistrationsImpl(int64_t sw_registration_id, |
255 const StatusAndRegistrationsCallback& callback); | 226 const StatusAndRegistrationsCallback& callback); |
256 | 227 |
257 bool AreOptionConditionsMet(const BackgroundSyncRegistrationOptions& options); | 228 bool AreOptionConditionsMet(const BackgroundSyncRegistrationOptions& options); |
258 bool IsRegistrationReadyToFire( | 229 bool IsRegistrationReadyToFire( |
259 const BackgroundSyncRegistration& registration); | 230 const BackgroundSyncRegistration& registration); |
260 | 231 |
261 // Determines if the browser needs to be able to run in the background (e.g., | 232 // Determines if the browser needs to be able to run in the background (e.g., |
(...skipping 13 matching lines...) Expand all Loading... |
275 const RegistrationKey& registration_key, | 246 const RegistrationKey& registration_key, |
276 BackgroundSyncRegistration::RegistrationId registration_id, | 247 BackgroundSyncRegistration::RegistrationId registration_id, |
277 const base::Closure& event_fired_callback, | 248 const base::Closure& event_fired_callback, |
278 const base::Closure& event_completed_callback, | 249 const base::Closure& event_completed_callback, |
279 ServiceWorkerStatusCode service_worker_status, | 250 ServiceWorkerStatusCode service_worker_status, |
280 const scoped_refptr<ServiceWorkerRegistration>& | 251 const scoped_refptr<ServiceWorkerRegistration>& |
281 service_worker_registration); | 252 service_worker_registration); |
282 void FireReadyEventsAllEventsFiring(const base::Closure& callback); | 253 void FireReadyEventsAllEventsFiring(const base::Closure& callback); |
283 | 254 |
284 // Called when a sync event has completed. | 255 // Called when a sync event has completed. |
285 void EventComplete( | 256 void EventComplete(const scoped_refptr<ServiceWorkerRegistration>& |
286 const scoped_refptr<ServiceWorkerRegistration>& | 257 service_worker_registration, |
287 service_worker_registration, | 258 int64_t service_worker_id, |
288 int64_t service_worker_id, | 259 const RegistrationKey& registration_key, |
289 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle, | 260 const base::Closure& callback, |
290 const base::Closure& callback, | 261 ServiceWorkerStatusCode status_code); |
291 ServiceWorkerStatusCode status_code); | 262 void EventCompleteImpl(int64_t service_worker_id, |
292 void EventCompleteImpl( | 263 const RegistrationKey& registration_key, |
293 int64_t service_worker_id, | 264 ServiceWorkerStatusCode status_code, |
294 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle, | 265 const base::Closure& callback); |
295 ServiceWorkerStatusCode status_code, | |
296 const base::Closure& callback); | |
297 void EventCompleteDidStore(int64_t service_worker_id, | 266 void EventCompleteDidStore(int64_t service_worker_id, |
298 const base::Closure& callback, | 267 const base::Closure& callback, |
299 ServiceWorkerStatusCode status_code); | 268 ServiceWorkerStatusCode status_code); |
300 | 269 |
301 // Called when all sync events have completed. | 270 // Called when all sync events have completed. |
302 static void OnAllSyncEventsCompleted(const base::TimeTicks& start_time, | 271 static void OnAllSyncEventsCompleted(const base::TimeTicks& start_time, |
303 int number_of_batched_sync_events); | 272 int number_of_batched_sync_events); |
304 | 273 |
305 // OnRegistrationDeleted callbacks | 274 // OnRegistrationDeleted callbacks |
306 void OnRegistrationDeletedImpl(int64_t sw_registration_id, | 275 void OnRegistrationDeletedImpl(int64_t sw_registration_id, |
307 const base::Closure& callback); | 276 const base::Closure& callback); |
308 | 277 |
309 // OnStorageWiped callbacks | 278 // OnStorageWiped callbacks |
310 void OnStorageWipedImpl(const base::Closure& callback); | 279 void OnStorageWipedImpl(const base::Closure& callback); |
311 | 280 |
312 void OnNetworkChanged(); | 281 void OnNetworkChanged(); |
313 | 282 |
314 // SetMaxSyncAttempts callback | 283 // SetMaxSyncAttempts callback |
315 void SetMaxSyncAttemptsImpl(int max_sync_attempts, | 284 void SetMaxSyncAttemptsImpl(int max_sync_attempts, |
316 const base::Closure& callback); | 285 const base::Closure& callback); |
317 | 286 |
318 // Operation Scheduling callback and convenience functions. | 287 // Operation Scheduling callback and convenience functions. |
319 template <typename CallbackT, typename... Params> | 288 template <typename CallbackT, typename... Params> |
320 void CompleteOperationCallback(const CallbackT& callback, | 289 void CompleteOperationCallback(const CallbackT& callback, |
321 Params... parameters); | 290 Params... parameters); |
322 void CompleteStatusAndRegistrationCallback( | 291 void CompleteStatusAndRegistrationCallback( |
323 StatusAndRegistrationCallback callback, | 292 StatusAndRegistrationCallback callback, |
324 BackgroundSyncStatus status, | 293 BackgroundSyncStatus status, |
325 scoped_ptr<BackgroundSyncRegistrationHandle> result); | 294 scoped_ptr<BackgroundSyncRegistration> registration); |
326 void CompleteStatusAndRegistrationsCallback( | 295 void CompleteStatusAndRegistrationsCallback( |
327 StatusAndRegistrationsCallback callback, | 296 StatusAndRegistrationsCallback callback, |
328 BackgroundSyncStatus status, | 297 BackgroundSyncStatus status, |
329 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>> results); | 298 scoped_ptr<ScopedVector<BackgroundSyncRegistration>> registrations); |
330 base::Closure MakeEmptyCompletion(); | 299 base::Closure MakeEmptyCompletion(); |
331 base::Closure MakeClosureCompletion(const base::Closure& callback); | 300 base::Closure MakeClosureCompletion(const base::Closure& callback); |
332 StatusAndRegistrationCallback MakeStatusAndRegistrationCompletion( | 301 StatusAndRegistrationCallback MakeStatusAndRegistrationCompletion( |
333 const StatusAndRegistrationCallback& callback); | 302 const StatusAndRegistrationCallback& callback); |
334 StatusAndRegistrationsCallback MakeStatusAndRegistrationsCompletion( | 303 StatusAndRegistrationsCallback MakeStatusAndRegistrationsCompletion( |
335 const StatusAndRegistrationsCallback& callback); | 304 const StatusAndRegistrationsCallback& callback); |
336 BackgroundSyncManager::StatusCallback MakeStatusCompletion( | 305 BackgroundSyncManager::StatusCallback MakeStatusCompletion( |
337 const StatusCallback& callback); | 306 const StatusCallback& callback); |
338 | 307 |
339 SWIdToRegistrationsMap active_registrations_; | 308 SWIdToRegistrationsMap active_registrations_; |
340 CacheStorageScheduler op_scheduler_; | 309 CacheStorageScheduler op_scheduler_; |
341 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | 310 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
342 | 311 |
343 scoped_ptr<BackgroundSyncParameters> parameters_; | 312 scoped_ptr<BackgroundSyncParameters> parameters_; |
344 | 313 |
345 // True if the manager is disabled and registrations should fail. | 314 // True if the manager is disabled and registrations should fail. |
346 bool disabled_; | 315 bool disabled_; |
347 | 316 |
348 // The number of registrations currently in the firing state. | 317 // The number of registrations currently in the firing state. |
349 int num_firing_registrations_; | 318 int num_firing_registrations_; |
350 | 319 |
351 base::CancelableCallback<void()> delayed_sync_task_; | 320 base::CancelableCallback<void()> delayed_sync_task_; |
352 | 321 |
353 scoped_ptr<BackgroundSyncNetworkObserver> network_observer_; | 322 scoped_ptr<BackgroundSyncNetworkObserver> network_observer_; |
354 | 323 |
355 // The registrations that clients have handles to. | |
356 IDMap<scoped_refptr<RefCountedRegistration>, | |
357 IDMapOwnPointer, | |
358 BackgroundSyncRegistrationHandle::HandleId> registration_handle_ids_; | |
359 | |
360 scoped_ptr<base::Clock> clock_; | 324 scoped_ptr<base::Clock> clock_; |
361 | 325 |
362 base::WeakPtrFactory<BackgroundSyncManager> weak_ptr_factory_; | 326 base::WeakPtrFactory<BackgroundSyncManager> weak_ptr_factory_; |
363 | 327 |
364 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncManager); | 328 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncManager); |
365 }; | 329 }; |
366 | 330 |
367 } // namespace content | 331 } // namespace content |
368 | 332 |
369 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_ | 333 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_ |
OLD | NEW |