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 <utility> |
| 8 |
7 #include "base/barrier_closure.h" | 9 #include "base/barrier_closure.h" |
8 #include "base/bind.h" | 10 #include "base/bind.h" |
9 #include "base/location.h" | 11 #include "base/location.h" |
10 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
11 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
12 #include "base/time/default_clock.h" | 14 #include "base/time/default_clock.h" |
13 #include "build/build_config.h" | 15 #include "build/build_config.h" |
14 #include "content/browser/background_sync/background_sync_metrics.h" | 16 #include "content/browser/background_sync/background_sync_metrics.h" |
15 #include "content/browser/background_sync/background_sync_network_observer.h" | 17 #include "content/browser/background_sync/background_sync_network_observer.h" |
16 #include "content/browser/background_sync/background_sync_power_observer.h" | 18 #include "content/browser/background_sync/background_sync_power_observer.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 const char kBackgroundSyncUserDataKey[] = "BackgroundSyncUserData"; | 51 const char kBackgroundSyncUserDataKey[] = "BackgroundSyncUserData"; |
50 | 52 |
51 // The amount of time that a sync event can fire for, in seconds. | 53 // The amount of time that a sync event can fire for, in seconds. |
52 const int kSyncEventSec = 3 * 60; // 3 minutes | 54 const int kSyncEventSec = 3 * 60; // 3 minutes |
53 | 55 |
54 void PostErrorResponse( | 56 void PostErrorResponse( |
55 BackgroundSyncStatus status, | 57 BackgroundSyncStatus status, |
56 const BackgroundSyncManager::StatusAndRegistrationCallback& callback) { | 58 const BackgroundSyncManager::StatusAndRegistrationCallback& callback) { |
57 base::ThreadTaskRunnerHandle::Get()->PostTask( | 59 base::ThreadTaskRunnerHandle::Get()->PostTask( |
58 FROM_HERE, | 60 FROM_HERE, |
59 base::Bind( | 61 base::Bind(callback, status, |
60 callback, status, | 62 base::Passed(scoped_ptr<BackgroundSyncRegistrationHandle>()))); |
61 base::Passed(scoped_ptr<BackgroundSyncRegistrationHandle>().Pass()))); | |
62 } | 63 } |
63 | 64 |
64 // Returns nullptr if the controller cannot be accessed for any reason. | 65 // Returns nullptr if the controller cannot be accessed for any reason. |
65 BackgroundSyncController* GetBackgroundSyncControllerOnUIThread( | 66 BackgroundSyncController* GetBackgroundSyncControllerOnUIThread( |
66 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) { | 67 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) { |
67 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 68 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
68 | 69 |
69 if (!service_worker_context) | 70 if (!service_worker_context) |
70 return nullptr; | 71 return nullptr; |
71 StoragePartitionImpl* storage_partition_impl = | 72 StoragePartitionImpl* storage_partition_impl = |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 scoped_ptr<BackgroundSyncParameters> GetControllerParameters( | 108 scoped_ptr<BackgroundSyncParameters> GetControllerParameters( |
108 const scoped_refptr<ServiceWorkerContextWrapper>& sw_context_wrapper, | 109 const scoped_refptr<ServiceWorkerContextWrapper>& sw_context_wrapper, |
109 scoped_ptr<BackgroundSyncParameters> parameters) { | 110 scoped_ptr<BackgroundSyncParameters> parameters) { |
110 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 111 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
111 | 112 |
112 BackgroundSyncController* background_sync_controller = | 113 BackgroundSyncController* background_sync_controller = |
113 GetBackgroundSyncControllerOnUIThread(sw_context_wrapper); | 114 GetBackgroundSyncControllerOnUIThread(sw_context_wrapper); |
114 | 115 |
115 if (!background_sync_controller) { | 116 if (!background_sync_controller) { |
116 // Return default ParameterOverrides which don't disable and don't override. | 117 // Return default ParameterOverrides which don't disable and don't override. |
117 return parameters.Pass(); | 118 return parameters; |
118 } | 119 } |
119 | 120 |
120 background_sync_controller->GetParameterOverrides(parameters.get()); | 121 background_sync_controller->GetParameterOverrides(parameters.get()); |
121 return parameters.Pass(); | 122 return parameters; |
122 } | 123 } |
123 | 124 |
124 } // namespace | 125 } // namespace |
125 | 126 |
126 BackgroundSyncManager::BackgroundSyncRegistrations:: | 127 BackgroundSyncManager::BackgroundSyncRegistrations:: |
127 BackgroundSyncRegistrations() | 128 BackgroundSyncRegistrations() |
128 : next_id(BackgroundSyncRegistration::kInitialId) { | 129 : next_id(BackgroundSyncRegistration::kInitialId) { |
129 } | 130 } |
130 | 131 |
131 BackgroundSyncManager::BackgroundSyncRegistrations:: | 132 BackgroundSyncManager::BackgroundSyncRegistrations:: |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 const StatusAndRegistrationsCallback& callback) { | 221 const StatusAndRegistrationsCallback& callback) { |
221 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 222 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
222 | 223 |
223 if (disabled_) { | 224 if (disabled_) { |
224 base::ThreadTaskRunnerHandle::Get()->PostTask( | 225 base::ThreadTaskRunnerHandle::Get()->PostTask( |
225 FROM_HERE, | 226 FROM_HERE, |
226 base::Bind( | 227 base::Bind( |
227 callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR, | 228 callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR, |
228 base::Passed( | 229 base::Passed( |
229 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>>( | 230 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>>( |
230 new ScopedVector<BackgroundSyncRegistrationHandle>()) | 231 new ScopedVector<BackgroundSyncRegistrationHandle>())))); |
231 .Pass()))); | |
232 return; | 232 return; |
233 } | 233 } |
234 | 234 |
235 op_scheduler_.ScheduleOperation( | 235 op_scheduler_.ScheduleOperation( |
236 base::Bind(&BackgroundSyncManager::GetRegistrationsImpl, | 236 base::Bind(&BackgroundSyncManager::GetRegistrationsImpl, |
237 weak_ptr_factory_.GetWeakPtr(), sw_registration_id, | 237 weak_ptr_factory_.GetWeakPtr(), sw_registration_id, |
238 periodicity, MakeStatusAndRegistrationsCompletion(callback))); | 238 periodicity, MakeStatusAndRegistrationsCompletion(callback))); |
239 } | 239 } |
240 | 240 |
241 // Given a HandleId |handle_id|, return a new handle for the same | 241 // Given a HandleId |handle_id|, return a new handle for the same |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 base::Bind(callback)); | 319 base::Bind(callback)); |
320 return; | 320 return; |
321 } | 321 } |
322 | 322 |
323 scoped_ptr<BackgroundSyncParameters> parameters_copy( | 323 scoped_ptr<BackgroundSyncParameters> parameters_copy( |
324 new BackgroundSyncParameters(*parameters_)); | 324 new BackgroundSyncParameters(*parameters_)); |
325 | 325 |
326 BrowserThread::PostTaskAndReplyWithResult( | 326 BrowserThread::PostTaskAndReplyWithResult( |
327 BrowserThread::UI, FROM_HERE, | 327 BrowserThread::UI, FROM_HERE, |
328 base::Bind(&GetControllerParameters, service_worker_context_, | 328 base::Bind(&GetControllerParameters, service_worker_context_, |
329 base::Passed(parameters_copy.Pass())), | 329 base::Passed(std::move(parameters_copy))), |
330 base::Bind(&BackgroundSyncManager::InitDidGetControllerParameters, | 330 base::Bind(&BackgroundSyncManager::InitDidGetControllerParameters, |
331 weak_ptr_factory_.GetWeakPtr(), callback)); | 331 weak_ptr_factory_.GetWeakPtr(), callback)); |
332 } | 332 } |
333 | 333 |
334 void BackgroundSyncManager::InitDidGetControllerParameters( | 334 void BackgroundSyncManager::InitDidGetControllerParameters( |
335 const base::Closure& callback, | 335 const base::Closure& callback, |
336 scoped_ptr<BackgroundSyncParameters> updated_parameters) { | 336 scoped_ptr<BackgroundSyncParameters> updated_parameters) { |
337 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 337 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
338 | 338 |
339 parameters_ = updated_parameters.Pass(); | 339 parameters_ = std::move(updated_parameters); |
340 if (parameters_->disable) { | 340 if (parameters_->disable) { |
341 disabled_ = true; | 341 disabled_ = true; |
342 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 342 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
343 base::Bind(callback)); | 343 base::Bind(callback)); |
344 return; | 344 return; |
345 } | 345 } |
346 | 346 |
347 GetDataFromBackend( | 347 GetDataFromBackend( |
348 kBackgroundSyncUserDataKey, | 348 kBackgroundSyncUserDataKey, |
349 base::Bind(&BackgroundSyncManager::InitDidGetDataFromBackend, | 349 base::Bind(&BackgroundSyncManager::InitDidGetDataFromBackend, |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 | 509 |
510 if (existing_registration->IsFiring()) { | 510 if (existing_registration->IsFiring()) { |
511 existing_registration->set_sync_state( | 511 existing_registration->set_sync_state( |
512 BACKGROUND_SYNC_STATE_REREGISTERED_WHILE_FIRING); | 512 BACKGROUND_SYNC_STATE_REREGISTERED_WHILE_FIRING); |
513 } | 513 } |
514 | 514 |
515 base::ThreadTaskRunnerHandle::Get()->PostTask( | 515 base::ThreadTaskRunnerHandle::Get()->PostTask( |
516 FROM_HERE, | 516 FROM_HERE, |
517 base::Bind( | 517 base::Bind( |
518 callback, BACKGROUND_SYNC_STATUS_OK, | 518 callback, BACKGROUND_SYNC_STATUS_OK, |
519 base::Passed( | 519 base::Passed(CreateRegistrationHandle(existing_registration_ref)))); |
520 CreateRegistrationHandle(existing_registration_ref).Pass()))); | |
521 return; | 520 return; |
522 } else { | 521 } else { |
523 existing_registration_ref->value()->SetUnregisteredState(); | 522 existing_registration_ref->value()->SetUnregisteredState(); |
524 } | 523 } |
525 } | 524 } |
526 | 525 |
527 scoped_refptr<RefCountedRegistration> new_ref_registration( | 526 scoped_refptr<RefCountedRegistration> new_ref_registration( |
528 new RefCountedRegistration()); | 527 new RefCountedRegistration()); |
529 BackgroundSyncRegistration* new_registration = new_ref_registration->value(); | 528 BackgroundSyncRegistration* new_registration = new_ref_registration->value(); |
530 | 529 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 } | 689 } |
691 | 690 |
692 if (status != SERVICE_WORKER_OK) { | 691 if (status != SERVICE_WORKER_OK) { |
693 LOG(ERROR) << "BackgroundSync failed to store registration due to backend " | 692 LOG(ERROR) << "BackgroundSync failed to store registration due to backend " |
694 "failure."; | 693 "failure."; |
695 BackgroundSyncMetrics::CountRegisterFailure( | 694 BackgroundSyncMetrics::CountRegisterFailure( |
696 new_registration->options()->periodicity, | 695 new_registration->options()->periodicity, |
697 BACKGROUND_SYNC_STATUS_STORAGE_ERROR); | 696 BACKGROUND_SYNC_STATUS_STORAGE_ERROR); |
698 DisableAndClearManager(base::Bind( | 697 DisableAndClearManager(base::Bind( |
699 callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR, | 698 callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR, |
700 base::Passed(scoped_ptr<BackgroundSyncRegistrationHandle>().Pass()))); | 699 base::Passed(scoped_ptr<BackgroundSyncRegistrationHandle>()))); |
701 return; | 700 return; |
702 } | 701 } |
703 | 702 |
704 BackgroundSyncMetrics::RegistrationCouldFire registration_could_fire = | 703 BackgroundSyncMetrics::RegistrationCouldFire registration_could_fire = |
705 AreOptionConditionsMet(*new_registration->options()) | 704 AreOptionConditionsMet(*new_registration->options()) |
706 ? BackgroundSyncMetrics::REGISTRATION_COULD_FIRE | 705 ? BackgroundSyncMetrics::REGISTRATION_COULD_FIRE |
707 : BackgroundSyncMetrics::REGISTRATION_COULD_NOT_FIRE; | 706 : BackgroundSyncMetrics::REGISTRATION_COULD_NOT_FIRE; |
708 BackgroundSyncMetrics::CountRegisterSuccess( | 707 BackgroundSyncMetrics::CountRegisterSuccess( |
709 new_registration->options()->periodicity, registration_could_fire, | 708 new_registration->options()->periodicity, registration_could_fire, |
710 BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE); | 709 BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE); |
711 | 710 |
712 FireReadyEvents(); | 711 FireReadyEvents(); |
713 base::ThreadTaskRunnerHandle::Get()->PostTask( | 712 base::ThreadTaskRunnerHandle::Get()->PostTask( |
714 FROM_HERE, | 713 FROM_HERE, |
715 base::Bind( | 714 base::Bind( |
716 callback, BACKGROUND_SYNC_STATUS_OK, | 715 callback, BACKGROUND_SYNC_STATUS_OK, |
717 base::Passed( | 716 base::Passed(CreateRegistrationHandle(new_registration_ref.get())))); |
718 CreateRegistrationHandle(new_registration_ref.get()).Pass()))); | |
719 } | 717 } |
720 | 718 |
721 void BackgroundSyncManager::RemoveActiveRegistration( | 719 void BackgroundSyncManager::RemoveActiveRegistration( |
722 int64_t sw_registration_id, | 720 int64_t sw_registration_id, |
723 const RegistrationKey& registration_key) { | 721 const RegistrationKey& registration_key) { |
724 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 722 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
725 DCHECK(LookupActiveRegistration(sw_registration_id, registration_key)); | 723 DCHECK(LookupActiveRegistration(sw_registration_id, registration_key)); |
726 | 724 |
727 BackgroundSyncRegistrations* registrations = | 725 BackgroundSyncRegistrations* registrations = |
728 &active_registrations_[sw_registration_id]; | 726 &active_registrations_[sw_registration_id]; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 BACKGROUND_SYNC_STATE_FAILED)); | 932 BACKGROUND_SYNC_STATE_FAILED)); |
935 return; | 933 return; |
936 } | 934 } |
937 | 935 |
938 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle = | 936 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle = |
939 DuplicateRegistrationHandle(handle_id); | 937 DuplicateRegistrationHandle(handle_id); |
940 | 938 |
941 op_scheduler_.ScheduleOperation( | 939 op_scheduler_.ScheduleOperation( |
942 base::Bind(&BackgroundSyncManager::NotifyWhenFinishedImpl, | 940 base::Bind(&BackgroundSyncManager::NotifyWhenFinishedImpl, |
943 weak_ptr_factory_.GetWeakPtr(), | 941 weak_ptr_factory_.GetWeakPtr(), |
944 base::Passed(registration_handle.Pass()), callback)); | 942 base::Passed(std::move(registration_handle)), callback)); |
945 } | 943 } |
946 | 944 |
947 void BackgroundSyncManager::NotifyWhenFinishedImpl( | 945 void BackgroundSyncManager::NotifyWhenFinishedImpl( |
948 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle, | 946 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle, |
949 const StatusAndStateCallback& callback) { | 947 const StatusAndStateCallback& callback) { |
950 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 948 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
951 DCHECK_EQ(SYNC_ONE_SHOT, registration_handle->options()->periodicity); | 949 DCHECK_EQ(SYNC_ONE_SHOT, registration_handle->options()->periodicity); |
952 | 950 |
953 if (disabled_) { | 951 if (disabled_) { |
954 base::ThreadTaskRunnerHandle::Get()->PostTask( | 952 base::ThreadTaskRunnerHandle::Get()->PostTask( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 RefCountedRegistration* registration = | 991 RefCountedRegistration* registration = |
994 LookupActiveRegistration(sw_registration_id, registration_key); | 992 LookupActiveRegistration(sw_registration_id, registration_key); |
995 if (!registration) { | 993 if (!registration) { |
996 PostErrorResponse(BACKGROUND_SYNC_STATUS_NOT_FOUND, callback); | 994 PostErrorResponse(BACKGROUND_SYNC_STATUS_NOT_FOUND, callback); |
997 return; | 995 return; |
998 } | 996 } |
999 | 997 |
1000 base::ThreadTaskRunnerHandle::Get()->PostTask( | 998 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1001 FROM_HERE, | 999 FROM_HERE, |
1002 base::Bind(callback, BACKGROUND_SYNC_STATUS_OK, | 1000 base::Bind(callback, BACKGROUND_SYNC_STATUS_OK, |
1003 base::Passed(CreateRegistrationHandle(registration).Pass()))); | 1001 base::Passed(CreateRegistrationHandle(registration)))); |
1004 } | 1002 } |
1005 | 1003 |
1006 void BackgroundSyncManager::GetRegistrationsImpl( | 1004 void BackgroundSyncManager::GetRegistrationsImpl( |
1007 int64_t sw_registration_id, | 1005 int64_t sw_registration_id, |
1008 SyncPeriodicity periodicity, | 1006 SyncPeriodicity periodicity, |
1009 const StatusAndRegistrationsCallback& callback) { | 1007 const StatusAndRegistrationsCallback& callback) { |
1010 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1008 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1011 | 1009 |
1012 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>> out_registrations( | 1010 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>> out_registrations( |
1013 new ScopedVector<BackgroundSyncRegistrationHandle>()); | 1011 new ScopedVector<BackgroundSyncRegistrationHandle>()); |
1014 | 1012 |
1015 if (disabled_) { | 1013 if (disabled_) { |
1016 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1014 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1017 FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR, | 1015 FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR, |
1018 base::Passed(out_registrations.Pass()))); | 1016 base::Passed(std::move(out_registrations)))); |
1019 return; | 1017 return; |
1020 } | 1018 } |
1021 | 1019 |
1022 SWIdToRegistrationsMap::iterator it = | 1020 SWIdToRegistrationsMap::iterator it = |
1023 active_registrations_.find(sw_registration_id); | 1021 active_registrations_.find(sw_registration_id); |
1024 | 1022 |
1025 if (it != active_registrations_.end()) { | 1023 if (it != active_registrations_.end()) { |
1026 const BackgroundSyncRegistrations& registrations = it->second; | 1024 const BackgroundSyncRegistrations& registrations = it->second; |
1027 for (const auto& tag_and_registration : registrations.registration_map) { | 1025 for (const auto& tag_and_registration : registrations.registration_map) { |
1028 RefCountedRegistration* registration = tag_and_registration.second.get(); | 1026 RefCountedRegistration* registration = tag_and_registration.second.get(); |
1029 if (registration->value()->options()->periodicity == periodicity) { | 1027 if (registration->value()->options()->periodicity == periodicity) { |
1030 out_registrations->push_back( | 1028 out_registrations->push_back( |
1031 CreateRegistrationHandle(registration).release()); | 1029 CreateRegistrationHandle(registration).release()); |
1032 } | 1030 } |
1033 } | 1031 } |
1034 } | 1032 } |
1035 | 1033 |
1036 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1034 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1037 FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_OK, | 1035 FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_OK, |
1038 base::Passed(out_registrations.Pass()))); | 1036 base::Passed(std::move(out_registrations)))); |
1039 } | 1037 } |
1040 | 1038 |
1041 bool BackgroundSyncManager::AreOptionConditionsMet( | 1039 bool BackgroundSyncManager::AreOptionConditionsMet( |
1042 const BackgroundSyncRegistrationOptions& options) { | 1040 const BackgroundSyncRegistrationOptions& options) { |
1043 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1041 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1044 return network_observer_->NetworkSufficient(options.network_state) && | 1042 return network_observer_->NetworkSufficient(options.network_state) && |
1045 power_observer_->PowerSufficient(options.power_state); | 1043 power_observer_->PowerSufficient(options.power_state); |
1046 } | 1044 } |
1047 | 1045 |
1048 bool BackgroundSyncManager::IsRegistrationReadyToFire( | 1046 bool BackgroundSyncManager::IsRegistrationReadyToFire( |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 ? BACKGROUND_SYNC_EVENT_LAST_CHANCE_IS_LAST_CHANCE | 1228 ? BACKGROUND_SYNC_EVENT_LAST_CHANCE_IS_LAST_CHANCE |
1231 : BACKGROUND_SYNC_EVENT_LAST_CHANCE_IS_NOT_LAST_CHANCE; | 1229 : BACKGROUND_SYNC_EVENT_LAST_CHANCE_IS_NOT_LAST_CHANCE; |
1232 | 1230 |
1233 HasMainFrameProviderHost( | 1231 HasMainFrameProviderHost( |
1234 service_worker_registration->pattern().GetOrigin(), | 1232 service_worker_registration->pattern().GetOrigin(), |
1235 base::Bind(&BackgroundSyncMetrics::RecordEventStarted, | 1233 base::Bind(&BackgroundSyncMetrics::RecordEventStarted, |
1236 registration->value()->options()->periodicity)); | 1234 registration->value()->options()->periodicity)); |
1237 | 1235 |
1238 FireOneShotSync( | 1236 FireOneShotSync( |
1239 handle_id, service_worker_registration->active_version(), last_chance, | 1237 handle_id, service_worker_registration->active_version(), last_chance, |
1240 base::Bind( | 1238 base::Bind(&BackgroundSyncManager::EventComplete, |
1241 &BackgroundSyncManager::EventComplete, weak_ptr_factory_.GetWeakPtr(), | 1239 weak_ptr_factory_.GetWeakPtr(), service_worker_registration, |
1242 service_worker_registration, service_worker_registration->id(), | 1240 service_worker_registration->id(), |
1243 base::Passed(registration_handle.Pass()), event_completed_callback)); | 1241 base::Passed(std::move(registration_handle)), |
| 1242 event_completed_callback)); |
1244 | 1243 |
1245 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1244 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1246 FROM_HERE, base::Bind(event_fired_callback)); | 1245 FROM_HERE, base::Bind(event_fired_callback)); |
1247 } | 1246 } |
1248 | 1247 |
1249 void BackgroundSyncManager::FireReadyEventsAllEventsFiring( | 1248 void BackgroundSyncManager::FireReadyEventsAllEventsFiring( |
1250 const base::Closure& callback) { | 1249 const base::Closure& callback) { |
1251 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1250 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1252 | 1251 |
1253 RunInBackgroundIfNecessary(); | 1252 RunInBackgroundIfNecessary(); |
1254 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 1253 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
1255 base::Bind(callback)); | 1254 base::Bind(callback)); |
1256 } | 1255 } |
1257 | 1256 |
1258 // |service_worker_registration| is just to keep the registration alive | 1257 // |service_worker_registration| is just to keep the registration alive |
1259 // while the event is firing. | 1258 // while the event is firing. |
1260 void BackgroundSyncManager::EventComplete( | 1259 void BackgroundSyncManager::EventComplete( |
1261 const scoped_refptr<ServiceWorkerRegistration>& service_worker_registration, | 1260 const scoped_refptr<ServiceWorkerRegistration>& service_worker_registration, |
1262 int64_t service_worker_id, | 1261 int64_t service_worker_id, |
1263 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle, | 1262 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle, |
1264 const base::Closure& callback, | 1263 const base::Closure& callback, |
1265 ServiceWorkerStatusCode status_code) { | 1264 ServiceWorkerStatusCode status_code) { |
1266 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1265 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1267 | 1266 |
1268 // Do not check for disabled as events that were firing when disabled should | 1267 // Do not check for disabled as events that were firing when disabled should |
1269 // be allowed to complete (for NotifyWhenFinished). | 1268 // be allowed to complete (for NotifyWhenFinished). |
1270 op_scheduler_.ScheduleOperation(base::Bind( | 1269 op_scheduler_.ScheduleOperation(base::Bind( |
1271 &BackgroundSyncManager::EventCompleteImpl, weak_ptr_factory_.GetWeakPtr(), | 1270 &BackgroundSyncManager::EventCompleteImpl, weak_ptr_factory_.GetWeakPtr(), |
1272 service_worker_id, base::Passed(registration_handle.Pass()), status_code, | 1271 service_worker_id, base::Passed(std::move(registration_handle)), |
1273 MakeClosureCompletion(callback))); | 1272 status_code, MakeClosureCompletion(callback))); |
1274 } | 1273 } |
1275 | 1274 |
1276 void BackgroundSyncManager::EventCompleteImpl( | 1275 void BackgroundSyncManager::EventCompleteImpl( |
1277 int64_t service_worker_id, | 1276 int64_t service_worker_id, |
1278 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle, | 1277 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle, |
1279 ServiceWorkerStatusCode status_code, | 1278 ServiceWorkerStatusCode status_code, |
1280 const base::Closure& callback) { | 1279 const base::Closure& callback) { |
1281 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1280 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1282 | 1281 |
1283 BackgroundSyncRegistration* registration = | 1282 BackgroundSyncRegistration* registration = |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1435 callback.Run(parameters...); | 1434 callback.Run(parameters...); |
1436 op_scheduler_.CompleteOperationAndRunNext(); | 1435 op_scheduler_.CompleteOperationAndRunNext(); |
1437 } | 1436 } |
1438 | 1437 |
1439 void BackgroundSyncManager::CompleteStatusAndRegistrationCallback( | 1438 void BackgroundSyncManager::CompleteStatusAndRegistrationCallback( |
1440 StatusAndRegistrationCallback callback, | 1439 StatusAndRegistrationCallback callback, |
1441 BackgroundSyncStatus status, | 1440 BackgroundSyncStatus status, |
1442 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle) { | 1441 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle) { |
1443 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1442 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1444 | 1443 |
1445 callback.Run(status, registration_handle.Pass()); | 1444 callback.Run(status, std::move(registration_handle)); |
1446 op_scheduler_.CompleteOperationAndRunNext(); | 1445 op_scheduler_.CompleteOperationAndRunNext(); |
1447 } | 1446 } |
1448 | 1447 |
1449 void BackgroundSyncManager::CompleteStatusAndRegistrationsCallback( | 1448 void BackgroundSyncManager::CompleteStatusAndRegistrationsCallback( |
1450 StatusAndRegistrationsCallback callback, | 1449 StatusAndRegistrationsCallback callback, |
1451 BackgroundSyncStatus status, | 1450 BackgroundSyncStatus status, |
1452 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>> | 1451 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>> |
1453 registration_handles) { | 1452 registration_handles) { |
1454 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1453 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1455 | 1454 |
1456 callback.Run(status, registration_handles.Pass()); | 1455 callback.Run(status, std::move(registration_handles)); |
1457 op_scheduler_.CompleteOperationAndRunNext(); | 1456 op_scheduler_.CompleteOperationAndRunNext(); |
1458 } | 1457 } |
1459 | 1458 |
1460 base::Closure BackgroundSyncManager::MakeEmptyCompletion() { | 1459 base::Closure BackgroundSyncManager::MakeEmptyCompletion() { |
1461 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1460 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1462 | 1461 |
1463 return MakeClosureCompletion(base::Bind(base::DoNothing)); | 1462 return MakeClosureCompletion(base::Bind(base::DoNothing)); |
1464 } | 1463 } |
1465 | 1464 |
1466 base::Closure BackgroundSyncManager::MakeClosureCompletion( | 1465 base::Closure BackgroundSyncManager::MakeClosureCompletion( |
(...skipping 29 matching lines...) Expand all Loading... |
1496 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { | 1495 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { |
1497 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1496 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1498 | 1497 |
1499 return base::Bind( | 1498 return base::Bind( |
1500 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, | 1499 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, |
1501 BackgroundSyncStatus>, | 1500 BackgroundSyncStatus>, |
1502 weak_ptr_factory_.GetWeakPtr(), callback); | 1501 weak_ptr_factory_.GetWeakPtr(), callback); |
1503 } | 1502 } |
1504 | 1503 |
1505 } // namespace content | 1504 } // namespace content |
OLD | NEW |