Chromium Code Reviews| 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/test/scoped_task_scheduler.h" | 5 #include "base/test/scoped_task_scheduler.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 | 40 |
| 41 class TestTaskScheduler : public TaskScheduler { | 41 class TestTaskScheduler : public TaskScheduler { |
| 42 public: | 42 public: |
| 43 // |external_message_loop| is an externally provided MessageLoop on which to | 43 // |external_message_loop| is an externally provided MessageLoop on which to |
| 44 // run tasks. A MessageLoop will be created by TestTaskScheduler if | 44 // run tasks. A MessageLoop will be created by TestTaskScheduler if |
| 45 // |external_message_loop| is nullptr. | 45 // |external_message_loop| is nullptr. |
| 46 explicit TestTaskScheduler(MessageLoop* external_message_loop); | 46 explicit TestTaskScheduler(MessageLoop* external_message_loop); |
| 47 ~TestTaskScheduler() override; | 47 ~TestTaskScheduler() override; |
| 48 | 48 |
| 49 // TaskScheduler: | 49 // TaskScheduler: |
| 50 void Start(const TaskScheduler::InitParams& init_params) override; | |
| 50 void PostDelayedTaskWithTraits(const tracked_objects::Location& from_here, | 51 void PostDelayedTaskWithTraits(const tracked_objects::Location& from_here, |
| 51 const TaskTraits& traits, | 52 const TaskTraits& traits, |
| 52 OnceClosure task, | 53 OnceClosure task, |
| 53 TimeDelta delay) override; | 54 TimeDelta delay) override; |
| 54 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( | 55 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( |
| 55 const TaskTraits& traits) override; | 56 const TaskTraits& traits) override; |
| 56 scoped_refptr<SequencedTaskRunner> CreateSequencedTaskRunnerWithTraits( | 57 scoped_refptr<SequencedTaskRunner> CreateSequencedTaskRunnerWithTraits( |
| 57 const TaskTraits& traits) override; | 58 const TaskTraits& traits) override; |
| 58 scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits( | 59 scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits( |
| 59 const TaskTraits& traits) override; | 60 const TaskTraits& traits) override; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 : MakeUnique<MessageLoop>()), | 158 : MakeUnique<MessageLoop>()), |
| 158 message_loop_(message_loop_owned_ ? message_loop_owned_.get() | 159 message_loop_(message_loop_owned_ ? message_loop_owned_.get() |
| 159 : external_message_loop) {} | 160 : external_message_loop) {} |
| 160 | 161 |
| 161 TestTaskScheduler::~TestTaskScheduler() { | 162 TestTaskScheduler::~TestTaskScheduler() { |
| 162 // Shutdown if it hasn't already been done explicitly. | 163 // Shutdown if it hasn't already been done explicitly. |
| 163 if (!task_tracker_.HasShutdownStarted()) | 164 if (!task_tracker_.HasShutdownStarted()) |
| 164 Shutdown(); | 165 Shutdown(); |
| 165 } | 166 } |
| 166 | 167 |
| 168 void TestTaskScheduler::Start(const TaskScheduler::InitParams&) { | |
| 169 // ScopedTaskScheduler intentionally breaks the TaskScheduler contract of not | |
|
robliao
2017/04/24 22:32:19
This comment should probably go at the top of Test
gab
2017/04/25 15:16:15
Agreed, also this is another argument for getting
fdoray
2017/04/25 18:43:35
Done.
| |
| 170 // running tasks before Start(). This avoid having to call Start() with dummy | |
| 171 // parameters. | |
| 172 NOTREACHED(); | |
| 173 } | |
| 174 | |
| 167 void TestTaskScheduler::PostDelayedTaskWithTraits( | 175 void TestTaskScheduler::PostDelayedTaskWithTraits( |
| 168 const tracked_objects::Location& from_here, | 176 const tracked_objects::Location& from_here, |
| 169 const TaskTraits& traits, | 177 const TaskTraits& traits, |
| 170 OnceClosure task, | 178 OnceClosure task, |
| 171 TimeDelta delay) { | 179 TimeDelta delay) { |
| 172 CreateTaskRunnerWithTraits(traits)->PostDelayedTask(from_here, | 180 CreateTaskRunnerWithTraits(traits)->PostDelayedTask(from_here, |
| 173 std::move(task), delay); | 181 std::move(task), delay); |
| 174 } | 182 } |
| 175 | 183 |
| 176 scoped_refptr<TaskRunner> TestTaskScheduler::CreateTaskRunnerWithTraits( | 184 scoped_refptr<TaskRunner> TestTaskScheduler::CreateTaskRunnerWithTraits( |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 DCHECK_EQ(task_scheduler_, TaskScheduler::GetInstance()); | 331 DCHECK_EQ(task_scheduler_, TaskScheduler::GetInstance()); |
| 324 | 332 |
| 325 // Per contract, call JoinForTesting() before deleting the TaskScheduler. | 333 // Per contract, call JoinForTesting() before deleting the TaskScheduler. |
| 326 TaskScheduler::GetInstance()->JoinForTesting(); | 334 TaskScheduler::GetInstance()->JoinForTesting(); |
| 327 | 335 |
| 328 TaskScheduler::SetInstance(nullptr); | 336 TaskScheduler::SetInstance(nullptr); |
| 329 } | 337 } |
| 330 | 338 |
| 331 } // namespace test | 339 } // namespace test |
| 332 } // namespace base | 340 } // namespace base |
| OLD | NEW |