| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "cc/test/ordered_simple_task_runner.h" | 5 #include "cc/test/ordered_simple_task_runner.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 TRACE_TASK("OrderedSimpleTaskRunner::PostNonNestableDelayedTask", pt); | 120 TRACE_TASK("OrderedSimpleTaskRunner::PostNonNestableDelayedTask", pt); |
| 121 pending_tasks_.insert(pt); | 121 pending_tasks_.insert(pt); |
| 122 return true; | 122 return true; |
| 123 } | 123 } |
| 124 | 124 |
| 125 bool OrderedSimpleTaskRunner::RunsTasksOnCurrentThread() const { | 125 bool OrderedSimpleTaskRunner::RunsTasksOnCurrentThread() const { |
| 126 DCHECK(thread_checker_.CalledOnValidThread()); | 126 DCHECK(thread_checker_.CalledOnValidThread()); |
| 127 return true; | 127 return true; |
| 128 } | 128 } |
| 129 | 129 |
| 130 bool OrderedSimpleTaskRunner::HasPendingTasks() { |
| 131 return pending_tasks_.size() > 0; |
| 132 } |
| 133 |
| 130 base::TimeTicks OrderedSimpleTaskRunner::NextTaskTime() { | 134 base::TimeTicks OrderedSimpleTaskRunner::NextTaskTime() { |
| 131 if (pending_tasks_.size() <= 0) { | 135 if (pending_tasks_.size() <= 0) { |
| 132 return TestNowSource::kAbsoluteMaxNow; | 136 return TestNowSource::kAbsoluteMaxNow; |
| 133 } | 137 } |
| 134 | 138 |
| 135 return pending_tasks_.begin()->GetTimeToRun(); | 139 return pending_tasks_.begin()->GetTimeToRun(); |
| 136 } | 140 } |
| 137 | 141 |
| 138 base::TimeDelta OrderedSimpleTaskRunner::DelayToNextTaskTime() { | 142 base::TimeDelta OrderedSimpleTaskRunner::DelayToNextTaskTime() { |
| 139 DCHECK(thread_checker_.CalledOnValidThread()); | 143 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 modifiable_conditions.begin(); | 199 modifiable_conditions.begin(); |
| 196 it != modifiable_conditions.end(); | 200 it != modifiable_conditions.end(); |
| 197 it++) { | 201 it++) { |
| 198 condition_success = it->Run(); | 202 condition_success = it->Run(); |
| 199 if (!condition_success) | 203 if (!condition_success) |
| 200 break; | 204 break; |
| 201 } | 205 } |
| 202 | 206 |
| 203 // Conditions could modify the pending task length, so we need to recheck | 207 // Conditions could modify the pending task length, so we need to recheck |
| 204 // that there are tasks to run. | 208 // that there are tasks to run. |
| 205 if (!condition_success || pending_tasks_.size() == 0) { | 209 if (!condition_success || !HasPendingTasks()) { |
| 206 break; | 210 break; |
| 207 } | 211 } |
| 208 | 212 |
| 209 std::set<TestOrderablePendingTask>::iterator task_to_run = | 213 std::set<TestOrderablePendingTask>::iterator task_to_run = |
| 210 pending_tasks_.begin(); | 214 pending_tasks_.begin(); |
| 211 { | 215 { |
| 212 TRACE_EVENT1("cc", | 216 TRACE_EVENT1("cc", |
| 213 "OrderedSimpleTaskRunner::RunPendingTasks running", | 217 "OrderedSimpleTaskRunner::RunPendingTasks running", |
| 214 "task", | 218 "task", |
| 215 task_to_run->AsValue()); | 219 task_to_run->AsValue()); |
| 216 task_to_run->task.Run(); | 220 task_to_run->task.Run(); |
| 217 } | 221 } |
| 218 | 222 |
| 219 pending_tasks_.erase(task_to_run); | 223 pending_tasks_.erase(task_to_run); |
| 220 } | 224 } |
| 221 | 225 |
| 222 return pending_tasks_.size() > 0; | 226 return HasPendingTasks(); |
| 223 } | 227 } |
| 224 | 228 |
| 225 bool OrderedSimpleTaskRunner::RunPendingTasks() { | 229 bool OrderedSimpleTaskRunner::RunPendingTasks() { |
| 226 return RunTasksWhile(TaskExistedInitially()); | 230 return RunTasksWhile(TaskExistedInitially()); |
| 227 } | 231 } |
| 228 | 232 |
| 229 bool OrderedSimpleTaskRunner::RunUntilIdle() { | 233 bool OrderedSimpleTaskRunner::RunUntilIdle() { |
| 230 return RunTasksWhile(std::vector<base::Callback<bool(void)> >()); | 234 return RunTasksWhile(std::vector<base::Callback<bool(void)> >()); |
| 231 } | 235 } |
| 232 | 236 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 | 320 |
| 317 bool OrderedSimpleTaskRunner::AdvanceNowCallback() { | 321 bool OrderedSimpleTaskRunner::AdvanceNowCallback() { |
| 318 base::TimeTicks next_task_time = NextTaskTime(); | 322 base::TimeTicks next_task_time = NextTaskTime(); |
| 319 if (now_src_->Now() < next_task_time) { | 323 if (now_src_->Now() < next_task_time) { |
| 320 now_src_->SetNow(next_task_time); | 324 now_src_->SetNow(next_task_time); |
| 321 } | 325 } |
| 322 return true; | 326 return true; |
| 323 } | 327 } |
| 324 | 328 |
| 325 } // namespace cc | 329 } // namespace cc |
| OLD | NEW |