| 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 if (delay > base::TimeDelta()) | 150 if (delay > base::TimeDelta()) |
| 151 return delay; | 151 return delay; |
| 152 return base::TimeDelta(); | 152 return base::TimeDelta(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 const size_t OrderedSimpleTaskRunner::kAbsoluteMaxTasks = | 155 const size_t OrderedSimpleTaskRunner::kAbsoluteMaxTasks = |
| 156 std::numeric_limits<size_t>::max(); | 156 std::numeric_limits<size_t>::max(); |
| 157 | 157 |
| 158 bool OrderedSimpleTaskRunner::RunTasksWhile( | 158 bool OrderedSimpleTaskRunner::RunTasksWhile( |
| 159 base::Callback<bool(void)> condition) { | 159 base::Callback<bool(void)> condition) { |
| 160 std::vector<base::Callback<bool(void)> > conditions(1); | 160 std::vector<base::Callback<bool(void)>> conditions(1); |
| 161 conditions[0] = condition; | 161 conditions[0] = condition; |
| 162 return RunTasksWhile(conditions); | 162 return RunTasksWhile(conditions); |
| 163 } | 163 } |
| 164 | 164 |
| 165 bool OrderedSimpleTaskRunner::RunTasksWhile( | 165 bool OrderedSimpleTaskRunner::RunTasksWhile( |
| 166 const std::vector<base::Callback<bool(void)> >& conditions) { | 166 const std::vector<base::Callback<bool(void)>>& conditions) { |
| 167 TRACE_EVENT2("cc", | 167 TRACE_EVENT2("cc", |
| 168 "OrderedSimpleTaskRunner::RunPendingTasks", | 168 "OrderedSimpleTaskRunner::RunPendingTasks", |
| 169 "this", | 169 "this", |
| 170 AsValue(), | 170 AsValue(), |
| 171 "nested", | 171 "nested", |
| 172 inside_run_tasks_until_); | 172 inside_run_tasks_until_); |
| 173 DCHECK(thread_checker_.CalledOnValidThread()); | 173 DCHECK(thread_checker_.CalledOnValidThread()); |
| 174 | 174 |
| 175 if (inside_run_tasks_until_) | 175 if (inside_run_tasks_until_) |
| 176 return true; | 176 return true; |
| 177 | 177 |
| 178 base::AutoReset<bool> reset_inside_run_tasks_until_(&inside_run_tasks_until_, | 178 base::AutoReset<bool> reset_inside_run_tasks_until_(&inside_run_tasks_until_, |
| 179 true); | 179 true); |
| 180 | 180 |
| 181 // Make a copy so we can append some extra run checks. | 181 // Make a copy so we can append some extra run checks. |
| 182 std::vector<base::Callback<bool(void)> > modifiable_conditions(conditions); | 182 std::vector<base::Callback<bool(void)>> modifiable_conditions(conditions); |
| 183 | 183 |
| 184 // Provide a timeout base on number of tasks run so this doesn't loop | 184 // Provide a timeout base on number of tasks run so this doesn't loop |
| 185 // forever. | 185 // forever. |
| 186 modifiable_conditions.push_back(TaskRunCountBelow(max_tasks_)); | 186 modifiable_conditions.push_back(TaskRunCountBelow(max_tasks_)); |
| 187 | 187 |
| 188 // If to advance now or not | 188 // If to advance now or not |
| 189 if (!advance_now_) { | 189 if (!advance_now_) { |
| 190 modifiable_conditions.push_back(NowBefore(now_src_->Now())); | 190 modifiable_conditions.push_back(NowBefore(now_src_->Now())); |
| 191 } else { | 191 } else { |
| 192 modifiable_conditions.push_back(AdvanceNow()); | 192 modifiable_conditions.push_back(AdvanceNow()); |
| 193 } | 193 } |
| 194 | 194 |
| 195 while (pending_tasks_.size() > 0) { | 195 while (pending_tasks_.size() > 0) { |
| 196 // Check if we should continue to run pending tasks. | 196 // Check if we should continue to run pending tasks. |
| 197 bool condition_success = true; | 197 bool condition_success = true; |
| 198 for (std::vector<base::Callback<bool(void)> >::iterator it = | 198 for (std::vector<base::Callback<bool(void)>>::iterator it = |
| 199 modifiable_conditions.begin(); | 199 modifiable_conditions.begin(); |
| 200 it != modifiable_conditions.end(); | 200 it != modifiable_conditions.end(); |
| 201 it++) { | 201 it++) { |
| 202 condition_success = it->Run(); | 202 condition_success = it->Run(); |
| 203 if (!condition_success) | 203 if (!condition_success) |
| 204 break; | 204 break; |
| 205 } | 205 } |
| 206 | 206 |
| 207 // 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 |
| 208 // that there are tasks to run. | 208 // that there are tasks to run. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 224 } | 224 } |
| 225 | 225 |
| 226 return HasPendingTasks(); | 226 return HasPendingTasks(); |
| 227 } | 227 } |
| 228 | 228 |
| 229 bool OrderedSimpleTaskRunner::RunPendingTasks() { | 229 bool OrderedSimpleTaskRunner::RunPendingTasks() { |
| 230 return RunTasksWhile(TaskExistedInitially()); | 230 return RunTasksWhile(TaskExistedInitially()); |
| 231 } | 231 } |
| 232 | 232 |
| 233 bool OrderedSimpleTaskRunner::RunUntilIdle() { | 233 bool OrderedSimpleTaskRunner::RunUntilIdle() { |
| 234 return RunTasksWhile(std::vector<base::Callback<bool(void)> >()); | 234 return RunTasksWhile(std::vector<base::Callback<bool(void)>>()); |
| 235 } | 235 } |
| 236 | 236 |
| 237 bool OrderedSimpleTaskRunner::RunUntilTime(base::TimeTicks time) { | 237 bool OrderedSimpleTaskRunner::RunUntilTime(base::TimeTicks time) { |
| 238 // If we are not auto advancing, force now forward to the time. | 238 // If we are not auto advancing, force now forward to the time. |
| 239 if (!advance_now_ && now_src_->Now() < time) | 239 if (!advance_now_ && now_src_->Now() < time) |
| 240 now_src_->SetNow(time); | 240 now_src_->SetNow(time); |
| 241 | 241 |
| 242 // Run tasks | 242 // Run tasks |
| 243 bool result = RunTasksWhile(NowBefore(time)); | 243 bool result = RunTasksWhile(NowBefore(time)); |
| 244 | 244 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 | 325 |
| 326 bool OrderedSimpleTaskRunner::AdvanceNowCallback() { | 326 bool OrderedSimpleTaskRunner::AdvanceNowCallback() { |
| 327 base::TimeTicks next_task_time = NextTaskTime(); | 327 base::TimeTicks next_task_time = NextTaskTime(); |
| 328 if (now_src_->Now() < next_task_time) { | 328 if (now_src_->Now() < next_task_time) { |
| 329 now_src_->SetNow(next_task_time); | 329 now_src_->SetNow(next_task_time); |
| 330 } | 330 } |
| 331 return true; | 331 return true; |
| 332 } | 332 } |
| 333 | 333 |
| 334 } // namespace cc | 334 } // namespace cc |
| OLD | NEW |