Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: base/test/test_simple_task_runner.cc

Issue 2331423002: Replace TestSimpleTaskRunner::GetPendingTasks with TakePendingTasks (Closed)
Patch Set: split test Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/test/test_simple_task_runner.h ('k') | cc/base/delayed_unique_notifier_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 20 matching lines...) Expand all
31 pending_tasks_.push_back( 31 pending_tasks_.push_back(
32 TestPendingTask(from_here, task, TimeTicks(), delay, 32 TestPendingTask(from_here, task, 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::GetPendingTasks() const { 41 std::deque<TestPendingTask> TestSimpleTaskRunner::TakePendingTasks() {
42 AutoLock auto_lock(lock_); 42 AutoLock auto_lock(lock_);
43 return pending_tasks_; 43 return std::move(pending_tasks_);
44 } 44 }
45 45
46 size_t TestSimpleTaskRunner::NumPendingTasks() const { 46 size_t TestSimpleTaskRunner::NumPendingTasks() const {
47 AutoLock auto_lock(lock_); 47 AutoLock auto_lock(lock_);
48 return pending_tasks_.size(); 48 return pending_tasks_.size();
49 } 49 }
50 50
51 bool TestSimpleTaskRunner::HasPendingTask() const { 51 bool TestSimpleTaskRunner::HasPendingTask() const {
52 AutoLock auto_lock(lock_); 52 AutoLock auto_lock(lock_);
53 return !pending_tasks_.empty(); 53 return !pending_tasks_.empty();
54 } 54 }
55 55
56 base::TimeDelta TestSimpleTaskRunner::NextPendingTaskDelay() const { 56 base::TimeDelta TestSimpleTaskRunner::NextPendingTaskDelay() const {
57 AutoLock auto_lock(lock_); 57 AutoLock auto_lock(lock_);
58 return pending_tasks_.front().GetTimeToRun() - base::TimeTicks(); 58 return pending_tasks_.front().GetTimeToRun() - base::TimeTicks();
59 } 59 }
60 60
61 base::TimeDelta TestSimpleTaskRunner::FinalPendingTaskDelay() const {
62 AutoLock auto_lock(lock_);
63 return pending_tasks_.back().GetTimeToRun() - base::TimeTicks();
64 }
65
61 void TestSimpleTaskRunner::ClearPendingTasks() { 66 void TestSimpleTaskRunner::ClearPendingTasks() {
62 AutoLock auto_lock(lock_); 67 AutoLock auto_lock(lock_);
63 pending_tasks_.clear(); 68 pending_tasks_.clear();
64 } 69 }
65 70
66 void TestSimpleTaskRunner::RunPendingTasks() { 71 void TestSimpleTaskRunner::RunPendingTasks() {
67 DCHECK(RunsTasksOnCurrentThread()); 72 DCHECK(RunsTasksOnCurrentThread());
68 73
69 // Swap with a local variable to avoid re-entrancy problems. 74 // Swap with a local variable to avoid re-entrancy problems.
70 std::deque<TestPendingTask> tasks_to_run; 75 std::deque<TestPendingTask> tasks_to_run;
71 { 76 {
72 AutoLock auto_lock(lock_); 77 AutoLock auto_lock(lock_);
73 tasks_to_run.swap(pending_tasks_); 78 tasks_to_run.swap(pending_tasks_);
74 } 79 }
75 80
76 for (const auto& task : tasks_to_run) 81 for (const auto& task : tasks_to_run)
77 task.task.Run(); 82 task.task.Run();
78 } 83 }
79 84
80 void TestSimpleTaskRunner::RunUntilIdle() { 85 void TestSimpleTaskRunner::RunUntilIdle() {
81 while (!pending_tasks_.empty()) { 86 while (!pending_tasks_.empty()) {
82 RunPendingTasks(); 87 RunPendingTasks();
83 } 88 }
84 } 89 }
85 90
86 } // namespace base 91 } // namespace base
OLDNEW
« no previous file with comments | « base/test/test_simple_task_runner.h ('k') | cc/base/delayed_unique_notifier_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698