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 <algorithm> | 7 #include <algorithm> |
8 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "base/logging.h" | |
11 | |
12 namespace { | 10 namespace { |
13 | 11 |
14 bool TestPendingTaskComparator(const base::TestPendingTask& lhs, | 12 bool TestPendingTaskComparator(const base::TestPendingTask& lhs, |
15 const base::TestPendingTask& rhs) { | 13 const base::TestPendingTask& rhs) { |
16 return lhs.ShouldRunBefore(rhs); | 14 return lhs.ShouldRunBefore(rhs); |
17 } | 15 } |
18 | 16 |
19 } | 17 } |
20 | 18 |
21 namespace cc { | 19 namespace cc { |
22 | 20 |
23 OrderedSimpleTaskRunner::OrderedSimpleTaskRunner() {} | |
24 | |
25 OrderedSimpleTaskRunner::~OrderedSimpleTaskRunner() {} | 21 OrderedSimpleTaskRunner::~OrderedSimpleTaskRunner() {} |
26 | 22 |
27 void OrderedSimpleTaskRunner::RunPendingTasks() { | 23 void OrderedSimpleTaskRunner::RunPendingTasks() { |
28 DCHECK(thread_checker_.CalledOnValidThread()); | 24 DCHECK(thread_checker_.CalledOnValidThread()); |
29 // Swap with a local variable to avoid re-entrancy problems. | 25 // Swap with a local variable to avoid re-entrancy problems. |
30 std::deque<base::TestPendingTask> tasks_to_run; | 26 std::deque<base::TestPendingTask> tasks_to_run; |
31 tasks_to_run.swap(pending_tasks_); | 27 tasks_to_run.swap(pending_tasks_); |
32 std::stable_sort(tasks_to_run.begin(), | 28 std::stable_sort(tasks_to_run.begin(), |
33 tasks_to_run.end(), | 29 tasks_to_run.end(), |
34 TestPendingTaskComparator); | 30 TestPendingTaskComparator); |
| 31 |
35 for (std::deque<base::TestPendingTask>::iterator it = tasks_to_run.begin(); | 32 for (std::deque<base::TestPendingTask>::iterator it = tasks_to_run.begin(); |
36 it != tasks_to_run.end(); ++it) { | 33 it != tasks_to_run.end(); ++it) { |
| 34 base::TimeTicks task_time = it->GetTimeToRun(); |
| 35 if (Now() < task_time) { |
| 36 if (advance_now_) { |
| 37 SetNow(task_time); |
| 38 } else { |
| 39 pending_tasks_.push_back(*it); |
| 40 continue; |
| 41 } |
| 42 } |
37 it->task.Run(); | 43 it->task.Run(); |
38 } | 44 } |
39 } | 45 } |
40 | 46 |
41 } // namespace cc | 47 } // namespace cc |
OLD | NEW |