| 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" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 BackgroundSyncManager::RegistrationKey::RegistrationKey( | 67 BackgroundSyncManager::RegistrationKey::RegistrationKey( |
| 68 const std::string& tag, | 68 const std::string& tag, |
| 69 SyncPeriodicity periodicity) | 69 SyncPeriodicity periodicity) |
| 70 : value_(periodicity == SYNC_ONE_SHOT ? "o_" + tag : "p_" + tag) { | 70 : value_(periodicity == SYNC_ONE_SHOT ? "o_" + tag : "p_" + tag) { |
| 71 } | 71 } |
| 72 | 72 |
| 73 void BackgroundSyncManager::Register( | 73 void BackgroundSyncManager::Register( |
| 74 int64 sw_registration_id, | 74 int64 sw_registration_id, |
| 75 const BackgroundSyncRegistrationOptions& options, | 75 const BackgroundSyncRegistrationOptions& options, |
| 76 bool requested_from_service_worker, |
| 76 const StatusAndRegistrationCallback& callback) { | 77 const StatusAndRegistrationCallback& callback) { |
| 77 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 78 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 78 | 79 |
| 79 // For UMA, determine here whether the sync could fire immediately | 80 // For UMA, determine here whether the sync could fire immediately |
| 80 BackgroundSyncMetrics::RegistrationCouldFire registration_could_fire = | 81 BackgroundSyncMetrics::RegistrationCouldFire registration_could_fire = |
| 81 AreOptionConditionsMet(options) | 82 AreOptionConditionsMet(options) |
| 82 ? BackgroundSyncMetrics::REGISTRATION_COULD_FIRE | 83 ? BackgroundSyncMetrics::REGISTRATION_COULD_FIRE |
| 83 : BackgroundSyncMetrics::REGISTRATION_COULD_NOT_FIRE; | 84 : BackgroundSyncMetrics::REGISTRATION_COULD_NOT_FIRE; |
| 84 | 85 |
| 85 if (disabled_) { | 86 if (disabled_) { |
| 86 BackgroundSyncMetrics::CountRegister( | 87 BackgroundSyncMetrics::CountRegister( |
| 87 options.periodicity, registration_could_fire, | 88 options.periodicity, registration_could_fire, |
| 88 BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE, | 89 BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE, |
| 89 BACKGROUND_SYNC_STATUS_STORAGE_ERROR); | 90 BACKGROUND_SYNC_STATUS_STORAGE_ERROR); |
| 90 base::ThreadTaskRunnerHandle::Get()->PostTask( | 91 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 91 FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR, | 92 FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR, |
| 92 BackgroundSyncRegistration())); | 93 BackgroundSyncRegistration())); |
| 93 return; | 94 return; |
| 94 } | 95 } |
| 95 | 96 |
| 96 op_scheduler_.ScheduleOperation( | 97 op_scheduler_.ScheduleOperation(base::Bind( |
| 97 base::Bind(&BackgroundSyncManager::RegisterImpl, | 98 &BackgroundSyncManager::RegisterImpl, weak_ptr_factory_.GetWeakPtr(), |
| 98 weak_ptr_factory_.GetWeakPtr(), sw_registration_id, options, | 99 sw_registration_id, options, requested_from_service_worker, |
| 99 MakeStatusAndRegistrationCompletion(callback))); | 100 MakeStatusAndRegistrationCompletion(callback))); |
| 100 } | 101 } |
| 101 | 102 |
| 102 void BackgroundSyncManager::Unregister( | 103 void BackgroundSyncManager::Unregister( |
| 103 int64 sw_registration_id, | 104 int64 sw_registration_id, |
| 104 const std::string& sync_registration_tag, | 105 const std::string& sync_registration_tag, |
| 105 SyncPeriodicity periodicity, | 106 SyncPeriodicity periodicity, |
| 106 BackgroundSyncRegistration::RegistrationId sync_registration_id, | 107 BackgroundSyncRegistration::RegistrationId sync_registration_id, |
| 107 const StatusCallback& callback) { | 108 const StatusCallback& callback) { |
| 108 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 109 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 109 | 110 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 295 |
| 295 FireReadyEvents(); | 296 FireReadyEvents(); |
| 296 | 297 |
| 297 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 298 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 298 base::Bind(callback)); | 299 base::Bind(callback)); |
| 299 } | 300 } |
| 300 | 301 |
| 301 void BackgroundSyncManager::RegisterImpl( | 302 void BackgroundSyncManager::RegisterImpl( |
| 302 int64 sw_registration_id, | 303 int64 sw_registration_id, |
| 303 const BackgroundSyncRegistrationOptions& options, | 304 const BackgroundSyncRegistrationOptions& options, |
| 305 bool requested_from_service_worker, |
| 304 const StatusAndRegistrationCallback& callback) { | 306 const StatusAndRegistrationCallback& callback) { |
| 305 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 307 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 306 | 308 |
| 307 // For UMA, determine here whether the sync could fire immediately | 309 // For UMA, determine here whether the sync could fire immediately |
| 308 BackgroundSyncMetrics::RegistrationCouldFire registration_could_fire = | 310 BackgroundSyncMetrics::RegistrationCouldFire registration_could_fire = |
| 309 AreOptionConditionsMet(options) | 311 AreOptionConditionsMet(options) |
| 310 ? BackgroundSyncMetrics::REGISTRATION_COULD_FIRE | 312 ? BackgroundSyncMetrics::REGISTRATION_COULD_FIRE |
| 311 : BackgroundSyncMetrics::REGISTRATION_COULD_NOT_FIRE; | 313 : BackgroundSyncMetrics::REGISTRATION_COULD_NOT_FIRE; |
| 312 | 314 |
| 313 if (disabled_) { | 315 if (disabled_) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 328 options.periodicity, registration_could_fire, | 330 options.periodicity, registration_could_fire, |
| 329 BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE, | 331 BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE, |
| 330 BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER); | 332 BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER); |
| 331 base::ThreadTaskRunnerHandle::Get()->PostTask( | 333 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 332 FROM_HERE, | 334 FROM_HERE, |
| 333 base::Bind(callback, BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, | 335 base::Bind(callback, BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, |
| 334 BackgroundSyncRegistration())); | 336 BackgroundSyncRegistration())); |
| 335 return; | 337 return; |
| 336 } | 338 } |
| 337 | 339 |
| 338 if (!sw_registration->active_version()->HasWindowClients()) { | 340 if (requested_from_service_worker && |
| 341 !sw_registration->active_version()->HasWindowClients()) { |
| 339 base::ThreadTaskRunnerHandle::Get()->PostTask( | 342 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 340 FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_NOT_ALLOWED, | 343 FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_NOT_ALLOWED, |
| 341 BackgroundSyncRegistration())); | 344 BackgroundSyncRegistration())); |
| 342 return; | 345 return; |
| 343 } | 346 } |
| 344 | 347 |
| 345 BackgroundSyncRegistration* existing_registration = | 348 BackgroundSyncRegistration* existing_registration = |
| 346 LookupRegistration(sw_registration_id, RegistrationKey(options)); | 349 LookupRegistration(sw_registration_id, RegistrationKey(options)); |
| 347 if (existing_registration && | 350 if (existing_registration && |
| 348 existing_registration->options()->Equals(options)) { | 351 existing_registration->options()->Equals(options)) { |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { | 1076 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { |
| 1074 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1077 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1075 | 1078 |
| 1076 return base::Bind( | 1079 return base::Bind( |
| 1077 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, | 1080 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, |
| 1078 BackgroundSyncStatus>, | 1081 BackgroundSyncStatus>, |
| 1079 weak_ptr_factory_.GetWeakPtr(), callback); | 1082 weak_ptr_factory_.GetWeakPtr(), callback); |
| 1080 } | 1083 } |
| 1081 | 1084 |
| 1082 } // namespace content | 1085 } // namespace content |
| OLD | NEW |