Chromium Code Reviews| 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( |
|
jsbell
2017/06/19 23:45:00
The overload is necessary to support background_sy
|
| + 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 = |