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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 // TestTaskScheduler doesn't create threads so this does nothing. | 229 // TestTaskScheduler doesn't create threads so this does nothing. |
230 } | 230 } |
231 | 231 |
232 bool TestTaskScheduler::PostTask(std::unique_ptr<internal::Task> task, | 232 bool TestTaskScheduler::PostTask(std::unique_ptr<internal::Task> task, |
233 const SequenceToken& sequence_token) { | 233 const SequenceToken& sequence_token) { |
234 DCHECK(task); | 234 DCHECK(task); |
235 if (!task_tracker_.WillPostTask(task.get())) | 235 if (!task_tracker_.WillPostTask(task.get())) |
236 return false; | 236 return false; |
237 internal::Task* const task_ptr = task.get(); | 237 internal::Task* const task_ptr = task.get(); |
238 return MessageLoopTaskRunner()->PostDelayedTask( | 238 return MessageLoopTaskRunner()->PostDelayedTask( |
239 task_ptr->posted_from, Bind(&TestTaskScheduler::RunTask, Unretained(this), | 239 task_ptr->posted_from, |
240 Passed(&task), sequence_token), | 240 BindOnce(&TestTaskScheduler::RunTask, Unretained(this), Passed(&task), |
| 241 sequence_token), |
241 task_ptr->delay); | 242 task_ptr->delay); |
242 } | 243 } |
243 | 244 |
244 void TestTaskScheduler::RunTask(std::unique_ptr<internal::Task> task, | 245 void TestTaskScheduler::RunTask(std::unique_ptr<internal::Task> task, |
245 const SequenceToken& sequence_token) { | 246 const SequenceToken& sequence_token) { |
246 DCHECK(!saved_task_runner_); | 247 DCHECK(!saved_task_runner_); |
247 saved_task_runner_ = MessageLoop::current()->task_runner(); | 248 saved_task_runner_ = MessageLoop::current()->task_runner(); |
248 | 249 |
249 // Clear the MessageLoop TaskRunner to allow TaskTracker to register its own | 250 // Clear the MessageLoop TaskRunner to allow TaskTracker to register its own |
250 // Thread/SequencedTaskRunnerHandle as appropriate. | 251 // Thread/SequencedTaskRunnerHandle as appropriate. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 DCHECK_EQ(task_scheduler_, TaskScheduler::GetInstance()); | 323 DCHECK_EQ(task_scheduler_, TaskScheduler::GetInstance()); |
323 | 324 |
324 // Per contract, call JoinForTesting() before deleting the TaskScheduler. | 325 // Per contract, call JoinForTesting() before deleting the TaskScheduler. |
325 TaskScheduler::GetInstance()->JoinForTesting(); | 326 TaskScheduler::GetInstance()->JoinForTesting(); |
326 | 327 |
327 TaskScheduler::SetInstance(nullptr); | 328 TaskScheduler::SetInstance(nullptr); |
328 } | 329 } |
329 | 330 |
330 } // namespace test | 331 } // namespace test |
331 } // namespace base | 332 } // namespace base |
OLD | NEW |