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