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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 static const RegistrationId kInitialId; | 57 static const RegistrationId kInitialId; |
58 BackgroundSyncRegistration() {} | 58 BackgroundSyncRegistration() {} |
59 | 59 |
60 bool Equals(const BackgroundSyncRegistration& other) const { | 60 bool Equals(const BackgroundSyncRegistration& other) const { |
61 return this->tag == other.tag && this->periodicity == other.periodicity && | 61 return this->tag == other.tag && this->periodicity == other.periodicity && |
62 this->min_period == other.min_period && | 62 this->min_period == other.min_period && |
63 network_state == other.network_state && | 63 network_state == other.network_state && |
64 power_state == other.power_state; | 64 power_state == other.power_state; |
65 } | 65 } |
66 | 66 |
67 RegistrationId id = kInvalidRegistrationId; | 67 // Registrations options from the specification |
68 std::string tag; | 68 std::string tag; |
69 SyncPeriodicity periodicity = SYNC_ONE_SHOT; | |
70 int64 min_period = 0; | 69 int64 min_period = 0; |
71 SyncNetworkState network_state = NETWORK_STATE_ONLINE; | 70 SyncNetworkState network_state = NETWORK_STATE_ONLINE; |
72 SyncPowerState power_state = POWER_STATE_AVOID_DRAINING; | 71 SyncPowerState power_state = POWER_STATE_AVOID_DRAINING; |
| 72 |
| 73 // Implementation specific members |
| 74 RegistrationId id = kInvalidRegistrationId; |
| 75 SyncPeriodicity periodicity = SYNC_ONE_SHOT; |
| 76 SyncState sync_state = SYNC_STATE_PENDING; |
73 }; | 77 }; |
74 | 78 |
75 using StatusCallback = base::Callback<void(ErrorType)>; | 79 using StatusCallback = base::Callback<void(ErrorType)>; |
76 using StatusAndRegistrationCallback = | 80 using StatusAndRegistrationCallback = |
77 base::Callback<void(ErrorType, const BackgroundSyncRegistration&)>; | 81 base::Callback<void(ErrorType, const BackgroundSyncRegistration&)>; |
78 | 82 |
79 static scoped_ptr<BackgroundSyncManager> Create( | 83 static scoped_ptr<BackgroundSyncManager> Create( |
80 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context); | 84 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context); |
81 ~BackgroundSyncManager() override; | 85 ~BackgroundSyncManager() override; |
82 | 86 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 virtual void StoreDataInBackend( | 130 virtual void StoreDataInBackend( |
127 int64 sw_registration_id, | 131 int64 sw_registration_id, |
128 const GURL& origin, | 132 const GURL& origin, |
129 const std::string& backend_key, | 133 const std::string& backend_key, |
130 const std::string& data, | 134 const std::string& data, |
131 const ServiceWorkerStorage::StatusCallback& callback); | 135 const ServiceWorkerStorage::StatusCallback& callback); |
132 virtual void GetDataFromBackend( | 136 virtual void GetDataFromBackend( |
133 const std::string& backend_key, | 137 const std::string& backend_key, |
134 const ServiceWorkerStorage::GetUserDataForAllRegistrationsCallback& | 138 const ServiceWorkerStorage::GetUserDataForAllRegistrationsCallback& |
135 callback); | 139 callback); |
| 140 virtual void FireOneShotSync( |
| 141 const scoped_refptr<ServiceWorkerVersion>& active_version, |
| 142 const ServiceWorkerVersion::StatusCallback& callback); |
136 | 143 |
137 private: | 144 private: |
138 class RegistrationKey { | 145 class RegistrationKey { |
139 public: | 146 public: |
140 explicit RegistrationKey(const BackgroundSyncRegistration& registration); | 147 explicit RegistrationKey(const BackgroundSyncRegistration& registration); |
141 RegistrationKey(const std::string& tag, SyncPeriodicity periodicity); | 148 RegistrationKey(const std::string& tag, SyncPeriodicity periodicity); |
142 RegistrationKey(const RegistrationKey& other) = default; | 149 RegistrationKey(const RegistrationKey& other) = default; |
143 RegistrationKey& operator=(const RegistrationKey& other) = default; | 150 RegistrationKey& operator=(const RegistrationKey& other) = default; |
144 | 151 |
145 bool operator<(const RegistrationKey& rhs) const { | 152 bool operator<(const RegistrationKey& rhs) const { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 void UnregisterDidStore( | 228 void UnregisterDidStore( |
222 int64 sw_registration_id, | 229 int64 sw_registration_id, |
223 const StatusCallback& callback, | 230 const StatusCallback& callback, |
224 ServiceWorkerStatusCode status); | 231 ServiceWorkerStatusCode status); |
225 | 232 |
226 // GetRegistration callbacks | 233 // GetRegistration callbacks |
227 void GetRegistrationImpl(int64 sw_registration_id, | 234 void GetRegistrationImpl(int64 sw_registration_id, |
228 const RegistrationKey& registration_key, | 235 const RegistrationKey& registration_key, |
229 const StatusAndRegistrationCallback& callback); | 236 const StatusAndRegistrationCallback& callback); |
230 | 237 |
| 238 bool IsRegistrationReadyToFire( |
| 239 const BackgroundSyncRegistration& registration); |
| 240 |
| 241 // FireReadyEvents and callbacks |
| 242 void FireReadyEvents(); |
| 243 void FireReadyEventsImpl(const base::Closure& callback); |
| 244 void FireReadyEventsDidFindRegistration( |
| 245 const RegistrationKey& registration_key, |
| 246 BackgroundSyncRegistration::RegistrationId registration_id, |
| 247 const base::Closure& callback, |
| 248 ServiceWorkerStatusCode service_worker_status, |
| 249 const scoped_refptr<ServiceWorkerRegistration>& |
| 250 service_worker_registration); |
| 251 |
| 252 // Called when a sync event has completed. |
| 253 void EventComplete( |
| 254 const scoped_refptr<ServiceWorkerRegistration>& |
| 255 service_worker_registration, |
| 256 int64 service_worker_id, |
| 257 const RegistrationKey& key, |
| 258 BackgroundSyncRegistration::RegistrationId sync_registration_id, |
| 259 ServiceWorkerStatusCode status_code); |
| 260 void EventCompleteImpl( |
| 261 int64 service_worker_id, |
| 262 const RegistrationKey& key, |
| 263 BackgroundSyncRegistration::RegistrationId sync_registration_id, |
| 264 ServiceWorkerStatusCode status_code, |
| 265 const base::Closure& callback); |
| 266 void EventCompleteDidStore(int64 service_worker_id, |
| 267 const base::Closure& callback, |
| 268 ServiceWorkerStatusCode status_code); |
| 269 |
231 // OnRegistrationDeleted callbacks | 270 // OnRegistrationDeleted callbacks |
232 void OnRegistrationDeletedImpl(int64 registration_id, | 271 void OnRegistrationDeletedImpl(int64 registration_id, |
233 const base::Closure& callback); | 272 const base::Closure& callback); |
234 | 273 |
235 // OnStorageWiped callbacks | 274 // OnStorageWiped callbacks |
236 void OnStorageWipedImpl(const base::Closure& callback); | 275 void OnStorageWipedImpl(const base::Closure& callback); |
237 | 276 |
238 void OnNetworkChanged(); | 277 void OnNetworkChanged(); |
239 | 278 |
240 // Operation Scheduling callbacks | 279 // Operation Scheduling callbacks |
(...skipping 18 matching lines...) Expand all Loading... |
259 scoped_ptr<BackgroundSyncNetworkObserver> network_observer_; | 298 scoped_ptr<BackgroundSyncNetworkObserver> network_observer_; |
260 | 299 |
261 base::WeakPtrFactory<BackgroundSyncManager> weak_ptr_factory_; | 300 base::WeakPtrFactory<BackgroundSyncManager> weak_ptr_factory_; |
262 | 301 |
263 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncManager); | 302 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncManager); |
264 }; | 303 }; |
265 | 304 |
266 } // namespace content | 305 } // namespace content |
267 | 306 |
268 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_ | 307 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_ |
OLD | NEW |