| 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> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/barrier_closure.h" | 9 #include "base/barrier_closure.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 void BackgroundSyncManager::GetRegistrations( | 209 void BackgroundSyncManager::GetRegistrations( |
| 210 int64_t sw_registration_id, | 210 int64_t sw_registration_id, |
| 211 const StatusAndRegistrationsCallback& callback) { | 211 const StatusAndRegistrationsCallback& callback) { |
| 212 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 212 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 213 | 213 |
| 214 if (disabled_) { | 214 if (disabled_) { |
| 215 base::ThreadTaskRunnerHandle::Get()->PostTask( | 215 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 216 FROM_HERE, | 216 FROM_HERE, |
| 217 base::Bind( | 217 base::Bind( |
| 218 callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR, | 218 callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR, |
| 219 base::Passed( | 219 base::Passed(base::MakeUnique<std::vector< |
| 220 std::unique_ptr<ScopedVector<BackgroundSyncRegistration>>( | 220 std::unique_ptr<BackgroundSyncRegistration>>>()))); |
| 221 new ScopedVector<BackgroundSyncRegistration>())))); | |
| 222 return; | 221 return; |
| 223 } | 222 } |
| 224 | 223 |
| 225 op_scheduler_.ScheduleOperation( | 224 op_scheduler_.ScheduleOperation( |
| 226 base::Bind(&BackgroundSyncManager::GetRegistrationsImpl, | 225 base::Bind(&BackgroundSyncManager::GetRegistrationsImpl, |
| 227 weak_ptr_factory_.GetWeakPtr(), sw_registration_id, | 226 weak_ptr_factory_.GetWeakPtr(), sw_registration_id, |
| 228 op_scheduler_.WrapCallbackToRunNext(callback))); | 227 op_scheduler_.WrapCallbackToRunNext(callback))); |
| 229 } | 228 } |
| 230 | 229 |
| 231 void BackgroundSyncManager::OnRegistrationDeleted(int64_t sw_registration_id, | 230 void BackgroundSyncManager::OnRegistrationDeleted(int64_t sw_registration_id, |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 const GURL& origin, | 781 const GURL& origin, |
| 783 const BoolCallback& callback) { | 782 const BoolCallback& callback) { |
| 784 service_worker_context_->HasMainFrameProviderHost(origin, callback); | 783 service_worker_context_->HasMainFrameProviderHost(origin, callback); |
| 785 } | 784 } |
| 786 | 785 |
| 787 void BackgroundSyncManager::GetRegistrationsImpl( | 786 void BackgroundSyncManager::GetRegistrationsImpl( |
| 788 int64_t sw_registration_id, | 787 int64_t sw_registration_id, |
| 789 const StatusAndRegistrationsCallback& callback) { | 788 const StatusAndRegistrationsCallback& callback) { |
| 790 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 789 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 791 | 790 |
| 792 std::unique_ptr<ScopedVector<BackgroundSyncRegistration>> out_registrations( | 791 auto out_registrations = base::MakeUnique< |
| 793 new ScopedVector<BackgroundSyncRegistration>()); | 792 std::vector<std::unique_ptr<BackgroundSyncRegistration>>>(); |
| 794 | 793 |
| 795 if (disabled_) { | 794 if (disabled_) { |
| 796 base::ThreadTaskRunnerHandle::Get()->PostTask( | 795 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 797 FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR, | 796 FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR, |
| 798 base::Passed(std::move(out_registrations)))); | 797 base::Passed(&out_registrations))); |
| 799 return; | 798 return; |
| 800 } | 799 } |
| 801 | 800 |
| 802 SWIdToRegistrationsMap::iterator it = | 801 SWIdToRegistrationsMap::iterator it = |
| 803 active_registrations_.find(sw_registration_id); | 802 active_registrations_.find(sw_registration_id); |
| 804 | 803 |
| 805 if (it != active_registrations_.end()) { | 804 if (it != active_registrations_.end()) { |
| 806 const BackgroundSyncRegistrations& registrations = it->second; | 805 const BackgroundSyncRegistrations& registrations = it->second; |
| 807 for (const auto& tag_and_registration : registrations.registration_map) { | 806 for (const auto& tag_and_registration : registrations.registration_map) { |
| 808 const BackgroundSyncRegistration& registration = | 807 const BackgroundSyncRegistration& registration = |
| 809 tag_and_registration.second; | 808 tag_and_registration.second; |
| 810 BackgroundSyncRegistration* out_registration = | 809 out_registrations->push_back( |
| 811 new BackgroundSyncRegistration(registration); | 810 base::MakeUnique<BackgroundSyncRegistration>(registration)); |
| 812 out_registrations->push_back(out_registration); | |
| 813 } | 811 } |
| 814 } | 812 } |
| 815 | 813 |
| 816 base::ThreadTaskRunnerHandle::Get()->PostTask( | 814 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 817 FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_OK, | 815 FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_OK, |
| 818 base::Passed(std::move(out_registrations)))); | 816 base::Passed(&out_registrations))); |
| 819 } | 817 } |
| 820 | 818 |
| 821 bool BackgroundSyncManager::AreOptionConditionsMet( | 819 bool BackgroundSyncManager::AreOptionConditionsMet( |
| 822 const BackgroundSyncRegistrationOptions& options) { | 820 const BackgroundSyncRegistrationOptions& options) { |
| 823 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 821 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 824 return network_observer_->NetworkSufficient(options.network_state); | 822 return network_observer_->NetworkSufficient(options.network_state); |
| 825 } | 823 } |
| 826 | 824 |
| 827 bool BackgroundSyncManager::IsRegistrationReadyToFire( | 825 bool BackgroundSyncManager::IsRegistrationReadyToFire( |
| 828 const BackgroundSyncRegistration& registration) { | 826 const BackgroundSyncRegistration& registration) { |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1170 parameters_->max_sync_attempts = max_attempts; | 1168 parameters_->max_sync_attempts = max_attempts; |
| 1171 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); | 1169 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); |
| 1172 } | 1170 } |
| 1173 | 1171 |
| 1174 base::Closure BackgroundSyncManager::MakeEmptyCompletion() { | 1172 base::Closure BackgroundSyncManager::MakeEmptyCompletion() { |
| 1175 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1173 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1176 return op_scheduler_.WrapCallbackToRunNext(base::Bind(&base::DoNothing)); | 1174 return op_scheduler_.WrapCallbackToRunNext(base::Bind(&base::DoNothing)); |
| 1177 } | 1175 } |
| 1178 | 1176 |
| 1179 } // namespace content | 1177 } // namespace content |
| OLD | NEW |