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 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "webkit/dom_storage/dom_storage_export.h" |
12 | 13 |
13 namespace base { | 14 namespace base { |
14 class MessageLoopProxy; | 15 class MessageLoopProxy; |
15 } | 16 } |
16 | 17 |
17 namespace dom_storage { | 18 namespace dom_storage { |
18 | 19 |
19 // DomStorage uses two task sequences (primary vs commit) to avoid | 20 // DomStorage uses two task sequences (primary vs commit) to avoid |
20 // primary access from queuing up behind commits to disk. | 21 // primary access from queuing up behind commits to disk. |
21 // * Initialization, shutdown, and administrative tasks are performed as | 22 // * Initialization, shutdown, and administrative tasks are performed as |
22 // shutdown-blocking primary sequence tasks. | 23 // shutdown-blocking primary sequence tasks. |
23 // * Tasks directly related to the javascript'able interface are performed | 24 // * Tasks directly related to the javascript'able interface are performed |
24 // as shutdown-blocking primary sequence tasks. | 25 // as shutdown-blocking primary sequence tasks. |
25 // TODO(michaeln): Skip tasks for reading during shutdown. | 26 // TODO(michaeln): Skip tasks for reading during shutdown. |
26 // * Internal tasks related to committing changes to disk are performed as | 27 // * Internal tasks related to committing changes to disk are performed as |
27 // shutdown-blocking commit sequence tasks. | 28 // shutdown-blocking commit sequence tasks. |
28 class DomStorageTaskRunner : public base::TaskRunner { | 29 class DOM_STORAGE_EXPORT DomStorageTaskRunner : public base::TaskRunner { |
29 public: | 30 public: |
30 enum SequenceID { | 31 enum SequenceID { |
31 PRIMARY_SEQUENCE, | 32 PRIMARY_SEQUENCE, |
32 COMMIT_SEQUENCE | 33 COMMIT_SEQUENCE |
33 }; | 34 }; |
34 | 35 |
35 // The PostTask() and PostDelayedTask() methods defined by TaskRunner | 36 // The PostTask() and PostDelayedTask() methods defined by TaskRunner |
36 // post shutdown-blocking tasks on the primary sequence. | 37 // post shutdown-blocking tasks on the primary sequence. |
37 virtual bool PostDelayedTask( | 38 virtual bool PostDelayedTask( |
38 const tracked_objects::Location& from_here, | 39 const tracked_objects::Location& from_here, |
(...skipping 19 matching lines...) Expand all Loading... |
58 return IsRunningOnSequence(COMMIT_SEQUENCE); | 59 return IsRunningOnSequence(COMMIT_SEQUENCE); |
59 } | 60 } |
60 | 61 |
61 protected: | 62 protected: |
62 virtual ~DomStorageTaskRunner() {} | 63 virtual ~DomStorageTaskRunner() {} |
63 }; | 64 }; |
64 | 65 |
65 // A derived class used in chromium that utilizes a SequenceWorkerPool | 66 // A derived class used in chromium that utilizes a SequenceWorkerPool |
66 // under dom_storage specific SequenceTokens. The |delayed_task_loop| | 67 // under dom_storage specific SequenceTokens. The |delayed_task_loop| |
67 // is used to delay scheduling on the worker pool. | 68 // is used to delay scheduling on the worker pool. |
68 class DomStorageWorkerPoolTaskRunner : public DomStorageTaskRunner { | 69 class DOM_STORAGE_EXPORT DomStorageWorkerPoolTaskRunner : |
| 70 public DomStorageTaskRunner { |
69 public: | 71 public: |
70 DomStorageWorkerPoolTaskRunner( | 72 DomStorageWorkerPoolTaskRunner( |
71 base::SequencedWorkerPool* sequenced_worker_pool, | 73 base::SequencedWorkerPool* sequenced_worker_pool, |
72 base::SequencedWorkerPool::SequenceToken primary_sequence_token, | 74 base::SequencedWorkerPool::SequenceToken primary_sequence_token, |
73 base::SequencedWorkerPool::SequenceToken commit_sequence_token, | 75 base::SequencedWorkerPool::SequenceToken commit_sequence_token, |
74 base::MessageLoopProxy* delayed_task_loop); | 76 base::MessageLoopProxy* delayed_task_loop); |
75 | 77 |
76 virtual bool PostDelayedTask( | 78 virtual bool PostDelayedTask( |
77 const tracked_objects::Location& from_here, | 79 const tracked_objects::Location& from_here, |
78 const base::Closure& task, | 80 const base::Closure& task, |
(...skipping 17 matching lines...) Expand all Loading... |
96 const scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_; | 98 const scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_; |
97 base::SequencedWorkerPool::SequenceToken primary_sequence_token_; | 99 base::SequencedWorkerPool::SequenceToken primary_sequence_token_; |
98 base::SequencedWorkerPool::SequenceToken commit_sequence_token_; | 100 base::SequencedWorkerPool::SequenceToken commit_sequence_token_; |
99 }; | 101 }; |
100 | 102 |
101 // A derived class used in unit tests that ignores all delays so | 103 // A derived class used in unit tests that ignores all delays so |
102 // we don't block in unit tests waiting for timeouts to expire. | 104 // we don't block in unit tests waiting for timeouts to expire. |
103 // There is no distinction between [non]-shutdown-blocking or | 105 // There is no distinction between [non]-shutdown-blocking or |
104 // the primary sequence vs the commit sequence in the mock, | 106 // the primary sequence vs the commit sequence in the mock, |
105 // all tasks are scheduled on |message_loop| with zero delay. | 107 // all tasks are scheduled on |message_loop| with zero delay. |
106 class MockDomStorageTaskRunner : public DomStorageTaskRunner { | 108 class DOM_STORAGE_EXPORT MockDomStorageTaskRunner : |
| 109 public DomStorageTaskRunner { |
107 public: | 110 public: |
108 explicit MockDomStorageTaskRunner(base::MessageLoopProxy* message_loop); | 111 explicit MockDomStorageTaskRunner(base::MessageLoopProxy* message_loop); |
109 | 112 |
110 virtual bool PostDelayedTask( | 113 virtual bool PostDelayedTask( |
111 const tracked_objects::Location& from_here, | 114 const tracked_objects::Location& from_here, |
112 const base::Closure& task, | 115 const base::Closure& task, |
113 base::TimeDelta delay) OVERRIDE; | 116 base::TimeDelta delay) OVERRIDE; |
114 | 117 |
115 virtual bool PostShutdownBlockingTask( | 118 virtual bool PostShutdownBlockingTask( |
116 const tracked_objects::Location& from_here, | 119 const tracked_objects::Location& from_here, |
117 SequenceID sequence_id, | 120 SequenceID sequence_id, |
118 const base::Closure& task) OVERRIDE; | 121 const base::Closure& task) OVERRIDE; |
119 | 122 |
120 virtual bool IsRunningOnSequence(SequenceID sequence_id) const OVERRIDE; | 123 virtual bool IsRunningOnSequence(SequenceID sequence_id) const OVERRIDE; |
121 | 124 |
122 protected: | 125 protected: |
123 virtual ~MockDomStorageTaskRunner(); | 126 virtual ~MockDomStorageTaskRunner(); |
124 | 127 |
125 private: | 128 private: |
126 const scoped_refptr<base::MessageLoopProxy> message_loop_; | 129 const scoped_refptr<base::MessageLoopProxy> message_loop_; |
127 }; | 130 }; |
128 | 131 |
129 } // namespace dom_storage | 132 } // namespace dom_storage |
130 | 133 |
131 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_ | 134 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_ |
OLD | NEW |