| 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 d5a48778dacd97878d2fdab1318722b4ec400f32..e886a71593b678bd422a50dadb2fe779d1418983 100644
|
| --- a/content/browser/cache_storage/cache_storage_scheduler.h
|
| +++ b/content/browser/cache_storage/cache_storage_scheduler.h
|
| @@ -7,8 +7,10 @@
|
|
|
| #include <list>
|
|
|
| +#include "base/bind.h"
|
| #include "base/callback.h"
|
| #include "base/macros.h"
|
| +#include "base/memory/weak_ptr.h"
|
| #include "content/common/content_export.h"
|
|
|
| namespace content {
|
| @@ -37,12 +39,34 @@ class CONTENT_EXPORT CacheStorageScheduler {
|
| // Returns true if there are any running or pending operations.
|
| bool ScheduledOperations() const;
|
|
|
| + // 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);
|
| + }
|
| +
|
| private:
|
| void RunOperationIfIdle();
|
|
|
| + template <typename... Args>
|
| + void RunNextContinuation(const base::Callback<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();
|
| +
|
| + callback.Run(std::forward<Args>(args)...);
|
| + if (scheduler)
|
| + CompleteOperationAndRunNext();
|
| + }
|
| +
|
| // The list of operations waiting on initialization.
|
| std::list<base::Closure> pending_operations_;
|
| bool operation_running_;
|
| + base::WeakPtrFactory<CacheStorageScheduler> weak_ptr_factory_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(CacheStorageScheduler);
|
| };
|
|
|