Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Unified Diff: content/browser/background_sync/background_sync_manager.cc

Issue 2167483002: [CacheStorage] Simpler way to wrap callbacks to run pending operation completions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment clarification Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/background_sync/background_sync_manager.cc
diff --git a/content/browser/background_sync/background_sync_manager.cc b/content/browser/background_sync/background_sync_manager.cc
index fadb79c8f8a9e64aa50a7ee07ba3eac04aeb4f76..859c530bc98fb224bea00c1b29437d16fc6b9fe5 100644
--- a/content/browser/background_sync/background_sync_manager.cc
+++ b/content/browser/background_sync/background_sync_manager.cc
@@ -203,7 +203,7 @@ void BackgroundSyncManager::Register(
op_scheduler_.ScheduleOperation(
base::Bind(&BackgroundSyncManager::RegisterCheckIfHasMainFrame,
weak_ptr_factory_.GetWeakPtr(), sw_registration_id, options,
- MakeStatusAndRegistrationCompletion(callback)));
+ op_scheduler_.WrapCallbackToRunNext(callback)));
}
void BackgroundSyncManager::GetRegistrations(
@@ -225,7 +225,7 @@ void BackgroundSyncManager::GetRegistrations(
op_scheduler_.ScheduleOperation(
base::Bind(&BackgroundSyncManager::GetRegistrationsImpl,
weak_ptr_factory_.GetWeakPtr(), sw_registration_id,
- MakeStatusAndRegistrationsCompletion(callback)));
+ op_scheduler_.WrapCallbackToRunNext(callback)));
}
void BackgroundSyncManager::OnRegistrationDeleted(int64_t sw_registration_id,
@@ -1037,9 +1037,10 @@ void BackgroundSyncManager::EventComplete(
return;
}
- op_scheduler_.ScheduleOperation(base::Bind(
- &BackgroundSyncManager::EventCompleteImpl, weak_ptr_factory_.GetWeakPtr(),
- service_worker_id, tag, status_code, MakeClosureCompletion(callback)));
+ op_scheduler_.ScheduleOperation(
+ base::Bind(&BackgroundSyncManager::EventCompleteImpl,
+ weak_ptr_factory_.GetWeakPtr(), service_worker_id, tag,
+ status_code, op_scheduler_.WrapCallbackToRunNext(callback)));
}
void BackgroundSyncManager::EventCompleteImpl(
@@ -1188,79 +1189,9 @@ void BackgroundSyncManager::SetMaxSyncAttemptsImpl(
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
}
-// TODO(jkarlin): Figure out how to pass scoped_ptrs with this.
-template <typename CallbackT, typename... Params>
-void BackgroundSyncManager::CompleteOperationCallback(const CallbackT& callback,
- Params... parameters) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
-
- callback.Run(parameters...);
- op_scheduler_.CompleteOperationAndRunNext();
-}
-
-void BackgroundSyncManager::CompleteStatusAndRegistrationCallback(
- StatusAndRegistrationCallback callback,
- BackgroundSyncStatus status,
- std::unique_ptr<BackgroundSyncRegistration> registration) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
-
- callback.Run(status, std::move(registration));
- op_scheduler_.CompleteOperationAndRunNext();
-}
-
-void BackgroundSyncManager::CompleteStatusAndRegistrationsCallback(
- StatusAndRegistrationsCallback callback,
- BackgroundSyncStatus status,
- std::unique_ptr<ScopedVector<BackgroundSyncRegistration>> registrations) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
-
- callback.Run(status, std::move(registrations));
- op_scheduler_.CompleteOperationAndRunNext();
-}
-
base::Closure BackgroundSyncManager::MakeEmptyCompletion() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
-
- return MakeClosureCompletion(base::Bind(base::DoNothing));
-}
-
-base::Closure BackgroundSyncManager::MakeClosureCompletion(
- const base::Closure& callback) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
-
- return base::Bind(
- &BackgroundSyncManager::CompleteOperationCallback<base::Closure>,
- weak_ptr_factory_.GetWeakPtr(), callback);
-}
-
-BackgroundSyncManager::StatusAndRegistrationCallback
-BackgroundSyncManager::MakeStatusAndRegistrationCompletion(
- const StatusAndRegistrationCallback& callback) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
-
- return base::Bind(
- &BackgroundSyncManager::CompleteStatusAndRegistrationCallback,
- weak_ptr_factory_.GetWeakPtr(), callback);
-}
-
-BackgroundSyncManager::StatusAndRegistrationsCallback
-BackgroundSyncManager::MakeStatusAndRegistrationsCompletion(
- const StatusAndRegistrationsCallback& callback) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
-
- return base::Bind(
- &BackgroundSyncManager::CompleteStatusAndRegistrationsCallback,
- weak_ptr_factory_.GetWeakPtr(), callback);
-}
-
-BackgroundSyncManager::StatusCallback
-BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
-
- return base::Bind(
- &BackgroundSyncManager::CompleteOperationCallback<StatusCallback,
- BackgroundSyncStatus>,
- weak_ptr_factory_.GetWeakPtr(), callback);
+ return op_scheduler_.WrapCallbackToRunNext(base::Bind(&base::DoNothing));
}
} // namespace content
« no previous file with comments | « content/browser/background_sync/background_sync_manager.h ('k') | content/browser/cache_storage/cache_storage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698