Chromium Code Reviews| 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 #ifndef CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_SCHEDULER_H_ | 5 #ifndef CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_SCHEDULER_H_ |
| 6 #define CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_SCHEDULER_H_ | 6 #define CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_SCHEDULER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | |
|
jsbell
2016/07/21 18:13:31
Needed?
jkarlin
2016/07/21 18:29:49
Done.
| |
| 13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/time/time.h" | |
| 16 #include "content/browser/cache_storage/cache_storage_scheduler_client.h" | |
| 14 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
| 15 | 18 |
| 19 namespace base { | |
| 20 class SingleThreadTaskRunner; | |
|
jsbell
2016/07/21 18:13:31
Needed?
jkarlin
2016/07/21 18:29:49
Done.
| |
| 21 } | |
| 22 | |
| 16 namespace content { | 23 namespace content { |
| 17 | 24 |
| 25 class CacheStorageOperation; | |
| 26 | |
| 18 // TODO(jkarlin): Support readers and writers so operations can run in parallel. | 27 // TODO(jkarlin): Support readers and writers so operations can run in parallel. |
| 19 // TODO(jkarlin): Support operation identification so that ops can be checked in | 28 // TODO(jkarlin): Support operation identification so that ops can be checked in |
| 20 // DCHECKs. | 29 // DCHECKs. |
| 21 | 30 |
| 22 // CacheStorageScheduler runs the scheduled callbacks sequentially. Add an | 31 // CacheStorageScheduler runs the scheduled callbacks sequentially. Add an |
| 23 // operation by calling ScheduleOperation() with your callback. Once your | 32 // operation by calling ScheduleOperation() with your callback. Once your |
| 24 // operation is done be sure to call CompleteOperationAndRunNext() to schedule | 33 // operation is done be sure to call CompleteOperationAndRunNext() to schedule |
| 25 // the next operation. | 34 // the next operation. |
| 26 class CONTENT_EXPORT CacheStorageScheduler { | 35 class CONTENT_EXPORT CacheStorageScheduler { |
| 27 public: | 36 public: |
| 28 CacheStorageScheduler(); | 37 explicit CacheStorageScheduler(CacheStorageSchedulerClient client_type); |
| 29 virtual ~CacheStorageScheduler(); | 38 virtual ~CacheStorageScheduler(); |
| 30 | 39 |
| 31 // Adds the operation to the tail of the queue and starts it if the scheduler | 40 // Adds the operation to the tail of the queue and starts it if the scheduler |
| 32 // is idle. | 41 // is idle. |
| 33 void ScheduleOperation(const base::Closure& closure); | 42 void ScheduleOperation(const base::Closure& closure); |
| 34 | 43 |
| 35 // Call this after each operation completes. It cleans up the current | 44 // Call this after each operation completes. It cleans up the current |
| 36 // operation and starts the next. | 45 // operation and starts the next. |
| 37 void CompleteOperationAndRunNext(); | 46 void CompleteOperationAndRunNext(); |
| 38 | 47 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 56 // Grab a weak ptr to guard against the scheduler being deleted during the | 65 // Grab a weak ptr to guard against the scheduler being deleted during the |
| 57 // callback. | 66 // callback. |
| 58 base::WeakPtr<CacheStorageScheduler> scheduler = | 67 base::WeakPtr<CacheStorageScheduler> scheduler = |
| 59 weak_ptr_factory_.GetWeakPtr(); | 68 weak_ptr_factory_.GetWeakPtr(); |
| 60 | 69 |
| 61 callback.Run(std::forward<Args>(args)...); | 70 callback.Run(std::forward<Args>(args)...); |
| 62 if (scheduler) | 71 if (scheduler) |
| 63 CompleteOperationAndRunNext(); | 72 CompleteOperationAndRunNext(); |
| 64 } | 73 } |
| 65 | 74 |
| 66 // The list of operations waiting on initialization. | 75 std::list<std::unique_ptr<CacheStorageOperation>> pending_operations_; |
| 67 std::list<base::Closure> pending_operations_; | 76 std::unique_ptr<CacheStorageOperation> running_operation_; |
| 68 bool operation_running_; | 77 CacheStorageSchedulerClient client_type_; |
| 78 | |
| 69 base::WeakPtrFactory<CacheStorageScheduler> weak_ptr_factory_; | 79 base::WeakPtrFactory<CacheStorageScheduler> weak_ptr_factory_; |
| 70 | 80 |
| 71 DISALLOW_COPY_AND_ASSIGN(CacheStorageScheduler); | 81 DISALLOW_COPY_AND_ASSIGN(CacheStorageScheduler); |
| 72 }; | 82 }; |
| 73 | 83 |
| 74 } // namespace content | 84 } // namespace content |
| 75 | 85 |
| 76 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_SCHEDULER_H_ | 86 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_SCHEDULER_H_ |
| OLD | NEW |