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 #include "content/browser/background_sync/background_sync_manager.h" | 5 #include "content/browser/background_sync/background_sync_manager.h" |
6 | 6 |
7 #include "base/barrier_closure.h" | 7 #include "base/barrier_closure.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
12 #include "base/time/default_clock.h" | 12 #include "base/time/default_clock.h" |
| 13 #include "build/build_config.h" |
13 #include "content/browser/background_sync/background_sync_metrics.h" | 14 #include "content/browser/background_sync/background_sync_metrics.h" |
14 #include "content/browser/background_sync/background_sync_network_observer.h" | 15 #include "content/browser/background_sync/background_sync_network_observer.h" |
15 #include "content/browser/background_sync/background_sync_power_observer.h" | 16 #include "content/browser/background_sync/background_sync_power_observer.h" |
16 #include "content/browser/background_sync/background_sync_registration_handle.h" | 17 #include "content/browser/background_sync/background_sync_registration_handle.h" |
17 #include "content/browser/background_sync/background_sync_registration_options.h
" | 18 #include "content/browser/background_sync/background_sync_registration_options.h
" |
18 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 19 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
19 #include "content/browser/service_worker/service_worker_storage.h" | 20 #include "content/browser/service_worker/service_worker_storage.h" |
20 #include "content/browser/storage_partition_impl.h" | 21 #include "content/browser/storage_partition_impl.h" |
21 #include "content/public/browser/background_sync_controller.h" | 22 #include "content/public/browser/background_sync_controller.h" |
22 #include "content/public/browser/browser_context.h" | 23 #include "content/public/browser/browser_context.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 : RegistrationKey(options.tag, options.periodicity) { | 160 : RegistrationKey(options.tag, options.periodicity) { |
160 } | 161 } |
161 | 162 |
162 BackgroundSyncManager::RegistrationKey::RegistrationKey( | 163 BackgroundSyncManager::RegistrationKey::RegistrationKey( |
163 const std::string& tag, | 164 const std::string& tag, |
164 SyncPeriodicity periodicity) | 165 SyncPeriodicity periodicity) |
165 : value_(periodicity == SYNC_ONE_SHOT ? "o_" + tag : "p_" + tag) { | 166 : value_(periodicity == SYNC_ONE_SHOT ? "o_" + tag : "p_" + tag) { |
166 } | 167 } |
167 | 168 |
168 void BackgroundSyncManager::Register( | 169 void BackgroundSyncManager::Register( |
169 int64 sw_registration_id, | 170 int64_t sw_registration_id, |
170 const BackgroundSyncRegistrationOptions& options, | 171 const BackgroundSyncRegistrationOptions& options, |
171 bool requested_from_service_worker, | 172 bool requested_from_service_worker, |
172 const StatusAndRegistrationCallback& callback) { | 173 const StatusAndRegistrationCallback& callback) { |
173 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 174 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
174 | 175 |
175 if (disabled_) { | 176 if (disabled_) { |
176 BackgroundSyncMetrics::CountRegisterFailure( | 177 BackgroundSyncMetrics::CountRegisterFailure( |
177 options.periodicity, BACKGROUND_SYNC_STATUS_STORAGE_ERROR); | 178 options.periodicity, BACKGROUND_SYNC_STATUS_STORAGE_ERROR); |
178 PostErrorResponse(BACKGROUND_SYNC_STATUS_STORAGE_ERROR, callback); | 179 PostErrorResponse(BACKGROUND_SYNC_STATUS_STORAGE_ERROR, callback); |
179 return; | 180 return; |
180 } | 181 } |
181 | 182 |
182 if (requested_from_service_worker) { | 183 if (requested_from_service_worker) { |
183 op_scheduler_.ScheduleOperation( | 184 op_scheduler_.ScheduleOperation( |
184 base::Bind(&BackgroundSyncManager::RegisterCheckIfHasMainFrame, | 185 base::Bind(&BackgroundSyncManager::RegisterCheckIfHasMainFrame, |
185 weak_ptr_factory_.GetWeakPtr(), sw_registration_id, options, | 186 weak_ptr_factory_.GetWeakPtr(), sw_registration_id, options, |
186 MakeStatusAndRegistrationCompletion(callback))); | 187 MakeStatusAndRegistrationCompletion(callback))); |
187 return; | 188 return; |
188 } | 189 } |
189 | 190 |
190 op_scheduler_.ScheduleOperation( | 191 op_scheduler_.ScheduleOperation( |
191 base::Bind(&BackgroundSyncManager::RegisterImpl, | 192 base::Bind(&BackgroundSyncManager::RegisterImpl, |
192 weak_ptr_factory_.GetWeakPtr(), sw_registration_id, options, | 193 weak_ptr_factory_.GetWeakPtr(), sw_registration_id, options, |
193 MakeStatusAndRegistrationCompletion(callback))); | 194 MakeStatusAndRegistrationCompletion(callback))); |
194 } | 195 } |
195 | 196 |
196 void BackgroundSyncManager::GetRegistration( | 197 void BackgroundSyncManager::GetRegistration( |
197 int64 sw_registration_id, | 198 int64_t sw_registration_id, |
198 const std::string& sync_registration_tag, | 199 const std::string& sync_registration_tag, |
199 SyncPeriodicity periodicity, | 200 SyncPeriodicity periodicity, |
200 const StatusAndRegistrationCallback& callback) { | 201 const StatusAndRegistrationCallback& callback) { |
201 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 202 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
202 | 203 |
203 if (disabled_) { | 204 if (disabled_) { |
204 PostErrorResponse(BACKGROUND_SYNC_STATUS_STORAGE_ERROR, callback); | 205 PostErrorResponse(BACKGROUND_SYNC_STATUS_STORAGE_ERROR, callback); |
205 return; | 206 return; |
206 } | 207 } |
207 | 208 |
208 RegistrationKey registration_key(sync_registration_tag, periodicity); | 209 RegistrationKey registration_key(sync_registration_tag, periodicity); |
209 | 210 |
210 op_scheduler_.ScheduleOperation(base::Bind( | 211 op_scheduler_.ScheduleOperation(base::Bind( |
211 &BackgroundSyncManager::GetRegistrationImpl, | 212 &BackgroundSyncManager::GetRegistrationImpl, |
212 weak_ptr_factory_.GetWeakPtr(), sw_registration_id, registration_key, | 213 weak_ptr_factory_.GetWeakPtr(), sw_registration_id, registration_key, |
213 MakeStatusAndRegistrationCompletion(callback))); | 214 MakeStatusAndRegistrationCompletion(callback))); |
214 } | 215 } |
215 | 216 |
216 void BackgroundSyncManager::GetRegistrations( | 217 void BackgroundSyncManager::GetRegistrations( |
217 int64 sw_registration_id, | 218 int64_t sw_registration_id, |
218 SyncPeriodicity periodicity, | 219 SyncPeriodicity periodicity, |
219 const StatusAndRegistrationsCallback& callback) { | 220 const StatusAndRegistrationsCallback& callback) { |
220 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 221 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
221 | 222 |
222 if (disabled_) { | 223 if (disabled_) { |
223 base::ThreadTaskRunnerHandle::Get()->PostTask( | 224 base::ThreadTaskRunnerHandle::Get()->PostTask( |
224 FROM_HERE, | 225 FROM_HERE, |
225 base::Bind( | 226 base::Bind( |
226 callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR, | 227 callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR, |
227 base::Passed( | 228 base::Passed( |
(...skipping 16 matching lines...) Expand all Loading... |
244 BackgroundSyncRegistrationHandle::HandleId handle_id) { | 245 BackgroundSyncRegistrationHandle::HandleId handle_id) { |
245 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 246 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
246 | 247 |
247 scoped_refptr<RefCountedRegistration>* ref_registration = | 248 scoped_refptr<RefCountedRegistration>* ref_registration = |
248 registration_handle_ids_.Lookup(handle_id); | 249 registration_handle_ids_.Lookup(handle_id); |
249 if (!ref_registration) | 250 if (!ref_registration) |
250 return scoped_ptr<BackgroundSyncRegistrationHandle>(); | 251 return scoped_ptr<BackgroundSyncRegistrationHandle>(); |
251 return CreateRegistrationHandle(ref_registration->get()); | 252 return CreateRegistrationHandle(ref_registration->get()); |
252 } | 253 } |
253 | 254 |
254 void BackgroundSyncManager::OnRegistrationDeleted(int64 sw_registration_id, | 255 void BackgroundSyncManager::OnRegistrationDeleted(int64_t sw_registration_id, |
255 const GURL& pattern) { | 256 const GURL& pattern) { |
256 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 257 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
257 | 258 |
258 // Operations already in the queue will either fail when they write to storage | 259 // Operations already in the queue will either fail when they write to storage |
259 // or return stale results based on registrations loaded in memory. This is | 260 // or return stale results based on registrations loaded in memory. This is |
260 // inconsequential since the service worker is gone. | 261 // inconsequential since the service worker is gone. |
261 op_scheduler_.ScheduleOperation( | 262 op_scheduler_.ScheduleOperation( |
262 base::Bind(&BackgroundSyncManager::OnRegistrationDeletedImpl, | 263 base::Bind(&BackgroundSyncManager::OnRegistrationDeletedImpl, |
263 weak_ptr_factory_.GetWeakPtr(), sw_registration_id, | 264 weak_ptr_factory_.GetWeakPtr(), sw_registration_id, |
264 MakeEmptyCompletion())); | 265 MakeEmptyCompletion())); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 } | 345 } |
345 | 346 |
346 GetDataFromBackend( | 347 GetDataFromBackend( |
347 kBackgroundSyncUserDataKey, | 348 kBackgroundSyncUserDataKey, |
348 base::Bind(&BackgroundSyncManager::InitDidGetDataFromBackend, | 349 base::Bind(&BackgroundSyncManager::InitDidGetDataFromBackend, |
349 weak_ptr_factory_.GetWeakPtr(), callback)); | 350 weak_ptr_factory_.GetWeakPtr(), callback)); |
350 } | 351 } |
351 | 352 |
352 void BackgroundSyncManager::InitDidGetDataFromBackend( | 353 void BackgroundSyncManager::InitDidGetDataFromBackend( |
353 const base::Closure& callback, | 354 const base::Closure& callback, |
354 const std::vector<std::pair<int64, std::string>>& user_data, | 355 const std::vector<std::pair<int64_t, std::string>>& user_data, |
355 ServiceWorkerStatusCode status) { | 356 ServiceWorkerStatusCode status) { |
356 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 357 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
357 | 358 |
358 if (status != SERVICE_WORKER_OK && status != SERVICE_WORKER_ERROR_NOT_FOUND) { | 359 if (status != SERVICE_WORKER_OK && status != SERVICE_WORKER_ERROR_NOT_FOUND) { |
359 LOG(ERROR) << "BackgroundSync failed to init due to backend failure."; | 360 LOG(ERROR) << "BackgroundSync failed to init due to backend failure."; |
360 DisableAndClearManager(base::Bind(callback)); | 361 DisableAndClearManager(base::Bind(callback)); |
361 return; | 362 return; |
362 } | 363 } |
363 | 364 |
364 bool corruption_detected = false; | 365 bool corruption_detected = false; |
365 for (const std::pair<int64, std::string>& data : user_data) { | 366 for (const std::pair<int64_t, std::string>& data : user_data) { |
366 BackgroundSyncRegistrationsProto registrations_proto; | 367 BackgroundSyncRegistrationsProto registrations_proto; |
367 if (registrations_proto.ParseFromString(data.second)) { | 368 if (registrations_proto.ParseFromString(data.second)) { |
368 BackgroundSyncRegistrations* registrations = | 369 BackgroundSyncRegistrations* registrations = |
369 &active_registrations_[data.first]; | 370 &active_registrations_[data.first]; |
370 registrations->next_id = registrations_proto.next_registration_id(); | 371 registrations->next_id = registrations_proto.next_registration_id(); |
371 registrations->origin = GURL(registrations_proto.origin()); | 372 registrations->origin = GURL(registrations_proto.origin()); |
372 | 373 |
373 for (int i = 0, max = registrations_proto.registration_size(); i < max; | 374 for (int i = 0, max = registrations_proto.registration_size(); i < max; |
374 ++i) { | 375 ++i) { |
375 const BackgroundSyncRegistrationProto& registration_proto = | 376 const BackgroundSyncRegistrationProto& registration_proto = |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 return; | 413 return; |
413 } | 414 } |
414 | 415 |
415 FireReadyEvents(); | 416 FireReadyEvents(); |
416 | 417 |
417 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 418 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
418 base::Bind(callback)); | 419 base::Bind(callback)); |
419 } | 420 } |
420 | 421 |
421 void BackgroundSyncManager::RegisterCheckIfHasMainFrame( | 422 void BackgroundSyncManager::RegisterCheckIfHasMainFrame( |
422 int64 sw_registration_id, | 423 int64_t sw_registration_id, |
423 const BackgroundSyncRegistrationOptions& options, | 424 const BackgroundSyncRegistrationOptions& options, |
424 const StatusAndRegistrationCallback& callback) { | 425 const StatusAndRegistrationCallback& callback) { |
425 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 426 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
426 | 427 |
427 ServiceWorkerRegistration* sw_registration = | 428 ServiceWorkerRegistration* sw_registration = |
428 service_worker_context_->GetLiveRegistration(sw_registration_id); | 429 service_worker_context_->GetLiveRegistration(sw_registration_id); |
429 if (!sw_registration || !sw_registration->active_version()) { | 430 if (!sw_registration || !sw_registration->active_version()) { |
430 BackgroundSyncMetrics::CountRegisterFailure( | 431 BackgroundSyncMetrics::CountRegisterFailure( |
431 options.periodicity, BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER); | 432 options.periodicity, BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER); |
432 PostErrorResponse(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback); | 433 PostErrorResponse(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback); |
433 return; | 434 return; |
434 } | 435 } |
435 | 436 |
436 HasMainFrameProviderHost( | 437 HasMainFrameProviderHost( |
437 sw_registration->pattern().GetOrigin(), | 438 sw_registration->pattern().GetOrigin(), |
438 base::Bind(&BackgroundSyncManager::RegisterDidCheckIfMainFrame, | 439 base::Bind(&BackgroundSyncManager::RegisterDidCheckIfMainFrame, |
439 weak_ptr_factory_.GetWeakPtr(), sw_registration_id, options, | 440 weak_ptr_factory_.GetWeakPtr(), sw_registration_id, options, |
440 callback)); | 441 callback)); |
441 } | 442 } |
442 | 443 |
443 void BackgroundSyncManager::RegisterDidCheckIfMainFrame( | 444 void BackgroundSyncManager::RegisterDidCheckIfMainFrame( |
444 int64 sw_registration_id, | 445 int64_t sw_registration_id, |
445 const BackgroundSyncRegistrationOptions& options, | 446 const BackgroundSyncRegistrationOptions& options, |
446 const StatusAndRegistrationCallback& callback, | 447 const StatusAndRegistrationCallback& callback, |
447 bool has_main_frame_client) { | 448 bool has_main_frame_client) { |
448 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 449 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
449 | 450 |
450 if (!has_main_frame_client) { | 451 if (!has_main_frame_client) { |
451 BackgroundSyncMetrics::CountRegisterFailure( | 452 BackgroundSyncMetrics::CountRegisterFailure( |
452 options.periodicity, BACKGROUND_SYNC_STATUS_NOT_ALLOWED); | 453 options.periodicity, BACKGROUND_SYNC_STATUS_NOT_ALLOWED); |
453 PostErrorResponse(BACKGROUND_SYNC_STATUS_NOT_ALLOWED, callback); | 454 PostErrorResponse(BACKGROUND_SYNC_STATUS_NOT_ALLOWED, callback); |
454 return; | 455 return; |
455 } | 456 } |
456 RegisterImpl(sw_registration_id, options, callback); | 457 RegisterImpl(sw_registration_id, options, callback); |
457 } | 458 } |
458 | 459 |
459 void BackgroundSyncManager::RegisterImpl( | 460 void BackgroundSyncManager::RegisterImpl( |
460 int64 sw_registration_id, | 461 int64_t sw_registration_id, |
461 const BackgroundSyncRegistrationOptions& options, | 462 const BackgroundSyncRegistrationOptions& options, |
462 const StatusAndRegistrationCallback& callback) { | 463 const StatusAndRegistrationCallback& callback) { |
463 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 464 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
464 | 465 |
465 if (disabled_) { | 466 if (disabled_) { |
466 BackgroundSyncMetrics::CountRegisterFailure( | 467 BackgroundSyncMetrics::CountRegisterFailure( |
467 options.periodicity, BACKGROUND_SYNC_STATUS_STORAGE_ERROR); | 468 options.periodicity, BACKGROUND_SYNC_STATUS_STORAGE_ERROR); |
468 PostErrorResponse(BACKGROUND_SYNC_STATUS_STORAGE_ERROR, callback); | 469 PostErrorResponse(BACKGROUND_SYNC_STATUS_STORAGE_ERROR, callback); |
469 return; | 470 return; |
470 } | 471 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 // may be out of sync with storage (e.g., due to corruption detection on | 572 // may be out of sync with storage (e.g., due to corruption detection on |
572 // loading from storage), so reload the registrations from storage again. | 573 // loading from storage), so reload the registrations from storage again. |
573 GetDataFromBackend( | 574 GetDataFromBackend( |
574 kBackgroundSyncUserDataKey, | 575 kBackgroundSyncUserDataKey, |
575 base::Bind(&BackgroundSyncManager::DisableAndClearDidGetRegistrations, | 576 base::Bind(&BackgroundSyncManager::DisableAndClearDidGetRegistrations, |
576 weak_ptr_factory_.GetWeakPtr(), callback)); | 577 weak_ptr_factory_.GetWeakPtr(), callback)); |
577 } | 578 } |
578 | 579 |
579 void BackgroundSyncManager::DisableAndClearDidGetRegistrations( | 580 void BackgroundSyncManager::DisableAndClearDidGetRegistrations( |
580 const base::Closure& callback, | 581 const base::Closure& callback, |
581 const std::vector<std::pair<int64, std::string>>& user_data, | 582 const std::vector<std::pair<int64_t, std::string>>& user_data, |
582 ServiceWorkerStatusCode status) { | 583 ServiceWorkerStatusCode status) { |
583 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 584 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
584 | 585 |
585 if (status != SERVICE_WORKER_OK || user_data.empty()) { | 586 if (status != SERVICE_WORKER_OK || user_data.empty()) { |
586 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 587 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
587 base::Bind(callback)); | 588 base::Bind(callback)); |
588 return; | 589 return; |
589 } | 590 } |
590 | 591 |
591 base::Closure barrier_closure = | 592 base::Closure barrier_closure = |
(...skipping 12 matching lines...) Expand all Loading... |
604 ServiceWorkerStatusCode status) { | 605 ServiceWorkerStatusCode status) { |
605 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 606 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
606 | 607 |
607 // The status doesn't matter at this point, there is nothing else to be done. | 608 // The status doesn't matter at this point, there is nothing else to be done. |
608 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 609 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
609 base::Bind(barrier_closure)); | 610 base::Bind(barrier_closure)); |
610 } | 611 } |
611 | 612 |
612 BackgroundSyncManager::RefCountedRegistration* | 613 BackgroundSyncManager::RefCountedRegistration* |
613 BackgroundSyncManager::LookupActiveRegistration( | 614 BackgroundSyncManager::LookupActiveRegistration( |
614 int64 sw_registration_id, | 615 int64_t sw_registration_id, |
615 const RegistrationKey& registration_key) { | 616 const RegistrationKey& registration_key) { |
616 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 617 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
617 | 618 |
618 SWIdToRegistrationsMap::iterator it = | 619 SWIdToRegistrationsMap::iterator it = |
619 active_registrations_.find(sw_registration_id); | 620 active_registrations_.find(sw_registration_id); |
620 if (it == active_registrations_.end()) | 621 if (it == active_registrations_.end()) |
621 return nullptr; | 622 return nullptr; |
622 | 623 |
623 BackgroundSyncRegistrations& registrations = it->second; | 624 BackgroundSyncRegistrations& registrations = it->second; |
624 DCHECK_LE(BackgroundSyncRegistration::kInitialId, registrations.next_id); | 625 DCHECK_LE(BackgroundSyncRegistration::kInitialId, registrations.next_id); |
625 DCHECK(!registrations.origin.is_empty()); | 626 DCHECK(!registrations.origin.is_empty()); |
626 | 627 |
627 auto key_and_registration_iter = | 628 auto key_and_registration_iter = |
628 registrations.registration_map.find(registration_key); | 629 registrations.registration_map.find(registration_key); |
629 if (key_and_registration_iter == registrations.registration_map.end()) | 630 if (key_and_registration_iter == registrations.registration_map.end()) |
630 return nullptr; | 631 return nullptr; |
631 | 632 |
632 return key_and_registration_iter->second.get(); | 633 return key_and_registration_iter->second.get(); |
633 } | 634 } |
634 | 635 |
635 void BackgroundSyncManager::StoreRegistrations( | 636 void BackgroundSyncManager::StoreRegistrations( |
636 int64 sw_registration_id, | 637 int64_t sw_registration_id, |
637 const ServiceWorkerStorage::StatusCallback& callback) { | 638 const ServiceWorkerStorage::StatusCallback& callback) { |
638 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 639 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
639 | 640 |
640 // Serialize the data. | 641 // Serialize the data. |
641 const BackgroundSyncRegistrations& registrations = | 642 const BackgroundSyncRegistrations& registrations = |
642 active_registrations_[sw_registration_id]; | 643 active_registrations_[sw_registration_id]; |
643 BackgroundSyncRegistrationsProto registrations_proto; | 644 BackgroundSyncRegistrationsProto registrations_proto; |
644 registrations_proto.set_next_registration_id(registrations.next_id); | 645 registrations_proto.set_next_registration_id(registrations.next_id); |
645 registrations_proto.set_origin(registrations.origin.spec()); | 646 registrations_proto.set_origin(registrations.origin.spec()); |
646 | 647 |
(...skipping 15 matching lines...) Expand all Loading... |
662 } | 663 } |
663 std::string serialized; | 664 std::string serialized; |
664 bool success = registrations_proto.SerializeToString(&serialized); | 665 bool success = registrations_proto.SerializeToString(&serialized); |
665 DCHECK(success); | 666 DCHECK(success); |
666 | 667 |
667 StoreDataInBackend(sw_registration_id, registrations.origin, | 668 StoreDataInBackend(sw_registration_id, registrations.origin, |
668 kBackgroundSyncUserDataKey, serialized, callback); | 669 kBackgroundSyncUserDataKey, serialized, callback); |
669 } | 670 } |
670 | 671 |
671 void BackgroundSyncManager::RegisterDidStore( | 672 void BackgroundSyncManager::RegisterDidStore( |
672 int64 sw_registration_id, | 673 int64_t sw_registration_id, |
673 const scoped_refptr<RefCountedRegistration>& new_registration_ref, | 674 const scoped_refptr<RefCountedRegistration>& new_registration_ref, |
674 const StatusAndRegistrationCallback& callback, | 675 const StatusAndRegistrationCallback& callback, |
675 ServiceWorkerStatusCode status) { | 676 ServiceWorkerStatusCode status) { |
676 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 677 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
677 | 678 |
678 const BackgroundSyncRegistration* new_registration = | 679 const BackgroundSyncRegistration* new_registration = |
679 new_registration_ref->value(); | 680 new_registration_ref->value(); |
680 | 681 |
681 if (status == SERVICE_WORKER_ERROR_NOT_FOUND) { | 682 if (status == SERVICE_WORKER_ERROR_NOT_FOUND) { |
682 // The service worker registration is gone. | 683 // The service worker registration is gone. |
(...skipping 28 matching lines...) Expand all Loading... |
711 FireReadyEvents(); | 712 FireReadyEvents(); |
712 base::ThreadTaskRunnerHandle::Get()->PostTask( | 713 base::ThreadTaskRunnerHandle::Get()->PostTask( |
713 FROM_HERE, | 714 FROM_HERE, |
714 base::Bind( | 715 base::Bind( |
715 callback, BACKGROUND_SYNC_STATUS_OK, | 716 callback, BACKGROUND_SYNC_STATUS_OK, |
716 base::Passed( | 717 base::Passed( |
717 CreateRegistrationHandle(new_registration_ref.get()).Pass()))); | 718 CreateRegistrationHandle(new_registration_ref.get()).Pass()))); |
718 } | 719 } |
719 | 720 |
720 void BackgroundSyncManager::RemoveActiveRegistration( | 721 void BackgroundSyncManager::RemoveActiveRegistration( |
721 int64 sw_registration_id, | 722 int64_t sw_registration_id, |
722 const RegistrationKey& registration_key) { | 723 const RegistrationKey& registration_key) { |
723 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 724 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
724 DCHECK(LookupActiveRegistration(sw_registration_id, registration_key)); | 725 DCHECK(LookupActiveRegistration(sw_registration_id, registration_key)); |
725 | 726 |
726 BackgroundSyncRegistrations* registrations = | 727 BackgroundSyncRegistrations* registrations = |
727 &active_registrations_[sw_registration_id]; | 728 &active_registrations_[sw_registration_id]; |
728 | 729 |
729 registrations->registration_map.erase(registration_key); | 730 registrations->registration_map.erase(registration_key); |
730 } | 731 } |
731 | 732 |
732 void BackgroundSyncManager::AddActiveRegistration( | 733 void BackgroundSyncManager::AddActiveRegistration( |
733 int64 sw_registration_id, | 734 int64_t sw_registration_id, |
734 const GURL& origin, | 735 const GURL& origin, |
735 const scoped_refptr<RefCountedRegistration>& sync_registration) { | 736 const scoped_refptr<RefCountedRegistration>& sync_registration) { |
736 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 737 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
737 DCHECK(sync_registration->value()->IsValid()); | 738 DCHECK(sync_registration->value()->IsValid()); |
738 | 739 |
739 BackgroundSyncRegistrations* registrations = | 740 BackgroundSyncRegistrations* registrations = |
740 &active_registrations_[sw_registration_id]; | 741 &active_registrations_[sw_registration_id]; |
741 registrations->origin = origin; | 742 registrations->origin = origin; |
742 | 743 |
743 RegistrationKey registration_key(*sync_registration->value()); | 744 RegistrationKey registration_key(*sync_registration->value()); |
744 registrations->registration_map[registration_key] = sync_registration; | 745 registrations->registration_map[registration_key] = sync_registration; |
745 } | 746 } |
746 | 747 |
747 void BackgroundSyncManager::StoreDataInBackend( | 748 void BackgroundSyncManager::StoreDataInBackend( |
748 int64 sw_registration_id, | 749 int64_t sw_registration_id, |
749 const GURL& origin, | 750 const GURL& origin, |
750 const std::string& backend_key, | 751 const std::string& backend_key, |
751 const std::string& data, | 752 const std::string& data, |
752 const ServiceWorkerStorage::StatusCallback& callback) { | 753 const ServiceWorkerStorage::StatusCallback& callback) { |
753 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 754 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
754 | 755 |
755 service_worker_context_->StoreRegistrationUserData( | 756 service_worker_context_->StoreRegistrationUserData( |
756 sw_registration_id, origin, backend_key, data, callback); | 757 sw_registration_id, origin, backend_key, data, callback); |
757 } | 758 } |
758 | 759 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 } | 823 } |
823 | 824 |
824 void BackgroundSyncManager::ReleaseRegistrationHandle( | 825 void BackgroundSyncManager::ReleaseRegistrationHandle( |
825 BackgroundSyncRegistrationHandle::HandleId handle_id) { | 826 BackgroundSyncRegistrationHandle::HandleId handle_id) { |
826 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 827 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
827 DCHECK(registration_handle_ids_.Lookup(handle_id)); | 828 DCHECK(registration_handle_ids_.Lookup(handle_id)); |
828 registration_handle_ids_.Remove(handle_id); | 829 registration_handle_ids_.Remove(handle_id); |
829 } | 830 } |
830 | 831 |
831 void BackgroundSyncManager::Unregister( | 832 void BackgroundSyncManager::Unregister( |
832 int64 sw_registration_id, | 833 int64_t sw_registration_id, |
833 BackgroundSyncRegistrationHandle::HandleId handle_id, | 834 BackgroundSyncRegistrationHandle::HandleId handle_id, |
834 const StatusCallback& callback) { | 835 const StatusCallback& callback) { |
835 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 836 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
836 | 837 |
837 BackgroundSyncRegistration* registration = | 838 BackgroundSyncRegistration* registration = |
838 GetRegistrationForHandle(handle_id); | 839 GetRegistrationForHandle(handle_id); |
839 DCHECK(registration); | 840 DCHECK(registration); |
840 | 841 |
841 if (disabled_) { | 842 if (disabled_) { |
842 BackgroundSyncMetrics::CountUnregister( | 843 BackgroundSyncMetrics::CountUnregister( |
843 registration->options()->periodicity, | 844 registration->options()->periodicity, |
844 BACKGROUND_SYNC_STATUS_STORAGE_ERROR); | 845 BACKGROUND_SYNC_STATUS_STORAGE_ERROR); |
845 base::ThreadTaskRunnerHandle::Get()->PostTask( | 846 base::ThreadTaskRunnerHandle::Get()->PostTask( |
846 FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR)); | 847 FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR)); |
847 return; | 848 return; |
848 } | 849 } |
849 | 850 |
850 op_scheduler_.ScheduleOperation(base::Bind( | 851 op_scheduler_.ScheduleOperation(base::Bind( |
851 &BackgroundSyncManager::UnregisterImpl, weak_ptr_factory_.GetWeakPtr(), | 852 &BackgroundSyncManager::UnregisterImpl, weak_ptr_factory_.GetWeakPtr(), |
852 sw_registration_id, RegistrationKey(*registration), registration->id(), | 853 sw_registration_id, RegistrationKey(*registration), registration->id(), |
853 registration->options()->periodicity, MakeStatusCompletion(callback))); | 854 registration->options()->periodicity, MakeStatusCompletion(callback))); |
854 } | 855 } |
855 | 856 |
856 void BackgroundSyncManager::UnregisterImpl( | 857 void BackgroundSyncManager::UnregisterImpl( |
857 int64 sw_registration_id, | 858 int64_t sw_registration_id, |
858 const RegistrationKey& registration_key, | 859 const RegistrationKey& registration_key, |
859 BackgroundSyncRegistration::RegistrationId sync_registration_id, | 860 BackgroundSyncRegistration::RegistrationId sync_registration_id, |
860 SyncPeriodicity periodicity, | 861 SyncPeriodicity periodicity, |
861 const StatusCallback& callback) { | 862 const StatusCallback& callback) { |
862 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 863 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
863 | 864 |
864 if (disabled_) { | 865 if (disabled_) { |
865 BackgroundSyncMetrics::CountUnregister( | 866 BackgroundSyncMetrics::CountUnregister( |
866 periodicity, BACKGROUND_SYNC_STATUS_STORAGE_ERROR); | 867 periodicity, BACKGROUND_SYNC_STATUS_STORAGE_ERROR); |
867 base::ThreadTaskRunnerHandle::Get()->PostTask( | 868 base::ThreadTaskRunnerHandle::Get()->PostTask( |
(...skipping 16 matching lines...) Expand all Loading... |
884 existing_registration->value()->SetUnregisteredState(); | 885 existing_registration->value()->SetUnregisteredState(); |
885 | 886 |
886 RemoveActiveRegistration(sw_registration_id, registration_key); | 887 RemoveActiveRegistration(sw_registration_id, registration_key); |
887 | 888 |
888 StoreRegistrations(sw_registration_id, | 889 StoreRegistrations(sw_registration_id, |
889 base::Bind(&BackgroundSyncManager::UnregisterDidStore, | 890 base::Bind(&BackgroundSyncManager::UnregisterDidStore, |
890 weak_ptr_factory_.GetWeakPtr(), | 891 weak_ptr_factory_.GetWeakPtr(), |
891 sw_registration_id, periodicity, callback)); | 892 sw_registration_id, periodicity, callback)); |
892 } | 893 } |
893 | 894 |
894 void BackgroundSyncManager::UnregisterDidStore(int64 sw_registration_id, | 895 void BackgroundSyncManager::UnregisterDidStore(int64_t sw_registration_id, |
895 SyncPeriodicity periodicity, | 896 SyncPeriodicity periodicity, |
896 const StatusCallback& callback, | 897 const StatusCallback& callback, |
897 ServiceWorkerStatusCode status) { | 898 ServiceWorkerStatusCode status) { |
898 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 899 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
899 | 900 |
900 if (status == SERVICE_WORKER_ERROR_NOT_FOUND) { | 901 if (status == SERVICE_WORKER_ERROR_NOT_FOUND) { |
901 // ServiceWorker was unregistered. | 902 // ServiceWorker was unregistered. |
902 BackgroundSyncMetrics::CountUnregister( | 903 BackgroundSyncMetrics::CountUnregister( |
903 periodicity, BACKGROUND_SYNC_STATUS_STORAGE_ERROR); | 904 periodicity, BACKGROUND_SYNC_STATUS_STORAGE_ERROR); |
904 active_registrations_.erase(sw_registration_id); | 905 active_registrations_.erase(sw_registration_id); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 | 973 |
973 void BackgroundSyncManager::NotifyWhenFinishedInvokeCallback( | 974 void BackgroundSyncManager::NotifyWhenFinishedInvokeCallback( |
974 const StatusAndStateCallback& callback, | 975 const StatusAndStateCallback& callback, |
975 BackgroundSyncState sync_state) { | 976 BackgroundSyncState sync_state) { |
976 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 977 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
977 | 978 |
978 callback.Run(BACKGROUND_SYNC_STATUS_OK, sync_state); | 979 callback.Run(BACKGROUND_SYNC_STATUS_OK, sync_state); |
979 } | 980 } |
980 | 981 |
981 void BackgroundSyncManager::GetRegistrationImpl( | 982 void BackgroundSyncManager::GetRegistrationImpl( |
982 int64 sw_registration_id, | 983 int64_t sw_registration_id, |
983 const RegistrationKey& registration_key, | 984 const RegistrationKey& registration_key, |
984 const StatusAndRegistrationCallback& callback) { | 985 const StatusAndRegistrationCallback& callback) { |
985 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 986 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
986 | 987 |
987 if (disabled_) { | 988 if (disabled_) { |
988 PostErrorResponse(BACKGROUND_SYNC_STATUS_STORAGE_ERROR, callback); | 989 PostErrorResponse(BACKGROUND_SYNC_STATUS_STORAGE_ERROR, callback); |
989 return; | 990 return; |
990 } | 991 } |
991 | 992 |
992 RefCountedRegistration* registration = | 993 RefCountedRegistration* registration = |
993 LookupActiveRegistration(sw_registration_id, registration_key); | 994 LookupActiveRegistration(sw_registration_id, registration_key); |
994 if (!registration) { | 995 if (!registration) { |
995 PostErrorResponse(BACKGROUND_SYNC_STATUS_NOT_FOUND, callback); | 996 PostErrorResponse(BACKGROUND_SYNC_STATUS_NOT_FOUND, callback); |
996 return; | 997 return; |
997 } | 998 } |
998 | 999 |
999 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1000 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1000 FROM_HERE, | 1001 FROM_HERE, |
1001 base::Bind(callback, BACKGROUND_SYNC_STATUS_OK, | 1002 base::Bind(callback, BACKGROUND_SYNC_STATUS_OK, |
1002 base::Passed(CreateRegistrationHandle(registration).Pass()))); | 1003 base::Passed(CreateRegistrationHandle(registration).Pass()))); |
1003 } | 1004 } |
1004 | 1005 |
1005 void BackgroundSyncManager::GetRegistrationsImpl( | 1006 void BackgroundSyncManager::GetRegistrationsImpl( |
1006 int64 sw_registration_id, | 1007 int64_t sw_registration_id, |
1007 SyncPeriodicity periodicity, | 1008 SyncPeriodicity periodicity, |
1008 const StatusAndRegistrationsCallback& callback) { | 1009 const StatusAndRegistrationsCallback& callback) { |
1009 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1010 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1010 | 1011 |
1011 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>> out_registrations( | 1012 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>> out_registrations( |
1012 new ScopedVector<BackgroundSyncRegistrationHandle>()); | 1013 new ScopedVector<BackgroundSyncRegistrationHandle>()); |
1013 | 1014 |
1014 if (disabled_) { | 1015 if (disabled_) { |
1015 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1016 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1016 FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR, | 1017 FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR, |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 void BackgroundSyncManager::FireReadyEventsImpl(const base::Closure& callback) { | 1130 void BackgroundSyncManager::FireReadyEventsImpl(const base::Closure& callback) { |
1130 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1131 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1131 | 1132 |
1132 if (disabled_) { | 1133 if (disabled_) { |
1133 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 1134 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
1134 base::Bind(callback)); | 1135 base::Bind(callback)); |
1135 return; | 1136 return; |
1136 } | 1137 } |
1137 | 1138 |
1138 // Find the registrations that are ready to run. | 1139 // Find the registrations that are ready to run. |
1139 std::vector<std::pair<int64, RegistrationKey>> sw_id_and_keys_to_fire; | 1140 std::vector<std::pair<int64_t, RegistrationKey>> sw_id_and_keys_to_fire; |
1140 | 1141 |
1141 for (auto& sw_id_and_registrations : active_registrations_) { | 1142 for (auto& sw_id_and_registrations : active_registrations_) { |
1142 const int64 service_worker_id = sw_id_and_registrations.first; | 1143 const int64_t service_worker_id = sw_id_and_registrations.first; |
1143 for (auto& key_and_registration : | 1144 for (auto& key_and_registration : |
1144 sw_id_and_registrations.second.registration_map) { | 1145 sw_id_and_registrations.second.registration_map) { |
1145 BackgroundSyncRegistration* registration = | 1146 BackgroundSyncRegistration* registration = |
1146 key_and_registration.second->value(); | 1147 key_and_registration.second->value(); |
1147 if (IsRegistrationReadyToFire(*registration)) { | 1148 if (IsRegistrationReadyToFire(*registration)) { |
1148 sw_id_and_keys_to_fire.push_back( | 1149 sw_id_and_keys_to_fire.push_back( |
1149 std::make_pair(service_worker_id, key_and_registration.first)); | 1150 std::make_pair(service_worker_id, key_and_registration.first)); |
1150 // The state change is not saved to persistent storage because | 1151 // The state change is not saved to persistent storage because |
1151 // if the sync event is killed mid-sync then it should return to | 1152 // if the sync event is killed mid-sync then it should return to |
1152 // SYNC_STATE_PENDING. | 1153 // SYNC_STATE_PENDING. |
(...skipping 18 matching lines...) Expand all Loading... |
1171 base::Bind(&BackgroundSyncManager::FireReadyEventsAllEventsFiring, | 1172 base::Bind(&BackgroundSyncManager::FireReadyEventsAllEventsFiring, |
1172 weak_ptr_factory_.GetWeakPtr(), callback)); | 1173 weak_ptr_factory_.GetWeakPtr(), callback)); |
1173 | 1174 |
1174 // Record the total time taken after all events have run to completion. | 1175 // Record the total time taken after all events have run to completion. |
1175 base::Closure events_completed_barrier_closure = | 1176 base::Closure events_completed_barrier_closure = |
1176 base::BarrierClosure(sw_id_and_keys_to_fire.size(), | 1177 base::BarrierClosure(sw_id_and_keys_to_fire.size(), |
1177 base::Bind(&OnAllSyncEventsCompleted, start_time, | 1178 base::Bind(&OnAllSyncEventsCompleted, start_time, |
1178 sw_id_and_keys_to_fire.size())); | 1179 sw_id_and_keys_to_fire.size())); |
1179 | 1180 |
1180 for (const auto& sw_id_and_key : sw_id_and_keys_to_fire) { | 1181 for (const auto& sw_id_and_key : sw_id_and_keys_to_fire) { |
1181 int64 service_worker_id = sw_id_and_key.first; | 1182 int64_t service_worker_id = sw_id_and_key.first; |
1182 const RefCountedRegistration* registration = | 1183 const RefCountedRegistration* registration = |
1183 LookupActiveRegistration(service_worker_id, sw_id_and_key.second); | 1184 LookupActiveRegistration(service_worker_id, sw_id_and_key.second); |
1184 DCHECK(registration); | 1185 DCHECK(registration); |
1185 | 1186 |
1186 service_worker_context_->FindReadyRegistrationForId( | 1187 service_worker_context_->FindReadyRegistrationForId( |
1187 service_worker_id, active_registrations_[service_worker_id].origin, | 1188 service_worker_id, active_registrations_[service_worker_id].origin, |
1188 base::Bind(&BackgroundSyncManager::FireReadyEventsDidFindRegistration, | 1189 base::Bind(&BackgroundSyncManager::FireReadyEventsDidFindRegistration, |
1189 weak_ptr_factory_.GetWeakPtr(), sw_id_and_key.second, | 1190 weak_ptr_factory_.GetWeakPtr(), sw_id_and_key.second, |
1190 registration->value()->id(), events_fired_barrier_closure, | 1191 registration->value()->id(), events_fired_barrier_closure, |
1191 events_completed_barrier_closure)); | 1192 events_completed_barrier_closure)); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1251 | 1252 |
1252 RunInBackgroundIfNecessary(); | 1253 RunInBackgroundIfNecessary(); |
1253 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 1254 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
1254 base::Bind(callback)); | 1255 base::Bind(callback)); |
1255 } | 1256 } |
1256 | 1257 |
1257 // |service_worker_registration| is just to keep the registration alive | 1258 // |service_worker_registration| is just to keep the registration alive |
1258 // while the event is firing. | 1259 // while the event is firing. |
1259 void BackgroundSyncManager::EventComplete( | 1260 void BackgroundSyncManager::EventComplete( |
1260 const scoped_refptr<ServiceWorkerRegistration>& service_worker_registration, | 1261 const scoped_refptr<ServiceWorkerRegistration>& service_worker_registration, |
1261 int64 service_worker_id, | 1262 int64_t service_worker_id, |
1262 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle, | 1263 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle, |
1263 const base::Closure& callback, | 1264 const base::Closure& callback, |
1264 ServiceWorkerStatusCode status_code) { | 1265 ServiceWorkerStatusCode status_code) { |
1265 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1266 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1266 | 1267 |
1267 // Do not check for disabled as events that were firing when disabled should | 1268 // Do not check for disabled as events that were firing when disabled should |
1268 // be allowed to complete (for NotifyWhenFinished). | 1269 // be allowed to complete (for NotifyWhenFinished). |
1269 op_scheduler_.ScheduleOperation(base::Bind( | 1270 op_scheduler_.ScheduleOperation(base::Bind( |
1270 &BackgroundSyncManager::EventCompleteImpl, weak_ptr_factory_.GetWeakPtr(), | 1271 &BackgroundSyncManager::EventCompleteImpl, weak_ptr_factory_.GetWeakPtr(), |
1271 service_worker_id, base::Passed(registration_handle.Pass()), status_code, | 1272 service_worker_id, base::Passed(registration_handle.Pass()), status_code, |
1272 MakeClosureCompletion(callback))); | 1273 MakeClosureCompletion(callback))); |
1273 } | 1274 } |
1274 | 1275 |
1275 void BackgroundSyncManager::EventCompleteImpl( | 1276 void BackgroundSyncManager::EventCompleteImpl( |
1276 int64 service_worker_id, | 1277 int64_t service_worker_id, |
1277 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle, | 1278 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle, |
1278 ServiceWorkerStatusCode status_code, | 1279 ServiceWorkerStatusCode status_code, |
1279 const base::Closure& callback) { | 1280 const base::Closure& callback) { |
1280 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1281 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1281 | 1282 |
1282 BackgroundSyncRegistration* registration = | 1283 BackgroundSyncRegistration* registration = |
1283 registration_handle->registration(); | 1284 registration_handle->registration(); |
1284 DCHECK(registration); | 1285 DCHECK(registration); |
1285 DCHECK(!registration->HasCompleted()); | 1286 DCHECK(!registration->HasCompleted()); |
1286 | 1287 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1350 return; | 1351 return; |
1351 } | 1352 } |
1352 | 1353 |
1353 StoreRegistrations( | 1354 StoreRegistrations( |
1354 service_worker_id, | 1355 service_worker_id, |
1355 base::Bind(&BackgroundSyncManager::EventCompleteDidStore, | 1356 base::Bind(&BackgroundSyncManager::EventCompleteDidStore, |
1356 weak_ptr_factory_.GetWeakPtr(), service_worker_id, callback)); | 1357 weak_ptr_factory_.GetWeakPtr(), service_worker_id, callback)); |
1357 } | 1358 } |
1358 | 1359 |
1359 void BackgroundSyncManager::EventCompleteDidStore( | 1360 void BackgroundSyncManager::EventCompleteDidStore( |
1360 int64 service_worker_id, | 1361 int64_t service_worker_id, |
1361 const base::Closure& callback, | 1362 const base::Closure& callback, |
1362 ServiceWorkerStatusCode status_code) { | 1363 ServiceWorkerStatusCode status_code) { |
1363 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1364 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1364 | 1365 |
1365 if (status_code == SERVICE_WORKER_ERROR_NOT_FOUND) { | 1366 if (status_code == SERVICE_WORKER_ERROR_NOT_FOUND) { |
1366 // The registration is gone. | 1367 // The registration is gone. |
1367 active_registrations_.erase(service_worker_id); | 1368 active_registrations_.erase(service_worker_id); |
1368 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 1369 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
1369 base::Bind(callback)); | 1370 base::Bind(callback)); |
1370 return; | 1371 return; |
(...skipping 16 matching lines...) Expand all Loading... |
1387 // static | 1388 // static |
1388 void BackgroundSyncManager::OnAllSyncEventsCompleted( | 1389 void BackgroundSyncManager::OnAllSyncEventsCompleted( |
1389 const base::TimeTicks& start_time, | 1390 const base::TimeTicks& start_time, |
1390 int number_of_batched_sync_events) { | 1391 int number_of_batched_sync_events) { |
1391 // Record the combined time taken by all sync events. | 1392 // Record the combined time taken by all sync events. |
1392 BackgroundSyncMetrics::RecordBatchSyncEventComplete( | 1393 BackgroundSyncMetrics::RecordBatchSyncEventComplete( |
1393 base::TimeTicks::Now() - start_time, number_of_batched_sync_events); | 1394 base::TimeTicks::Now() - start_time, number_of_batched_sync_events); |
1394 } | 1395 } |
1395 | 1396 |
1396 void BackgroundSyncManager::OnRegistrationDeletedImpl( | 1397 void BackgroundSyncManager::OnRegistrationDeletedImpl( |
1397 int64 sw_registration_id, | 1398 int64_t sw_registration_id, |
1398 const base::Closure& callback) { | 1399 const base::Closure& callback) { |
1399 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1400 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1400 | 1401 |
1401 // The backend (ServiceWorkerStorage) will delete the data, so just delete the | 1402 // The backend (ServiceWorkerStorage) will delete the data, so just delete the |
1402 // memory representation here. | 1403 // memory representation here. |
1403 active_registrations_.erase(sw_registration_id); | 1404 active_registrations_.erase(sw_registration_id); |
1404 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 1405 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
1405 base::Bind(callback)); | 1406 base::Bind(callback)); |
1406 } | 1407 } |
1407 | 1408 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1495 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { | 1496 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { |
1496 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1497 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1497 | 1498 |
1498 return base::Bind( | 1499 return base::Bind( |
1499 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, | 1500 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, |
1500 BackgroundSyncStatus>, | 1501 BackgroundSyncStatus>, |
1501 weak_ptr_factory_.GetWeakPtr(), callback); | 1502 weak_ptr_factory_.GetWeakPtr(), callback); |
1502 } | 1503 } |
1503 | 1504 |
1504 } // namespace content | 1505 } // namespace content |
OLD | NEW |