OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 WEBKIT_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_ | 5 #ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_ |
6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_ | 6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
11 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 class MessageLoopProxy; | 15 class MessageLoopProxy; |
16 } | 16 } |
17 | 17 |
18 namespace dom_storage { | 18 namespace dom_storage { |
19 | 19 |
20 // Tasks must run serially with respect to one another, but may | 20 // Tasks must run serially with respect to one another, but may |
21 // execute on different OS threads. The base class is implemented | 21 // execute on different OS threads. |
22 // in terms of a MessageLoopProxy. | |
23 class DomStorageTaskRunner : public base::SequencedTaskRunner { | 22 class DomStorageTaskRunner : public base::SequencedTaskRunner { |
24 public: | 23 public: |
25 explicit DomStorageTaskRunner(base::MessageLoopProxy* message_loop); | |
26 virtual ~DomStorageTaskRunner(); | 24 virtual ~DomStorageTaskRunner(); |
27 | 25 |
28 // The PostTask() method, defined by TaskRunner, schedules a task | 26 // The PostTask() method, defined by TaskRunner, schedules a task |
29 // to run immediately. | 27 // to run immediately. |
30 | 28 |
31 // Schedules a task to be run after a delay. | 29 // Schedules a task to be run after a delay. |
32 virtual bool PostDelayedTask( | 30 virtual bool PostDelayedTask( |
33 const tracked_objects::Location& from_here, | 31 const tracked_objects::Location& from_here, |
34 const base::Closure& task, | 32 const base::Closure& task, |
35 base::TimeDelta delay) OVERRIDE; | 33 base::TimeDelta delay) OVERRIDE; |
(...skipping 13 matching lines...) Expand all Loading... |
49 // terms of PostDelayedTask and the latter is similarly deprecated. | 47 // terms of PostDelayedTask and the latter is similarly deprecated. |
50 virtual bool PostNonNestableDelayedTask( | 48 virtual bool PostNonNestableDelayedTask( |
51 const tracked_objects::Location& from_here, | 49 const tracked_objects::Location& from_here, |
52 const base::Closure& task, | 50 const base::Closure& task, |
53 base::TimeDelta delay) OVERRIDE; | 51 base::TimeDelta delay) OVERRIDE; |
54 virtual bool PostNonNestableDelayedTask( | 52 virtual bool PostNonNestableDelayedTask( |
55 const tracked_objects::Location& from_here, | 53 const tracked_objects::Location& from_here, |
56 const base::Closure& task, | 54 const base::Closure& task, |
57 int64 delay_ms) OVERRIDE; | 55 int64 delay_ms) OVERRIDE; |
58 | 56 |
| 57 virtual bool PostShutdownBlockingTask( |
| 58 const tracked_objects::Location& from_here, |
| 59 const base::Closure& task) = 0; |
| 60 |
| 61 virtual bool PostShutdownBlockingCommitTask( |
| 62 const tracked_objects::Location& from_here, |
| 63 const base::Closure& task) = 0; |
| 64 |
59 protected: | 65 protected: |
| 66 explicit DomStorageTaskRunner(base::MessageLoopProxy* message_loop); |
| 67 |
60 const scoped_refptr<base::MessageLoopProxy> message_loop_; | 68 const scoped_refptr<base::MessageLoopProxy> message_loop_; |
61 }; | 69 }; |
62 | 70 |
63 // A derived class that utlizes the SequenceWorkerPool under a | 71 // A derived class that utlizes the SequenceWorkerPool under a |
64 // dom_storage specific SequenceToken. The MessageLoopProxy | 72 // dom_storage specific SequenceTokens. The MessageLoopProxy |
65 // is used to delay scheduling on the worker pool. | 73 // is used to delay scheduling on the worker pool. |
66 class DomStorageWorkerPoolTaskRunner : public DomStorageTaskRunner { | 74 class DomStorageWorkerPoolTaskRunner : public DomStorageTaskRunner { |
67 public: | 75 public: |
68 DomStorageWorkerPoolTaskRunner( | 76 DomStorageWorkerPoolTaskRunner( |
69 base::SequencedWorkerPool* sequenced_worker_pool, | 77 base::SequencedWorkerPool* sequenced_worker_pool, |
70 base::SequencedWorkerPool::SequenceToken sequence_token, | 78 base::SequencedWorkerPool::SequenceToken sequence_token, |
71 base::MessageLoopProxy* delayed_task_loop); | 79 base::MessageLoopProxy* delayed_task_loop); |
72 virtual ~DomStorageWorkerPoolTaskRunner(); | 80 virtual ~DomStorageWorkerPoolTaskRunner(); |
73 | 81 |
74 // Schedules a sequenced worker task to be run after a delay. | 82 // Schedules a sequenced worker task to be run after a delay. |
75 virtual bool PostDelayedTask( | 83 virtual bool PostDelayedTask( |
76 const tracked_objects::Location& from_here, | 84 const tracked_objects::Location& from_here, |
77 const base::Closure& task, | 85 const base::Closure& task, |
78 base::TimeDelta delay) OVERRIDE; | 86 base::TimeDelta delay) OVERRIDE; |
79 | 87 |
80 base::SequencedWorkerPool::SequenceToken sequence_token() const; | 88 base::SequencedWorkerPool::SequenceToken sequence_token() const; |
81 | 89 |
| 90 virtual bool PostShutdownBlockingTask( |
| 91 const tracked_objects::Location& from_here, |
| 92 const base::Closure& task) OVERRIDE; |
| 93 |
| 94 virtual bool PostShutdownBlockingCommitTask( |
| 95 const tracked_objects::Location& from_here, |
| 96 const base::Closure& task) OVERRIDE; |
| 97 |
82 private: | 98 private: |
83 const scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_; | 99 const scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_; |
84 base::SequencedWorkerPool::SequenceToken sequence_token_; | 100 base::SequencedWorkerPool::SequenceToken sequence_token_; |
| 101 base::SequencedWorkerPool::SequenceToken commit_sequence_token_; |
85 }; | 102 }; |
86 | 103 |
87 // A derived class used in unit tests that causes us to ignore the | 104 // A derived class used in unit tests that causes us to ignore the |
88 // delay in PostDelayedTask so we don't need to block in unit tests | 105 // delay in PostDelayedTask so we don't need to block in unit tests |
89 // for the timeout to expire. | 106 // for the timeout to expire. |
90 class MockDomStorageTaskRunner : public DomStorageTaskRunner { | 107 class MockDomStorageTaskRunner : public DomStorageTaskRunner { |
91 public: | 108 public: |
92 explicit MockDomStorageTaskRunner(base::MessageLoopProxy* message_loop); | 109 explicit MockDomStorageTaskRunner(base::MessageLoopProxy* message_loop); |
93 virtual ~MockDomStorageTaskRunner() {} | 110 virtual ~MockDomStorageTaskRunner() {} |
94 | 111 |
95 virtual bool PostDelayedTask( | 112 virtual bool PostDelayedTask( |
96 const tracked_objects::Location& from_here, | 113 const tracked_objects::Location& from_here, |
97 const base::Closure& task, | 114 const base::Closure& task, |
98 base::TimeDelta delay) OVERRIDE; | 115 base::TimeDelta delay) OVERRIDE; |
| 116 |
| 117 virtual bool PostShutdownBlockingTask( |
| 118 const tracked_objects::Location& from_here, |
| 119 const base::Closure& task) OVERRIDE; |
| 120 |
| 121 virtual bool PostShutdownBlockingCommitTask( |
| 122 const tracked_objects::Location& from_here, |
| 123 const base::Closure& task) OVERRIDE; |
99 }; | 124 }; |
100 | 125 |
101 } // namespace dom_storage | 126 } // namespace dom_storage |
102 | 127 |
103 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_ | 128 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_ |
OLD | NEW |