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 "components/scheduler/child/idle_helper.h" | 5 #include "components/scheduler/child/idle_helper.h" |
6 | 6 |
7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
9 #include "base/trace_event/trace_event_argument.h" | 9 #include "base/trace_event/trace_event_argument.h" |
10 #include "components/scheduler/base/task_queue.h" | 10 #include "components/scheduler/base/task_queue.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 EndIdlePeriod(); | 132 EndIdlePeriod(); |
133 | 133 |
134 if (ShouldWaitForQuiescence()) { | 134 if (ShouldWaitForQuiescence()) { |
135 helper_->ControlTaskRunner()->PostDelayedTask( | 135 helper_->ControlTaskRunner()->PostDelayedTask( |
136 FROM_HERE, enable_next_long_idle_period_closure_.callback(), | 136 FROM_HERE, enable_next_long_idle_period_closure_.callback(), |
137 required_quiescence_duration_before_long_idle_period_); | 137 required_quiescence_duration_before_long_idle_period_); |
138 delegate_->IsNotQuiescent(); | 138 delegate_->IsNotQuiescent(); |
139 return; | 139 return; |
140 } | 140 } |
141 | 141 |
142 base::TimeTicks now(helper_->Now()); | 142 base::TimeTicks now(helper_->tick_clock()->NowTicks()); |
143 base::TimeDelta next_long_idle_period_delay; | 143 base::TimeDelta next_long_idle_period_delay; |
144 IdlePeriodState new_idle_period_state = | 144 IdlePeriodState new_idle_period_state = |
145 ComputeNewLongIdlePeriodState(now, &next_long_idle_period_delay); | 145 ComputeNewLongIdlePeriodState(now, &next_long_idle_period_delay); |
146 if (IsInIdlePeriod(new_idle_period_state)) { | 146 if (IsInIdlePeriod(new_idle_period_state)) { |
147 StartIdlePeriod(new_idle_period_state, now, | 147 StartIdlePeriod(new_idle_period_state, now, |
148 now + next_long_idle_period_delay); | 148 now + next_long_idle_period_delay); |
149 } else { | 149 } else { |
150 // Otherwise wait for the next long idle period delay before trying again. | 150 // Otherwise wait for the next long idle period delay before trying again. |
151 helper_->ControlTaskRunner()->PostDelayedTask( | 151 helper_->ControlTaskRunner()->PostDelayedTask( |
152 FROM_HERE, enable_next_long_idle_period_closure_.callback(), | 152 FROM_HERE, enable_next_long_idle_period_closure_.callback(), |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 196 |
197 void IdleHelper::WillProcessTask(const base::PendingTask& pending_task) { | 197 void IdleHelper::WillProcessTask(const base::PendingTask& pending_task) { |
198 } | 198 } |
199 | 199 |
200 void IdleHelper::DidProcessTask(const base::PendingTask& pending_task) { | 200 void IdleHelper::DidProcessTask(const base::PendingTask& pending_task) { |
201 helper_->CheckOnValidThread(); | 201 helper_->CheckOnValidThread(); |
202 TRACE_EVENT0(disabled_by_default_tracing_category_, "DidProcessTask"); | 202 TRACE_EVENT0(disabled_by_default_tracing_category_, "DidProcessTask"); |
203 if (IsInIdlePeriod(state_.idle_period_state()) && | 203 if (IsInIdlePeriod(state_.idle_period_state()) && |
204 state_.idle_period_state() != | 204 state_.idle_period_state() != |
205 IdlePeriodState::IN_LONG_IDLE_PERIOD_PAUSED && | 205 IdlePeriodState::IN_LONG_IDLE_PERIOD_PAUSED && |
206 helper_->Now() >= state_.idle_period_deadline()) { | 206 helper_->tick_clock()->NowTicks() >= state_.idle_period_deadline()) { |
207 // If the idle period deadline has now been reached, either end the idle | 207 // If the idle period deadline has now been reached, either end the idle |
208 // period or trigger a new long-idle period. | 208 // period or trigger a new long-idle period. |
209 if (IsInLongIdlePeriod(state_.idle_period_state())) { | 209 if (IsInLongIdlePeriod(state_.idle_period_state())) { |
210 EnableLongIdlePeriod(); | 210 EnableLongIdlePeriod(); |
211 } else { | 211 } else { |
212 DCHECK(IdlePeriodState::IN_SHORT_IDLE_PERIOD == | 212 DCHECK(IdlePeriodState::IN_SHORT_IDLE_PERIOD == |
213 state_.idle_period_state()); | 213 state_.idle_period_state()); |
214 EndIdlePeriod(); | 214 EndIdlePeriod(); |
215 } | 215 } |
216 } | 216 } |
(...skipping 14 matching lines...) Expand all Loading... |
231 // If there is still idle work to do then just start the next idle period. | 231 // If there is still idle work to do then just start the next idle period. |
232 base::TimeDelta next_long_idle_period_delay; | 232 base::TimeDelta next_long_idle_period_delay; |
233 if (state_.idle_period_state() == | 233 if (state_.idle_period_state() == |
234 IdlePeriodState::IN_LONG_IDLE_PERIOD_WITH_MAX_DEADLINE) { | 234 IdlePeriodState::IN_LONG_IDLE_PERIOD_WITH_MAX_DEADLINE) { |
235 // If we are in a max deadline long idle period then start the next | 235 // If we are in a max deadline long idle period then start the next |
236 // idle period immediately. | 236 // idle period immediately. |
237 next_long_idle_period_delay = base::TimeDelta(); | 237 next_long_idle_period_delay = base::TimeDelta(); |
238 } else { | 238 } else { |
239 // Otherwise ensure that we kick the scheduler at the right time to | 239 // Otherwise ensure that we kick the scheduler at the right time to |
240 // initiate the next idle period. | 240 // initiate the next idle period. |
241 next_long_idle_period_delay = std::max( | 241 next_long_idle_period_delay = |
242 base::TimeDelta(), state_.idle_period_deadline() - helper_->Now()); | 242 std::max(base::TimeDelta(), state_.idle_period_deadline() - |
| 243 helper_->tick_clock()->NowTicks()); |
243 } | 244 } |
244 if (next_long_idle_period_delay == base::TimeDelta()) { | 245 if (next_long_idle_period_delay == base::TimeDelta()) { |
245 EnableLongIdlePeriod(); | 246 EnableLongIdlePeriod(); |
246 } else { | 247 } else { |
247 helper_->ControlTaskRunner()->PostDelayedTask( | 248 helper_->ControlTaskRunner()->PostDelayedTask( |
248 FROM_HERE, enable_next_long_idle_period_closure_.callback(), | 249 FROM_HERE, enable_next_long_idle_period_closure_.callback(), |
249 next_long_idle_period_delay); | 250 next_long_idle_period_delay); |
250 } | 251 } |
251 } | 252 } |
252 } | 253 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 | 352 |
352 helper_->CheckOnValidThread(); | 353 helper_->CheckOnValidThread(); |
353 if (new_state == idle_period_state_) { | 354 if (new_state == idle_period_state_) { |
354 DCHECK_EQ(new_deadline, idle_period_deadline_); | 355 DCHECK_EQ(new_deadline, idle_period_deadline_); |
355 return; | 356 return; |
356 } | 357 } |
357 | 358 |
358 bool is_tracing; | 359 bool is_tracing; |
359 TRACE_EVENT_CATEGORY_GROUP_ENABLED(tracing_category_, &is_tracing); | 360 TRACE_EVENT_CATEGORY_GROUP_ENABLED(tracing_category_, &is_tracing); |
360 if (is_tracing) { | 361 if (is_tracing) { |
361 base::TimeTicks now(optional_now.is_null() ? helper_->Now() : optional_now); | 362 base::TimeTicks now(optional_now.is_null() |
| 363 ? helper_->tick_clock()->NowTicks() |
| 364 : optional_now); |
362 base::TraceTicks trace_now = base::TraceTicks::Now(); | 365 base::TraceTicks trace_now = base::TraceTicks::Now(); |
363 idle_period_deadline_for_tracing_ = trace_now + (new_deadline - now); | 366 idle_period_deadline_for_tracing_ = trace_now + (new_deadline - now); |
364 TraceEventIdlePeriodStateChange( | 367 TraceEventIdlePeriodStateChange( |
365 new_state, running_idle_task_for_tracing_, | 368 new_state, running_idle_task_for_tracing_, |
366 idle_period_deadline_for_tracing_, trace_now); | 369 idle_period_deadline_for_tracing_, trace_now); |
367 } | 370 } |
368 | 371 |
369 idle_period_state_ = new_state; | 372 idle_period_state_ = new_state; |
370 idle_period_deadline_ = new_deadline; | 373 idle_period_deadline_ = new_deadline; |
371 | 374 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 return "in_long_idle_period_with_max_deadline"; | 476 return "in_long_idle_period_with_max_deadline"; |
474 case IdlePeriodState::IN_LONG_IDLE_PERIOD_PAUSED: | 477 case IdlePeriodState::IN_LONG_IDLE_PERIOD_PAUSED: |
475 return "in_long_idle_period_paused"; | 478 return "in_long_idle_period_paused"; |
476 default: | 479 default: |
477 NOTREACHED(); | 480 NOTREACHED(); |
478 return nullptr; | 481 return nullptr; |
479 } | 482 } |
480 } | 483 } |
481 | 484 |
482 } // namespace scheduler | 485 } // namespace scheduler |
OLD | NEW |