| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 return true; | 157 return true; |
| 158 } | 158 } |
| 159 | 159 |
| 160 bool TestMockTimeTaskRunner::PostNonNestableDelayedTask( | 160 bool TestMockTimeTaskRunner::PostNonNestableDelayedTask( |
| 161 const tracked_objects::Location& from_here, | 161 const tracked_objects::Location& from_here, |
| 162 const Closure& task, | 162 const Closure& task, |
| 163 TimeDelta delay) { | 163 TimeDelta delay) { |
| 164 return PostDelayedTask(from_here, task, delay); | 164 return PostDelayedTask(from_here, task, delay); |
| 165 } | 165 } |
| 166 | 166 |
| 167 bool TestMockTimeTaskRunner::IsElapsingStopped() { |
| 168 return false; |
| 169 } |
| 170 |
| 167 void TestMockTimeTaskRunner::OnBeforeSelectingTask() { | 171 void TestMockTimeTaskRunner::OnBeforeSelectingTask() { |
| 168 // Empty default implementation. | 172 // Empty default implementation. |
| 169 } | 173 } |
| 170 | 174 |
| 171 void TestMockTimeTaskRunner::OnAfterTimePassed() { | 175 void TestMockTimeTaskRunner::OnAfterTimePassed() { |
| 172 // Empty default implementation. | 176 // Empty default implementation. |
| 173 } | 177 } |
| 174 | 178 |
| 175 void TestMockTimeTaskRunner::OnAfterTaskRun() { | 179 void TestMockTimeTaskRunner::OnAfterTaskRun() { |
| 176 // Empty default implementation. | 180 // Empty default implementation. |
| 177 } | 181 } |
| 178 | 182 |
| 179 void TestMockTimeTaskRunner::ProcessAllTasksNoLaterThan(TimeDelta max_delta) { | 183 void TestMockTimeTaskRunner::ProcessAllTasksNoLaterThan(TimeDelta max_delta) { |
| 180 DCHECK_GE(max_delta, TimeDelta()); | 184 DCHECK_GE(max_delta, TimeDelta()); |
| 181 const TimeTicks original_now_ticks = now_ticks_; | 185 const TimeTicks original_now_ticks = now_ticks_; |
| 182 while (true) { | 186 while (!IsElapsingStopped()) { |
| 183 OnBeforeSelectingTask(); | 187 OnBeforeSelectingTask(); |
| 184 TestPendingTask task_info; | 188 TestPendingTask task_info; |
| 185 if (!DequeueNextTask(original_now_ticks, max_delta, &task_info)) | 189 if (!DequeueNextTask(original_now_ticks, max_delta, &task_info)) |
| 186 break; | 190 break; |
| 187 // If tasks were posted with a negative delay, task_info.GetTimeToRun() will | 191 // If tasks were posted with a negative delay, task_info.GetTimeToRun() will |
| 188 // be less than |now_ticks_|. ForwardClocksUntilTickTime() takes care of not | 192 // be less than |now_ticks_|. ForwardClocksUntilTickTime() takes care of not |
| 189 // moving the clock backwards in this case. | 193 // moving the clock backwards in this case. |
| 190 ForwardClocksUntilTickTime(task_info.GetTimeToRun()); | 194 ForwardClocksUntilTickTime(task_info.GetTimeToRun()); |
| 191 task_info.task.Run(); | 195 task_info.task.Run(); |
| 192 OnAfterTaskRun(); | 196 OnAfterTaskRun(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 209 if (!tasks_.empty() && | 213 if (!tasks_.empty() && |
| 210 (tasks_.top().GetTimeToRun() - reference) <= max_delta) { | 214 (tasks_.top().GetTimeToRun() - reference) <= max_delta) { |
| 211 *next_task = tasks_.top(); | 215 *next_task = tasks_.top(); |
| 212 tasks_.pop(); | 216 tasks_.pop(); |
| 213 return true; | 217 return true; |
| 214 } | 218 } |
| 215 return false; | 219 return false; |
| 216 } | 220 } |
| 217 | 221 |
| 218 } // namespace base | 222 } // namespace base |
| OLD | NEW |