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/task_runner_test_template.h" | 5 #include "base/test/task_runner_test_template.h" |
6 | 6 |
7 namespace base { | 7 namespace base { |
8 | 8 |
9 namespace internal { | 9 namespace internal { |
10 | 10 |
11 TaskTracker::TaskTracker() {} | 11 TaskTracker::TaskTracker() : task_runs_(0), task_runs_cv_(&lock_) {} |
12 | 12 |
13 TaskTracker::~TaskTracker() {} | 13 TaskTracker::~TaskTracker() {} |
14 | 14 |
15 Closure TaskTracker::WrapTask(const Closure& task, int i) { | 15 Closure TaskTracker::WrapTask(const Closure& task, int i) { |
16 return Bind(&TaskTracker::RunTask, this, task, i); | 16 return Bind(&TaskTracker::RunTask, this, task, i); |
17 } | 17 } |
18 | 18 |
19 void TaskTracker::RunTask(const Closure& task, int i) { | 19 void TaskTracker::RunTask(const Closure& task, int i) { |
20 AutoLock lock(task_run_counts_lock_); | 20 AutoLock lock(lock_); |
21 if (!task.is_null()) { | 21 if (!task.is_null()) { |
22 task.Run(); | 22 task.Run(); |
23 } | 23 } |
24 ++task_run_counts_[i]; | 24 ++task_run_counts_[i]; |
| 25 ++task_runs_; |
| 26 task_runs_cv_.Signal(); |
25 } | 27 } |
26 | 28 |
27 std::map<int, int> TaskTracker::GetTaskRunCounts() const { | 29 std::map<int, int> TaskTracker::GetTaskRunCounts() const { |
28 AutoLock lock(task_run_counts_lock_); | 30 AutoLock lock(lock_); |
29 return task_run_counts_; | 31 return task_run_counts_; |
30 } | 32 } |
31 | 33 |
| 34 void TaskTracker::WaitForCompletedTasks(int count) { |
| 35 AutoLock lock(lock_); |
| 36 while (task_runs_ < count) |
| 37 task_runs_cv_.Wait(); |
| 38 } |
| 39 |
32 void ExpectRunsTasksOnCurrentThread( | 40 void ExpectRunsTasksOnCurrentThread( |
33 bool expected_value, | 41 bool expected_value, |
34 const scoped_refptr<TaskRunner>& task_runner) { | 42 const scoped_refptr<TaskRunner>& task_runner) { |
35 EXPECT_EQ(expected_value, task_runner->RunsTasksOnCurrentThread()); | 43 EXPECT_EQ(expected_value, task_runner->RunsTasksOnCurrentThread()); |
36 } | 44 } |
37 | 45 |
38 } // namespace internal | 46 } // namespace internal |
39 | 47 |
40 } // namespace base | 48 } // namespace base |
OLD | NEW |