Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: content/browser/background_sync/background_sync_manager.h

Issue 1106523002: [BackgroundSync] Fire one-shot sync events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@store_origin
Patch Set: Rebase Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 static const RegistrationId kInitialId; 56 static const RegistrationId kInitialId;
57 BackgroundSyncRegistration() {} 57 BackgroundSyncRegistration() {}
58 58
59 bool Equals(const BackgroundSyncRegistration& other) const { 59 bool Equals(const BackgroundSyncRegistration& other) const {
60 return this->tag == other.tag && this->periodicity == other.periodicity && 60 return this->tag == other.tag && this->periodicity == other.periodicity &&
61 this->min_period == other.min_period && 61 this->min_period == other.min_period &&
62 network_state == other.network_state && 62 network_state == other.network_state &&
63 power_state == other.power_state; 63 power_state == other.power_state;
64 } 64 }
65 65
66 RegistrationId id = kInvalidRegistrationId; 66 // Registrations options from the specification
67 std::string tag; 67 std::string tag;
68 SyncPeriodicity periodicity = SYNC_ONE_SHOT;
69 int64 min_period = 0; 68 int64 min_period = 0;
70 SyncNetworkState network_state = NETWORK_STATE_ONLINE; 69 SyncNetworkState network_state = NETWORK_STATE_ONLINE;
71 SyncPowerState power_state = POWER_STATE_AVOID_DRAINING; 70 SyncPowerState power_state = POWER_STATE_AVOID_DRAINING;
71
72 // Implementation specific members
73 RegistrationId id = kInvalidRegistrationId;
74 SyncPeriodicity periodicity = SYNC_ONE_SHOT;
75 SyncState sync_state = SYNC_STATE_PENDING;
72 }; 76 };
73 77
74 using StatusCallback = base::Callback<void(ErrorType)>; 78 using StatusCallback = base::Callback<void(ErrorType)>;
75 using StatusAndRegistrationCallback = 79 using StatusAndRegistrationCallback =
76 base::Callback<void(ErrorType, const BackgroundSyncRegistration&)>; 80 base::Callback<void(ErrorType, const BackgroundSyncRegistration&)>;
77 81
78 static scoped_ptr<BackgroundSyncManager> Create( 82 static scoped_ptr<BackgroundSyncManager> Create(
79 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context); 83 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context);
80 ~BackgroundSyncManager() override; 84 ~BackgroundSyncManager() override;
81 85
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 virtual void StoreDataInBackend( 132 virtual void StoreDataInBackend(
129 int64 sw_registration_id, 133 int64 sw_registration_id,
130 const GURL& origin, 134 const GURL& origin,
131 const std::string& backend_key, 135 const std::string& backend_key,
132 const std::string& data, 136 const std::string& data,
133 const ServiceWorkerStorage::StatusCallback& callback); 137 const ServiceWorkerStorage::StatusCallback& callback);
134 virtual void GetDataFromBackend( 138 virtual void GetDataFromBackend(
135 const std::string& backend_key, 139 const std::string& backend_key,
136 const ServiceWorkerStorage::GetUserDataForAllRegistrationsCallback& 140 const ServiceWorkerStorage::GetUserDataForAllRegistrationsCallback&
137 callback); 141 callback);
142 virtual void FireOneShotSync(
143 const scoped_refptr<ServiceWorkerVersion>& active_version,
144 const ServiceWorkerVersion::StatusCallback& callback);
138 145
139 private: 146 private:
140 class RegistrationKey { 147 class RegistrationKey {
141 public: 148 public:
142 explicit RegistrationKey(const BackgroundSyncRegistration& registration); 149 explicit RegistrationKey(const BackgroundSyncRegistration& registration);
143 RegistrationKey(const std::string& tag, SyncPeriodicity periodicity); 150 RegistrationKey(const std::string& tag, SyncPeriodicity periodicity);
144 RegistrationKey(const RegistrationKey& other) = default; 151 RegistrationKey(const RegistrationKey& other) = default;
145 RegistrationKey& operator=(const RegistrationKey& other) = default; 152 RegistrationKey& operator=(const RegistrationKey& other) = default;
146 153
147 bool operator<(const RegistrationKey& rhs) const { 154 bool operator<(const RegistrationKey& rhs) const {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 void OnNetworkChanged(); 250 void OnNetworkChanged();
244 251
245 // Operation Scheduling callbacks 252 // Operation Scheduling callbacks
246 void PendingStatusAndRegistrationCallback( 253 void PendingStatusAndRegistrationCallback(
247 const StatusAndRegistrationCallback& callback, 254 const StatusAndRegistrationCallback& callback,
248 ErrorType error, 255 ErrorType error,
249 const BackgroundSyncRegistration& sync_registration); 256 const BackgroundSyncRegistration& sync_registration);
250 void PendingStatusCallback(const StatusCallback& callback, ErrorType error); 257 void PendingStatusCallback(const StatusCallback& callback, ErrorType error);
251 void PendingClosure(const base::Closure& closure); 258 void PendingClosure(const base::Closure& closure);
252 259
260 bool IsRegistrationReadyToFire(
261 const BackgroundSyncRegistration& registration);
262
263 // FireReadyEvents and callbacks
264 void FireReadyEvents();
265 void FireReadyEventsImpl(const base::Closure& callback);
266 void FireReadyEventsDidFindRegistration(
267 const RegistrationKey& registration_key,
268 BackgroundSyncRegistration::RegistrationId registration_id,
269 const base::Closure& callback,
270 ServiceWorkerStatusCode service_worker_status,
271 const scoped_refptr<ServiceWorkerRegistration>&
272 service_worker_registration);
273
274 // Called when a sync event has completed.
275 void EventComplete(
276 int64 service_worker_id,
277 const RegistrationKey& key,
278 BackgroundSyncRegistration::RegistrationId sync_registration_id,
279 ServiceWorkerStatusCode status_code);
280 void EventCompleteImpl(
281 int64 service_worker_id,
282 const RegistrationKey& key,
283 BackgroundSyncRegistration::RegistrationId sync_registration_id,
284 ServiceWorkerStatusCode status_code,
285 const base::Closure& callback);
286 void EventCompleteDidStore(int64 service_worker_id,
287 const base::Closure& callback,
288 ServiceWorkerStatusCode status_code);
289
253 StatusAndRegistrationCallback MakeStatusAndRegistrationCompletion( 290 StatusAndRegistrationCallback MakeStatusAndRegistrationCompletion(
254 const StatusAndRegistrationCallback& callback); 291 const StatusAndRegistrationCallback& callback);
255 BackgroundSyncManager::StatusCallback MakeStatusCompletion( 292 BackgroundSyncManager::StatusCallback MakeStatusCompletion(
256 const StatusCallback& callback); 293 const StatusCallback& callback);
257 base::Closure MakeEmptyCompletion(); 294 base::Closure MakeEmptyCompletion();
258 295
259 SWIdToRegistrationsMap sw_to_registrations_map_; 296 SWIdToRegistrationsMap sw_to_registrations_map_;
260 CacheStorageScheduler op_scheduler_; 297 CacheStorageScheduler op_scheduler_;
261 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; 298 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
262 bool disabled_; 299 bool disabled_;
263 300
264 scoped_ptr<BackgroundSyncNetworkObserver> network_observer_; 301 scoped_ptr<BackgroundSyncNetworkObserver> network_observer_;
265 302
266 base::WeakPtrFactory<BackgroundSyncManager> weak_ptr_factory_; 303 base::WeakPtrFactory<BackgroundSyncManager> weak_ptr_factory_;
267 304
268 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncManager); 305 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncManager);
269 }; 306 };
270 307
271 } // namespace content 308 } // namespace content
272 309
273 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_ 310 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698