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