| 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/child/scheduler_helper.h" | 12 #include "components/scheduler/child/scheduler_helper.h" |
| 13 #include "components/scheduler/child/scheduler_tqm_delegate.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, |
| 22 base::TimeDelta required_quiescence_duration_before_long_idle_period) | 23 base::TimeDelta required_quiescence_duration_before_long_idle_period) |
| (...skipping 109 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_->scheduler_tqm_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_->scheduler_tqm_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 14 matching lines...) Expand all Loading... |
| 231 // If there is still idle work to do then just start the next idle period. | 233 // If there is still idle work to do then just start the next idle period. |
| 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 = std::max( |
| 242 std::max(base::TimeDelta(), state_.idle_period_deadline() - | 244 base::TimeDelta(), state_.idle_period_deadline() - |
| 243 helper_->tick_clock()->NowTicks()); | 245 helper_->scheduler_tqm_delegate()->NowTicks()); |
| 244 } | 246 } |
| 245 if (next_long_idle_period_delay == base::TimeDelta()) { | 247 if (next_long_idle_period_delay == base::TimeDelta()) { |
| 246 EnableLongIdlePeriod(); | 248 EnableLongIdlePeriod(); |
| 247 } else { | 249 } else { |
| 248 helper_->ControlTaskRunner()->PostDelayedTask( | 250 helper_->ControlTaskRunner()->PostDelayedTask( |
| 249 FROM_HERE, enable_next_long_idle_period_closure_.callback(), | 251 FROM_HERE, enable_next_long_idle_period_closure_.callback(), |
| 250 next_long_idle_period_delay); | 252 next_long_idle_period_delay); |
| 251 } | 253 } |
| 252 } | 254 } |
| 253 } | 255 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 helper_->CheckOnValidThread(); | 355 helper_->CheckOnValidThread(); |
| 354 if (new_state == idle_period_state_) { | 356 if (new_state == idle_period_state_) { |
| 355 DCHECK_EQ(new_deadline, idle_period_deadline_); | 357 DCHECK_EQ(new_deadline, idle_period_deadline_); |
| 356 return; | 358 return; |
| 357 } | 359 } |
| 358 | 360 |
| 359 bool is_tracing; | 361 bool is_tracing; |
| 360 TRACE_EVENT_CATEGORY_GROUP_ENABLED(tracing_category_, &is_tracing); | 362 TRACE_EVENT_CATEGORY_GROUP_ENABLED(tracing_category_, &is_tracing); |
| 361 if (is_tracing) { | 363 if (is_tracing) { |
| 362 base::TimeTicks now(optional_now.is_null() | 364 base::TimeTicks now(optional_now.is_null() |
| 363 ? helper_->tick_clock()->NowTicks() | 365 ? helper_->scheduler_tqm_delegate()->NowTicks() |
| 364 : optional_now); | 366 : optional_now); |
| 365 TraceEventIdlePeriodStateChange( | 367 TraceEventIdlePeriodStateChange( |
| 366 new_state, running_idle_task_for_tracing_, idle_period_deadline_, now); | 368 new_state, running_idle_task_for_tracing_, idle_period_deadline_, now); |
| 367 } | 369 } |
| 368 | 370 |
| 369 idle_period_state_ = new_state; | 371 idle_period_state_ = new_state; |
| 370 idle_period_deadline_ = new_deadline; | 372 idle_period_deadline_ = new_deadline; |
| 371 | 373 |
| 372 // Inform the delegate if we are starting or ending an idle period. | 374 // Inform the delegate if we are starting or ending an idle period. |
| 373 if (IsInIdlePeriod(new_state) && !IsInIdlePeriod(old_idle_period_state)) { | 375 if (IsInIdlePeriod(new_state) && !IsInIdlePeriod(old_idle_period_state)) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 return "in_long_idle_period_with_max_deadline"; | 474 return "in_long_idle_period_with_max_deadline"; |
| 473 case IdlePeriodState::IN_LONG_IDLE_PERIOD_PAUSED: | 475 case IdlePeriodState::IN_LONG_IDLE_PERIOD_PAUSED: |
| 474 return "in_long_idle_period_paused"; | 476 return "in_long_idle_period_paused"; |
| 475 default: | 477 default: |
| 476 NOTREACHED(); | 478 NOTREACHED(); |
| 477 return nullptr; | 479 return nullptr; |
| 478 } | 480 } |
| 479 } | 481 } |
| 480 | 482 |
| 481 } // namespace scheduler | 483 } // namespace scheduler |
| OLD | NEW |