| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 class TestTaskScheduler : public TaskScheduler { | 34 class TestTaskScheduler : public TaskScheduler { |
| 35 public: | 35 public: |
| 36 // |external_message_loop| is an externally provided MessageLoop on which to | 36 // |external_message_loop| is an externally provided MessageLoop on which to |
| 37 // run tasks. A MessageLoop will be created by TestTaskScheduler if | 37 // run tasks. A MessageLoop will be created by TestTaskScheduler if |
| 38 // |external_message_loop| is nullptr. | 38 // |external_message_loop| is nullptr. |
| 39 explicit TestTaskScheduler(MessageLoop* external_message_loop); | 39 explicit TestTaskScheduler(MessageLoop* external_message_loop); |
| 40 ~TestTaskScheduler() override; | 40 ~TestTaskScheduler() override; |
| 41 | 41 |
| 42 // TaskScheduler: | 42 // TaskScheduler: |
| 43 void PostTaskWithTraits(const tracked_objects::Location& from_here, | 43 void PostDelayedTaskWithTraits(const tracked_objects::Location& from_here, |
| 44 const TaskTraits& traits, | 44 const TaskTraits& traits, |
| 45 const Closure& task) override; | 45 const Closure& task, |
| 46 TimeDelta delay) override; |
| 46 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( | 47 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( |
| 47 const TaskTraits& traits) override; | 48 const TaskTraits& traits) override; |
| 48 scoped_refptr<SequencedTaskRunner> CreateSequencedTaskRunnerWithTraits( | 49 scoped_refptr<SequencedTaskRunner> CreateSequencedTaskRunnerWithTraits( |
| 49 const TaskTraits& traits) override; | 50 const TaskTraits& traits) override; |
| 50 scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits( | 51 scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits( |
| 51 const TaskTraits& traits) override; | 52 const TaskTraits& traits) override; |
| 52 std::vector<const HistogramBase*> GetHistograms() const override; | 53 std::vector<const HistogramBase*> GetHistograms() const override; |
| 53 void Shutdown() override; | 54 void Shutdown() override; |
| 54 void FlushForTesting() override; | 55 void FlushForTesting() override; |
| 55 | 56 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 118 |
| 118 TestTaskScheduler::~TestTaskScheduler() { | 119 TestTaskScheduler::~TestTaskScheduler() { |
| 119 // Prevent the RunUntilIdle() call below from running SKIP_ON_SHUTDOWN and | 120 // Prevent the RunUntilIdle() call below from running SKIP_ON_SHUTDOWN and |
| 120 // CONTINUE_ON_SHUTDOWN tasks. | 121 // CONTINUE_ON_SHUTDOWN tasks. |
| 121 task_tracker_.SetHasShutdownStartedForTesting(); | 122 task_tracker_.SetHasShutdownStartedForTesting(); |
| 122 | 123 |
| 123 // Run pending BLOCK_SHUTDOWN tasks. | 124 // Run pending BLOCK_SHUTDOWN tasks. |
| 124 RunLoop().RunUntilIdle(); | 125 RunLoop().RunUntilIdle(); |
| 125 } | 126 } |
| 126 | 127 |
| 127 void TestTaskScheduler::PostTaskWithTraits( | 128 void TestTaskScheduler::PostDelayedTaskWithTraits( |
| 128 const tracked_objects::Location& from_here, | 129 const tracked_objects::Location& from_here, |
| 129 const TaskTraits& traits, | 130 const TaskTraits& traits, |
| 130 const Closure& task) { | 131 const Closure& task, |
| 131 CreateTaskRunnerWithTraits(traits)->PostTask(from_here, task); | 132 TimeDelta delay) { |
| 133 CreateTaskRunnerWithTraits(traits)->PostDelayedTask(from_here, task, delay); |
| 132 } | 134 } |
| 133 | 135 |
| 134 scoped_refptr<TaskRunner> TestTaskScheduler::CreateTaskRunnerWithTraits( | 136 scoped_refptr<TaskRunner> TestTaskScheduler::CreateTaskRunnerWithTraits( |
| 135 const TaskTraits& traits) { | 137 const TaskTraits& traits) { |
| 136 return make_scoped_refptr( | 138 return make_scoped_refptr( |
| 137 new TestTaskSchedulerTaskRunner(this, ExecutionMode::PARALLEL, traits)); | 139 new TestTaskSchedulerTaskRunner(this, ExecutionMode::PARALLEL, traits)); |
| 138 } | 140 } |
| 139 | 141 |
| 140 scoped_refptr<SequencedTaskRunner> | 142 scoped_refptr<SequencedTaskRunner> |
| 141 TestTaskScheduler::CreateSequencedTaskRunnerWithTraits( | 143 TestTaskScheduler::CreateSequencedTaskRunnerWithTraits( |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 } | 248 } |
| 247 | 249 |
| 248 ScopedTaskScheduler::~ScopedTaskScheduler() { | 250 ScopedTaskScheduler::~ScopedTaskScheduler() { |
| 249 DCHECK(thread_checker_.CalledOnValidThread()); | 251 DCHECK(thread_checker_.CalledOnValidThread()); |
| 250 DCHECK_EQ(task_scheduler_, TaskScheduler::GetInstance()); | 252 DCHECK_EQ(task_scheduler_, TaskScheduler::GetInstance()); |
| 251 TaskScheduler::SetInstance(nullptr); | 253 TaskScheduler::SetInstance(nullptr); |
| 252 } | 254 } |
| 253 | 255 |
| 254 } // namespace test | 256 } // namespace test |
| 255 } // namespace base | 257 } // namespace base |
| OLD | NEW |