| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/task_scheduler/test_task_factory.h" | 5 #include "base/task_scheduler/test_task_factory.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 TestTaskFactory::~TestTaskFactory() { | 31 TestTaskFactory::~TestTaskFactory() { |
| 32 WaitForAllTasksToRun(); | 32 WaitForAllTasksToRun(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 bool TestTaskFactory::PostTask(PostNestedTask post_nested_task, | 35 bool TestTaskFactory::PostTask(PostNestedTask post_nested_task, |
| 36 const Closure& after_task_closure) { | 36 const Closure& after_task_closure) { |
| 37 AutoLock auto_lock(lock_); | 37 AutoLock auto_lock(lock_); |
| 38 return task_runner_->PostTask( | 38 return task_runner_->PostTask( |
| 39 FROM_HERE, | 39 FROM_HERE, |
| 40 Bind(&TestTaskFactory::RunTaskCallback, Unretained(this), | 40 BindOnce(&TestTaskFactory::RunTaskCallback, Unretained(this), |
| 41 num_posted_tasks_++, post_nested_task, after_task_closure)); | 41 num_posted_tasks_++, post_nested_task, after_task_closure)); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void TestTaskFactory::WaitForAllTasksToRun() const { | 44 void TestTaskFactory::WaitForAllTasksToRun() const { |
| 45 AutoLock auto_lock(lock_); | 45 AutoLock auto_lock(lock_); |
| 46 while (ran_tasks_.size() < num_posted_tasks_) | 46 while (ran_tasks_.size() < num_posted_tasks_) |
| 47 cv_.Wait(); | 47 cv_.Wait(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void TestTaskFactory::RunTaskCallback(size_t task_index, | 50 void TestTaskFactory::RunTaskCallback(size_t task_index, |
| 51 PostNestedTask post_nested_task, | 51 PostNestedTask post_nested_task, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 cv_.Signal(); | 97 cv_.Signal(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 if (!after_task_closure.is_null()) | 100 if (!after_task_closure.is_null()) |
| 101 after_task_closure.Run(); | 101 after_task_closure.Run(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 } // namespace test | 104 } // namespace test |
| 105 } // namespace internal | 105 } // namespace internal |
| 106 } // namespace base | 106 } // namespace base |
| OLD | NEW |