OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_ | 5 #ifndef CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_ |
6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_ | 6 #define CONTENT_BROWSER_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" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 base::TimeDelta delay) = 0; | 42 base::TimeDelta delay) = 0; |
43 | 43 |
44 // Posts a shutdown blocking task to |sequence_id|. | 44 // Posts a shutdown blocking task to |sequence_id|. |
45 virtual bool PostShutdownBlockingTask( | 45 virtual bool PostShutdownBlockingTask( |
46 const tracked_objects::Location& from_here, | 46 const tracked_objects::Location& from_here, |
47 SequenceID sequence_id, | 47 SequenceID sequence_id, |
48 const base::Closure& task) = 0; | 48 const base::Closure& task) = 0; |
49 | 49 |
50 // The TaskRunner override returns true if the current thread is running | 50 // The TaskRunner override returns true if the current thread is running |
51 // on the primary sequence. | 51 // on the primary sequence. |
52 virtual bool RunsTasksOnCurrentThread() const override; | 52 bool RunsTasksOnCurrentThread() const override; |
53 | 53 |
54 // Returns true if the current thread is running on the given |sequence_id|. | 54 // Returns true if the current thread is running on the given |sequence_id|. |
55 virtual bool IsRunningOnSequence(SequenceID sequence_id) const = 0; | 55 virtual bool IsRunningOnSequence(SequenceID sequence_id) const = 0; |
56 bool IsRunningOnPrimarySequence() const { | 56 bool IsRunningOnPrimarySequence() const { |
57 return IsRunningOnSequence(PRIMARY_SEQUENCE); | 57 return IsRunningOnSequence(PRIMARY_SEQUENCE); |
58 } | 58 } |
59 bool IsRunningOnCommitSequence() const { | 59 bool IsRunningOnCommitSequence() const { |
60 return IsRunningOnSequence(COMMIT_SEQUENCE); | 60 return IsRunningOnSequence(COMMIT_SEQUENCE); |
61 } | 61 } |
62 | 62 |
63 protected: | 63 protected: |
64 virtual ~DOMStorageTaskRunner() {} | 64 ~DOMStorageTaskRunner() override {} |
65 }; | 65 }; |
66 | 66 |
67 // A derived class used in chromium that utilizes a SequenceWorkerPool | 67 // A derived class used in chromium that utilizes a SequenceWorkerPool |
68 // under dom_storage specific SequenceTokens. The |delayed_task_loop| | 68 // under dom_storage specific SequenceTokens. The |delayed_task_loop| |
69 // is used to delay scheduling on the worker pool. | 69 // is used to delay scheduling on the worker pool. |
70 class CONTENT_EXPORT DOMStorageWorkerPoolTaskRunner : | 70 class CONTENT_EXPORT DOMStorageWorkerPoolTaskRunner : |
71 public DOMStorageTaskRunner { | 71 public DOMStorageTaskRunner { |
72 public: | 72 public: |
73 DOMStorageWorkerPoolTaskRunner( | 73 DOMStorageWorkerPoolTaskRunner( |
74 base::SequencedWorkerPool* sequenced_worker_pool, | 74 base::SequencedWorkerPool* sequenced_worker_pool, |
75 base::SequencedWorkerPool::SequenceToken primary_sequence_token, | 75 base::SequencedWorkerPool::SequenceToken primary_sequence_token, |
76 base::SequencedWorkerPool::SequenceToken commit_sequence_token, | 76 base::SequencedWorkerPool::SequenceToken commit_sequence_token, |
77 base::MessageLoopProxy* delayed_task_loop); | 77 base::MessageLoopProxy* delayed_task_loop); |
78 | 78 |
79 virtual bool PostDelayedTask( | 79 bool PostDelayedTask(const tracked_objects::Location& from_here, |
80 const tracked_objects::Location& from_here, | 80 const base::Closure& task, |
81 const base::Closure& task, | 81 base::TimeDelta delay) override; |
82 base::TimeDelta delay) override; | |
83 | 82 |
84 virtual bool PostShutdownBlockingTask( | 83 bool PostShutdownBlockingTask(const tracked_objects::Location& from_here, |
85 const tracked_objects::Location& from_here, | 84 SequenceID sequence_id, |
86 SequenceID sequence_id, | 85 const base::Closure& task) override; |
87 const base::Closure& task) override; | |
88 | 86 |
89 virtual bool IsRunningOnSequence(SequenceID sequence_id) const override; | 87 bool IsRunningOnSequence(SequenceID sequence_id) const override; |
90 | 88 |
91 protected: | 89 protected: |
92 virtual ~DOMStorageWorkerPoolTaskRunner(); | 90 ~DOMStorageWorkerPoolTaskRunner() override; |
93 | 91 |
94 private: | 92 private: |
95 | 93 |
96 base::SequencedWorkerPool::SequenceToken IDtoToken(SequenceID id) const; | 94 base::SequencedWorkerPool::SequenceToken IDtoToken(SequenceID id) const; |
97 | 95 |
98 const scoped_refptr<base::MessageLoopProxy> message_loop_; | 96 const scoped_refptr<base::MessageLoopProxy> message_loop_; |
99 const scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_; | 97 const scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_; |
100 base::SequencedWorkerPool::SequenceToken primary_sequence_token_; | 98 base::SequencedWorkerPool::SequenceToken primary_sequence_token_; |
101 base::SequencedWorkerPool::SequenceToken commit_sequence_token_; | 99 base::SequencedWorkerPool::SequenceToken commit_sequence_token_; |
102 }; | 100 }; |
103 | 101 |
104 // A derived class used in unit tests that ignores all delays so | 102 // A derived class used in unit tests that ignores all delays so |
105 // we don't block in unit tests waiting for timeouts to expire. | 103 // we don't block in unit tests waiting for timeouts to expire. |
106 // There is no distinction between [non]-shutdown-blocking or | 104 // There is no distinction between [non]-shutdown-blocking or |
107 // the primary sequence vs the commit sequence in the mock, | 105 // the primary sequence vs the commit sequence in the mock, |
108 // all tasks are scheduled on |message_loop| with zero delay. | 106 // all tasks are scheduled on |message_loop| with zero delay. |
109 class CONTENT_EXPORT MockDOMStorageTaskRunner : | 107 class CONTENT_EXPORT MockDOMStorageTaskRunner : |
110 public DOMStorageTaskRunner { | 108 public DOMStorageTaskRunner { |
111 public: | 109 public: |
112 explicit MockDOMStorageTaskRunner(base::MessageLoopProxy* message_loop); | 110 explicit MockDOMStorageTaskRunner(base::MessageLoopProxy* message_loop); |
113 | 111 |
114 virtual bool PostDelayedTask( | 112 bool PostDelayedTask(const tracked_objects::Location& from_here, |
115 const tracked_objects::Location& from_here, | 113 const base::Closure& task, |
116 const base::Closure& task, | 114 base::TimeDelta delay) override; |
117 base::TimeDelta delay) override; | |
118 | 115 |
119 virtual bool PostShutdownBlockingTask( | 116 bool PostShutdownBlockingTask(const tracked_objects::Location& from_here, |
120 const tracked_objects::Location& from_here, | 117 SequenceID sequence_id, |
121 SequenceID sequence_id, | 118 const base::Closure& task) override; |
122 const base::Closure& task) override; | |
123 | 119 |
124 virtual bool IsRunningOnSequence(SequenceID sequence_id) const override; | 120 bool IsRunningOnSequence(SequenceID sequence_id) const override; |
125 | 121 |
126 protected: | 122 protected: |
127 virtual ~MockDOMStorageTaskRunner(); | 123 ~MockDOMStorageTaskRunner() override; |
128 | 124 |
129 private: | 125 private: |
130 const scoped_refptr<base::MessageLoopProxy> message_loop_; | 126 const scoped_refptr<base::MessageLoopProxy> message_loop_; |
131 }; | 127 }; |
132 | 128 |
133 } // namespace content | 129 } // namespace content |
134 | 130 |
135 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_ | 131 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_TASK_RUNNER_ |
OLD | NEW |