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 #include "base/test/test_mock_time_task_runner.h" | 5 #include "base/test/test_mock_time_task_runner.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
11 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
12 #include "base/time/clock.h" | 14 #include "base/time/clock.h" |
13 #include "base/time/tick_clock.h" | 15 #include "base/time/tick_clock.h" |
14 | 16 |
15 namespace base { | 17 namespace base { |
16 | 18 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 74 |
73 // TestMockTimeTaskRunner::TestOrderedPendingTask ----------------------------- | 75 // TestMockTimeTaskRunner::TestOrderedPendingTask ----------------------------- |
74 | 76 |
75 // Subclass of TestPendingTask which has a strictly monotonically increasing ID | 77 // Subclass of TestPendingTask which has a strictly monotonically increasing ID |
76 // for every task, so that tasks posted with the same 'time to run' can be run | 78 // for every task, so that tasks posted with the same 'time to run' can be run |
77 // in the order of being posted. | 79 // in the order of being posted. |
78 struct TestMockTimeTaskRunner::TestOrderedPendingTask | 80 struct TestMockTimeTaskRunner::TestOrderedPendingTask |
79 : public base::TestPendingTask { | 81 : public base::TestPendingTask { |
80 TestOrderedPendingTask(); | 82 TestOrderedPendingTask(); |
81 TestOrderedPendingTask(const tracked_objects::Location& location, | 83 TestOrderedPendingTask(const tracked_objects::Location& location, |
82 const Closure& task, | 84 Closure task, |
83 TimeTicks post_time, | 85 TimeTicks post_time, |
84 TimeDelta delay, | 86 TimeDelta delay, |
85 size_t ordinal, | 87 size_t ordinal, |
86 TestNestability nestability); | 88 TestNestability nestability); |
87 TestOrderedPendingTask(TestOrderedPendingTask&&); | 89 TestOrderedPendingTask(TestOrderedPendingTask&&); |
88 ~TestOrderedPendingTask(); | 90 ~TestOrderedPendingTask(); |
89 | 91 |
90 TestOrderedPendingTask& operator=(TestOrderedPendingTask&&); | 92 TestOrderedPendingTask& operator=(TestOrderedPendingTask&&); |
91 | 93 |
92 size_t ordinal; | 94 size_t ordinal; |
93 | 95 |
94 private: | 96 private: |
95 DISALLOW_COPY_AND_ASSIGN(TestOrderedPendingTask); | 97 DISALLOW_COPY_AND_ASSIGN(TestOrderedPendingTask); |
96 }; | 98 }; |
97 | 99 |
98 TestMockTimeTaskRunner::TestOrderedPendingTask::TestOrderedPendingTask() | 100 TestMockTimeTaskRunner::TestOrderedPendingTask::TestOrderedPendingTask() |
99 : ordinal(0) { | 101 : ordinal(0) { |
100 } | 102 } |
101 | 103 |
102 TestMockTimeTaskRunner::TestOrderedPendingTask::TestOrderedPendingTask( | 104 TestMockTimeTaskRunner::TestOrderedPendingTask::TestOrderedPendingTask( |
103 TestOrderedPendingTask&&) = default; | 105 TestOrderedPendingTask&&) = default; |
104 | 106 |
105 TestMockTimeTaskRunner::TestOrderedPendingTask::TestOrderedPendingTask( | 107 TestMockTimeTaskRunner::TestOrderedPendingTask::TestOrderedPendingTask( |
106 const tracked_objects::Location& location, | 108 const tracked_objects::Location& location, |
107 const Closure& task, | 109 Closure task, |
108 TimeTicks post_time, | 110 TimeTicks post_time, |
109 TimeDelta delay, | 111 TimeDelta delay, |
110 size_t ordinal, | 112 size_t ordinal, |
111 TestNestability nestability) | 113 TestNestability nestability) |
112 : base::TestPendingTask(location, task, post_time, delay, nestability), | 114 : base::TestPendingTask(location, |
| 115 std::move(task), |
| 116 post_time, |
| 117 delay, |
| 118 nestability), |
113 ordinal(ordinal) {} | 119 ordinal(ordinal) {} |
114 | 120 |
115 TestMockTimeTaskRunner::TestOrderedPendingTask::~TestOrderedPendingTask() { | 121 TestMockTimeTaskRunner::TestOrderedPendingTask::~TestOrderedPendingTask() { |
116 } | 122 } |
117 | 123 |
118 TestMockTimeTaskRunner::TestOrderedPendingTask& | 124 TestMockTimeTaskRunner::TestOrderedPendingTask& |
119 TestMockTimeTaskRunner::TestOrderedPendingTask::operator=( | 125 TestMockTimeTaskRunner::TestOrderedPendingTask::operator=( |
120 TestOrderedPendingTask&&) = default; | 126 TestOrderedPendingTask&&) = default; |
121 | 127 |
122 // TestMockTimeTaskRunner ----------------------------------------------------- | 128 // TestMockTimeTaskRunner ----------------------------------------------------- |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 233 |
228 // TODO(gab): Combine |thread_checker_| with a SequenceToken to differentiate | 234 // TODO(gab): Combine |thread_checker_| with a SequenceToken to differentiate |
229 // between tasks running in the scope of this TestMockTimeTaskRunner and other | 235 // between tasks running in the scope of this TestMockTimeTaskRunner and other |
230 // task runners sharing this thread. http://crbug.com/631186 | 236 // task runners sharing this thread. http://crbug.com/631186 |
231 bool TestMockTimeTaskRunner::RunsTasksOnCurrentThread() const { | 237 bool TestMockTimeTaskRunner::RunsTasksOnCurrentThread() const { |
232 return thread_checker_.CalledOnValidThread(); | 238 return thread_checker_.CalledOnValidThread(); |
233 } | 239 } |
234 | 240 |
235 bool TestMockTimeTaskRunner::PostDelayedTask( | 241 bool TestMockTimeTaskRunner::PostDelayedTask( |
236 const tracked_objects::Location& from_here, | 242 const tracked_objects::Location& from_here, |
237 const Closure& task, | 243 Closure task, |
238 TimeDelta delay) { | 244 TimeDelta delay) { |
239 AutoLock scoped_lock(tasks_lock_); | 245 AutoLock scoped_lock(tasks_lock_); |
240 tasks_.push(TestOrderedPendingTask(from_here, task, now_ticks_, delay, | 246 tasks_.push(TestOrderedPendingTask(from_here, std::move(task), now_ticks_, |
241 next_task_ordinal_++, | 247 delay, next_task_ordinal_++, |
242 TestPendingTask::NESTABLE)); | 248 TestPendingTask::NESTABLE)); |
243 return true; | 249 return true; |
244 } | 250 } |
245 | 251 |
246 bool TestMockTimeTaskRunner::PostNonNestableDelayedTask( | 252 bool TestMockTimeTaskRunner::PostNonNestableDelayedTask( |
247 const tracked_objects::Location& from_here, | 253 const tracked_objects::Location& from_here, |
248 const Closure& task, | 254 Closure task, |
249 TimeDelta delay) { | 255 TimeDelta delay) { |
250 return PostDelayedTask(from_here, task, delay); | 256 return PostDelayedTask(from_here, std::move(task), delay); |
251 } | 257 } |
252 | 258 |
253 bool TestMockTimeTaskRunner::IsElapsingStopped() { | 259 bool TestMockTimeTaskRunner::IsElapsingStopped() { |
254 return false; | 260 return false; |
255 } | 261 } |
256 | 262 |
257 void TestMockTimeTaskRunner::OnBeforeSelectingTask() { | 263 void TestMockTimeTaskRunner::OnBeforeSelectingTask() { |
258 // Empty default implementation. | 264 // Empty default implementation. |
259 } | 265 } |
260 | 266 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 // It's safe to remove const and consume |task| here, since |task| is not | 318 // It's safe to remove const and consume |task| here, since |task| is not |
313 // used for ordering the item. | 319 // used for ordering the item. |
314 *next_task = std::move(const_cast<TestOrderedPendingTask&>(tasks_.top())); | 320 *next_task = std::move(const_cast<TestOrderedPendingTask&>(tasks_.top())); |
315 tasks_.pop(); | 321 tasks_.pop(); |
316 return true; | 322 return true; |
317 } | 323 } |
318 return false; | 324 return false; |
319 } | 325 } |
320 | 326 |
321 } // namespace base | 327 } // namespace base |
OLD | NEW |