| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/test_mock_time_task_runner.h" | 5 #include "base/test/test_mock_time_task_runner.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/time/clock.h" | 9 #include "base/time/clock.h" |
| 10 #include "base/time/tick_clock.h" | 10 #include "base/time/tick_clock.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 return true; | 150 return true; |
| 151 } | 151 } |
| 152 | 152 |
| 153 bool TestMockTimeTaskRunner::PostNonNestableDelayedTask( | 153 bool TestMockTimeTaskRunner::PostNonNestableDelayedTask( |
| 154 const tracked_objects::Location& from_here, | 154 const tracked_objects::Location& from_here, |
| 155 const Closure& task, | 155 const Closure& task, |
| 156 TimeDelta delay) { | 156 TimeDelta delay) { |
| 157 return PostDelayedTask(from_here, task, delay); | 157 return PostDelayedTask(from_here, task, delay); |
| 158 } | 158 } |
| 159 | 159 |
| 160 bool TestMockTimeTaskRunner::IsElapsingStopped() { |
| 161 return false; |
| 162 } |
| 163 |
| 160 void TestMockTimeTaskRunner::OnBeforeSelectingTask() { | 164 void TestMockTimeTaskRunner::OnBeforeSelectingTask() { |
| 161 // Empty default implementation. | 165 // Empty default implementation. |
| 162 } | 166 } |
| 163 | 167 |
| 164 void TestMockTimeTaskRunner::OnAfterTimePassed() { | 168 void TestMockTimeTaskRunner::OnAfterTimePassed() { |
| 165 // Empty default implementation. | 169 // Empty default implementation. |
| 166 } | 170 } |
| 167 | 171 |
| 168 void TestMockTimeTaskRunner::OnAfterTaskRun() { | 172 void TestMockTimeTaskRunner::OnAfterTaskRun() { |
| 169 // Empty default implementation. | 173 // Empty default implementation. |
| 170 } | 174 } |
| 171 | 175 |
| 172 void TestMockTimeTaskRunner::ProcessAllTasksNoLaterThan(TimeDelta max_delta) { | 176 void TestMockTimeTaskRunner::ProcessAllTasksNoLaterThan(TimeDelta max_delta) { |
| 173 DCHECK_GE(max_delta, TimeDelta()); | 177 DCHECK_GE(max_delta, TimeDelta()); |
| 174 const TimeTicks original_now_ticks = now_ticks_; | 178 const TimeTicks original_now_ticks = now_ticks_; |
| 175 while (true) { | 179 while (!IsElapsingStopped()) { |
| 176 OnBeforeSelectingTask(); | 180 OnBeforeSelectingTask(); |
| 177 TestPendingTask task_info; | 181 TestPendingTask task_info; |
| 178 if (!DequeueNextTask(original_now_ticks, max_delta, &task_info)) | 182 if (!DequeueNextTask(original_now_ticks, max_delta, &task_info)) |
| 179 break; | 183 break; |
| 180 // If tasks were posted with a negative delay, task_info.GetTimeToRun() will | 184 // If tasks were posted with a negative delay, task_info.GetTimeToRun() will |
| 181 // be less than |now_ticks_|. ForwardClocksUntilTickTime() takes care of not | 185 // be less than |now_ticks_|. ForwardClocksUntilTickTime() takes care of not |
| 182 // moving the clock backwards in this case. | 186 // moving the clock backwards in this case. |
| 183 ForwardClocksUntilTickTime(task_info.GetTimeToRun()); | 187 ForwardClocksUntilTickTime(task_info.GetTimeToRun()); |
| 184 task_info.task.Run(); | 188 task_info.task.Run(); |
| 185 OnAfterTaskRun(); | 189 OnAfterTaskRun(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 202 if (!tasks_.empty() && | 206 if (!tasks_.empty() && |
| 203 (tasks_.top().GetTimeToRun() - reference) <= max_delta) { | 207 (tasks_.top().GetTimeToRun() - reference) <= max_delta) { |
| 204 *next_task = tasks_.top(); | 208 *next_task = tasks_.top(); |
| 205 tasks_.pop(); | 209 tasks_.pop(); |
| 206 return true; | 210 return true; |
| 207 } | 211 } |
| 208 return false; | 212 return false; |
| 209 } | 213 } |
| 210 | 214 |
| 211 } // namespace base | 215 } // namespace base |
| OLD | NEW |