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 #include "base/test/test_simple_task_runner.h" | 5 #include "base/test/test_simple_task_runner.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace base { | 9 namespace base { |
10 | 10 |
11 TestSimpleTaskRunner::TestSimpleTaskRunner() = default; | 11 TestSimpleTaskRunner::TestSimpleTaskRunner() = default; |
12 | 12 |
13 TestSimpleTaskRunner::~TestSimpleTaskRunner() = default; | 13 TestSimpleTaskRunner::~TestSimpleTaskRunner() = default; |
14 | 14 |
15 bool TestSimpleTaskRunner::PostDelayedTask( | 15 bool TestSimpleTaskRunner::PostDelayedTask( |
16 const tracked_objects::Location& from_here, | 16 const tracked_objects::Location& from_here, |
17 const Closure& task, | 17 OnceClosure task, |
18 TimeDelta delay) { | 18 TimeDelta delay) { |
19 AutoLock auto_lock(lock_); | 19 AutoLock auto_lock(lock_); |
20 pending_tasks_.push_back( | 20 pending_tasks_.push_back(TestPendingTask(from_here, std::move(task), |
21 TestPendingTask(from_here, task, TimeTicks(), delay, | 21 TimeTicks(), delay, |
22 TestPendingTask::NESTABLE)); | 22 TestPendingTask::NESTABLE)); |
23 return true; | 23 return true; |
24 } | 24 } |
25 | 25 |
26 bool TestSimpleTaskRunner::PostNonNestableDelayedTask( | 26 bool TestSimpleTaskRunner::PostNonNestableDelayedTask( |
27 const tracked_objects::Location& from_here, | 27 const tracked_objects::Location& from_here, |
28 const Closure& task, | 28 OnceClosure task, |
29 TimeDelta delay) { | 29 TimeDelta delay) { |
30 AutoLock auto_lock(lock_); | 30 AutoLock auto_lock(lock_); |
31 pending_tasks_.push_back( | 31 pending_tasks_.push_back(TestPendingTask(from_here, std::move(task), |
32 TestPendingTask(from_here, task, TimeTicks(), delay, | 32 TimeTicks(), delay, |
33 TestPendingTask::NON_NESTABLE)); | 33 TestPendingTask::NON_NESTABLE)); |
34 return true; | 34 return true; |
35 } | 35 } |
36 | 36 |
37 bool TestSimpleTaskRunner::RunsTasksOnCurrentThread() const { | 37 bool TestSimpleTaskRunner::RunsTasksOnCurrentThread() const { |
38 return thread_ref_ == PlatformThread::CurrentRef(); | 38 return thread_ref_ == PlatformThread::CurrentRef(); |
39 } | 39 } |
40 | 40 |
41 std::deque<TestPendingTask> TestSimpleTaskRunner::TakePendingTasks() { | 41 std::deque<TestPendingTask> TestSimpleTaskRunner::TakePendingTasks() { |
42 AutoLock auto_lock(lock_); | 42 AutoLock auto_lock(lock_); |
43 return std::move(pending_tasks_); | 43 return std::move(pending_tasks_); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 void TestSimpleTaskRunner::RunPendingTasks() { | 77 void TestSimpleTaskRunner::RunPendingTasks() { |
78 DCHECK(RunsTasksOnCurrentThread()); | 78 DCHECK(RunsTasksOnCurrentThread()); |
79 | 79 |
80 // Swap with a local variable to avoid re-entrancy problems. | 80 // Swap with a local variable to avoid re-entrancy problems. |
81 std::deque<TestPendingTask> tasks_to_run; | 81 std::deque<TestPendingTask> tasks_to_run; |
82 { | 82 { |
83 AutoLock auto_lock(lock_); | 83 AutoLock auto_lock(lock_); |
84 tasks_to_run.swap(pending_tasks_); | 84 tasks_to_run.swap(pending_tasks_); |
85 } | 85 } |
86 | 86 |
87 for (const auto& task : tasks_to_run) | 87 for (auto& task : tasks_to_run) |
88 task.task.Run(); | 88 std::move(task.task).Run(); |
89 } | 89 } |
90 | 90 |
91 void TestSimpleTaskRunner::RunUntilIdle() { | 91 void TestSimpleTaskRunner::RunUntilIdle() { |
92 while (!pending_tasks_.empty()) { | 92 while (!pending_tasks_.empty()) { |
93 RunPendingTasks(); | 93 RunPendingTasks(); |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 } // namespace base | 97 } // namespace base |
OLD | NEW |