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/callback.h" | 10 #include "base/callback.h" |
11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
12 | 12 |
13 namespace content { | 13 namespace content { |
14 | 14 |
| 15 // TODO(jkarlin): Support readers and writers so operations can run in parallel. |
| 16 // TODO(jkarlin): Support operation identification so that ops can be checked in |
| 17 // DCHECKs. |
| 18 |
| 19 // CacheStorageScheduler runs the scheduled callbacks sequentially. Add an |
| 20 // operation by calling ScheduleOperation() with your callback. Once your |
| 21 // operation is done be sure to call CompleteOperationAndRunNext() to schedule |
| 22 // the next operation. |
15 class CONTENT_EXPORT CacheStorageScheduler { | 23 class CONTENT_EXPORT CacheStorageScheduler { |
16 public: | 24 public: |
17 CacheStorageScheduler(); | 25 CacheStorageScheduler(); |
18 virtual ~CacheStorageScheduler(); | 26 virtual ~CacheStorageScheduler(); |
19 | 27 |
20 // Adds the operation to the tail of the queue and starts it if the scheduler | 28 // Adds the operation to the tail of the queue and starts it if the scheduler |
21 // is idle. | 29 // is idle. |
22 void ScheduleOperation(const base::Closure& closure); | 30 void ScheduleOperation(const base::Closure& closure); |
23 | 31 |
24 // Call this after each operation completes. It cleans up the current | 32 // Call this after each operation completes. It cleans up the current |
25 // operation and starts the next. | 33 // operation and starts the next. |
26 void CompleteOperationAndRunNext(); | 34 void CompleteOperationAndRunNext(); |
27 | 35 |
28 // Returns true if there are any running or pending operations. | 36 // Returns true if there are any running or pending operations. |
29 bool ScheduledOperations() const; | 37 bool ScheduledOperations() const; |
30 | 38 |
31 private: | 39 private: |
32 void RunOperationIfIdle(); | 40 void RunOperationIfIdle(); |
33 | 41 |
34 // The list of operations waiting on initialization. | 42 // The list of operations waiting on initialization. |
35 std::list<base::Closure> pending_operations_; | 43 std::list<base::Closure> pending_operations_; |
36 bool operation_running_; | 44 bool operation_running_; |
37 | 45 |
38 DISALLOW_COPY_AND_ASSIGN(CacheStorageScheduler); | 46 DISALLOW_COPY_AND_ASSIGN(CacheStorageScheduler); |
39 }; | 47 }; |
40 | 48 |
41 } // namespace content | 49 } // namespace content |
42 | 50 |
43 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_SCHEDULER_H_ | 51 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_SCHEDULER_H_ |
OLD | NEW |