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

Unified Diff: content/browser/cache_storage/cache_storage_scheduler.h

Issue 2947753002: CacheStorage: Migrate to BindOnce/OnceCallback/OnceClosure (Closed)
Patch Set: Untangle Batch logic (relies on AdaptCallbackForRepeating) Created 3 years, 6 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/cache_storage/cache_storage_scheduler.h
diff --git a/content/browser/cache_storage/cache_storage_scheduler.h b/content/browser/cache_storage/cache_storage_scheduler.h
index bcfe2ea8f5b158d87e47d793ff1f1f67280c167d..fdf668134c888f41a8449ef8b8f1654d4897faa2 100644
--- a/content/browser/cache_storage/cache_storage_scheduler.h
+++ b/content/browser/cache_storage/cache_storage_scheduler.h
@@ -34,7 +34,7 @@ class CONTENT_EXPORT CacheStorageScheduler {
// Adds the operation to the tail of the queue and starts it if the scheduler
// is idle.
- void ScheduleOperation(const base::Closure& closure);
+ void ScheduleOperation(base::OnceClosure closure);
// Call this after each operation completes. It cleans up the current
// operation and starts the next.
@@ -45,18 +45,39 @@ class CONTENT_EXPORT CacheStorageScheduler {
// Wraps |callback| to also call CompleteOperationAndRunNext.
template <typename... Args>
- base::Callback<void(Args...)> WrapCallbackToRunNext(
- const base::Callback<void(Args...)>& callback) {
- return base::Bind(&CacheStorageScheduler::RunNextContinuation<Args...>,
- weak_ptr_factory_.GetWeakPtr(), callback);
+ base::OnceCallback<void(Args...)> WrapCallbackToRunNext(
+ base::OnceCallback<void(Args...)> callback) {
+ return base::BindOnce(
+ &CacheStorageScheduler::RunNextOnceContinuation<Args...>,
+ weak_ptr_factory_.GetWeakPtr(), std::move(callback));
+ }
+ template <typename... Args>
+ base::RepeatingCallback<void(Args...)> WrapCallbackToRunNext(
+ const base::RepeatingCallback<void(Args...)>& callback) {
+ return base::BindRepeating(
+ &CacheStorageScheduler::RunNextRepeatingContinuation<Args...>,
+ weak_ptr_factory_.GetWeakPtr(), callback);
}
private:
void RunOperationIfIdle();
template <typename... Args>
- void RunNextContinuation(const base::Callback<void(Args...)>& callback,
- Args... args) {
+ void RunNextOnceContinuation(base::OnceCallback<void(Args...)> callback,
+ Args... args) {
+ // Grab a weak ptr to guard against the scheduler being deleted during the
+ // callback.
+ base::WeakPtr<CacheStorageScheduler> scheduler =
+ weak_ptr_factory_.GetWeakPtr();
+
+ std::move(callback).Run(std::forward<Args>(args)...);
+ if (scheduler)
+ CompleteOperationAndRunNext();
+ }
+ template <typename... Args>
+ void RunNextRepeatingContinuation(
+ const base::RepeatingCallback<void(Args...)>& callback,
+ Args... args) {
// Grab a weak ptr to guard against the scheduler being deleted during the
// callback.
base::WeakPtr<CacheStorageScheduler> scheduler =

Powered by Google App Engine
This is Rietveld 408576698