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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
11 #include <set> | 11 #include <set> |
12 #include <sstream> | 12 #include <sstream> |
13 #include <string> | 13 #include <string> |
| 14 #include <utility> |
14 #include <vector> | 15 #include <vector> |
15 | 16 |
16 #include "base/auto_reset.h" | 17 #include "base/auto_reset.h" |
17 #include "base/numerics/safe_conversions.h" | 18 #include "base/numerics/safe_conversions.h" |
18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
19 #include "base/trace_event/trace_event.h" | 20 #include "base/trace_event/trace_event.h" |
20 #include "base/trace_event/trace_event_argument.h" | 21 #include "base/trace_event/trace_event_argument.h" |
21 | 22 |
22 #define TRACE_TASK(function, task) \ | 23 #define TRACE_TASK(function, task) \ |
23 TRACE_EVENT_INSTANT1( \ | 24 TRACE_EVENT_INSTANT1( \ |
24 "cc", function, TRACE_EVENT_SCOPE_THREAD, "task", task.AsValue()); | 25 "cc", function, TRACE_EVENT_SCOPE_THREAD, "task", task.AsValue()); |
25 | 26 |
26 #define TRACE_TASK_RUN(function, tag, task) | 27 #define TRACE_TASK_RUN(function, tag, task) |
27 | 28 |
28 namespace cc { | 29 namespace cc { |
29 | 30 |
30 // TestOrderablePendingTask implementation | 31 // TestOrderablePendingTask implementation |
31 TestOrderablePendingTask::TestOrderablePendingTask() | 32 TestOrderablePendingTask::TestOrderablePendingTask() |
32 : base::TestPendingTask(), | 33 : base::TestPendingTask(), |
33 task_id_(TestOrderablePendingTask::task_id_counter++) { | 34 task_id_(TestOrderablePendingTask::task_id_counter++) { |
34 } | 35 } |
35 | 36 |
36 TestOrderablePendingTask::TestOrderablePendingTask( | 37 TestOrderablePendingTask::TestOrderablePendingTask( |
37 const tracked_objects::Location& location, | 38 const tracked_objects::Location& location, |
38 const base::Closure& task, | 39 base::Closure task, |
39 base::TimeTicks post_time, | 40 base::TimeTicks post_time, |
40 base::TimeDelta delay, | 41 base::TimeDelta delay, |
41 TestNestability nestability) | 42 TestNestability nestability) |
42 : base::TestPendingTask(location, task, post_time, delay, nestability), | 43 : base::TestPendingTask(location, |
43 task_id_(TestOrderablePendingTask::task_id_counter++) { | 44 std::move(task), |
44 } | 45 post_time, |
| 46 delay, |
| 47 nestability), |
| 48 task_id_(TestOrderablePendingTask::task_id_counter++) {} |
45 | 49 |
46 TestOrderablePendingTask::TestOrderablePendingTask(TestOrderablePendingTask&&) = | 50 TestOrderablePendingTask::TestOrderablePendingTask(TestOrderablePendingTask&&) = |
47 default; | 51 default; |
48 | 52 |
49 TestOrderablePendingTask& TestOrderablePendingTask::operator=( | 53 TestOrderablePendingTask& TestOrderablePendingTask::operator=( |
50 TestOrderablePendingTask&&) = default; | 54 TestOrderablePendingTask&&) = default; |
51 | 55 |
52 size_t TestOrderablePendingTask::task_id_counter = 0; | 56 size_t TestOrderablePendingTask::task_id_counter = 0; |
53 | 57 |
54 TestOrderablePendingTask::~TestOrderablePendingTask() { | 58 TestOrderablePendingTask::~TestOrderablePendingTask() { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 102 |
99 // static | 103 // static |
100 base::TimeTicks OrderedSimpleTaskRunner::AbsoluteMaxNow() { | 104 base::TimeTicks OrderedSimpleTaskRunner::AbsoluteMaxNow() { |
101 return base::TimeTicks::FromInternalValue( | 105 return base::TimeTicks::FromInternalValue( |
102 std::numeric_limits<int64_t>::max()); | 106 std::numeric_limits<int64_t>::max()); |
103 } | 107 } |
104 | 108 |
105 // base::TestSimpleTaskRunner implementation | 109 // base::TestSimpleTaskRunner implementation |
106 bool OrderedSimpleTaskRunner::PostDelayedTask( | 110 bool OrderedSimpleTaskRunner::PostDelayedTask( |
107 const tracked_objects::Location& from_here, | 111 const tracked_objects::Location& from_here, |
108 const base::Closure& task, | 112 base::Closure task, |
109 base::TimeDelta delay) { | 113 base::TimeDelta delay) { |
110 DCHECK(thread_checker_.CalledOnValidThread()); | 114 DCHECK(thread_checker_.CalledOnValidThread()); |
111 TestOrderablePendingTask pt(from_here, task, now_src_->NowTicks(), delay, | 115 TestOrderablePendingTask pt(from_here, std::move(task), now_src_->NowTicks(), |
112 base::TestPendingTask::NESTABLE); | 116 delay, base::TestPendingTask::NESTABLE); |
113 | 117 |
114 TRACE_TASK("OrderedSimpleTaskRunner::PostDelayedTask", pt); | 118 TRACE_TASK("OrderedSimpleTaskRunner::PostDelayedTask", pt); |
115 pending_tasks_.insert(std::move(pt)); | 119 pending_tasks_.insert(std::move(pt)); |
116 return true; | 120 return true; |
117 } | 121 } |
118 | 122 |
119 bool OrderedSimpleTaskRunner::PostNonNestableDelayedTask( | 123 bool OrderedSimpleTaskRunner::PostNonNestableDelayedTask( |
120 const tracked_objects::Location& from_here, | 124 const tracked_objects::Location& from_here, |
121 const base::Closure& task, | 125 base::Closure task, |
122 base::TimeDelta delay) { | 126 base::TimeDelta delay) { |
123 DCHECK(thread_checker_.CalledOnValidThread()); | 127 DCHECK(thread_checker_.CalledOnValidThread()); |
124 TestOrderablePendingTask pt(from_here, task, now_src_->NowTicks(), delay, | 128 TestOrderablePendingTask pt(from_here, std::move(task), now_src_->NowTicks(), |
125 base::TestPendingTask::NON_NESTABLE); | 129 delay, base::TestPendingTask::NON_NESTABLE); |
126 | 130 |
127 TRACE_TASK("OrderedSimpleTaskRunner::PostNonNestableDelayedTask", pt); | 131 TRACE_TASK("OrderedSimpleTaskRunner::PostNonNestableDelayedTask", pt); |
128 pending_tasks_.insert(std::move(pt)); | 132 pending_tasks_.insert(std::move(pt)); |
129 return true; | 133 return true; |
130 } | 134 } |
131 | 135 |
132 bool OrderedSimpleTaskRunner::RunsTasksOnCurrentThread() const { | 136 bool OrderedSimpleTaskRunner::RunsTasksOnCurrentThread() const { |
133 DCHECK(thread_checker_.CalledOnValidThread()); | 137 DCHECK(thread_checker_.CalledOnValidThread()); |
134 return true; | 138 return true; |
135 } | 139 } |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 while (it != pending_tasks_.end()) { | 374 while (it != pending_tasks_.end()) { |
371 if (it->task.IsCancelled()) { | 375 if (it->task.IsCancelled()) { |
372 it = pending_tasks_.erase(it); | 376 it = pending_tasks_.erase(it); |
373 } else { | 377 } else { |
374 it++; | 378 it++; |
375 } | 379 } |
376 } | 380 } |
377 } | 381 } |
378 | 382 |
379 } // namespace cc | 383 } // namespace cc |
OLD | NEW |