| 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/real_time_domain.h" | |
| 11 #include "components/scheduler/base/task_queue.h" | 10 #include "components/scheduler/base/task_queue.h" |
| 12 #include "components/scheduler/base/task_queue_manager.h" | 11 #include "components/scheduler/base/task_queue_manager.h" |
| 13 #include "components/scheduler/child/scheduler_helper.h" | 12 #include "components/scheduler/child/scheduler_helper.h" |
| 14 #include "components/scheduler/child/scheduler_tqm_delegate.h" | 13 #include "components/scheduler/child/scheduler_tqm_delegate.h" |
| 15 | 14 |
| 16 namespace scheduler { | 15 namespace scheduler { |
| 17 | 16 |
| 18 IdleHelper::IdleHelper( | 17 IdleHelper::IdleHelper( |
| 19 SchedulerHelper* helper, | 18 SchedulerHelper* helper, |
| 20 Delegate* delegate, | 19 Delegate* delegate, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 IdleHelper::IdlePeriodState IdleHelper::ComputeNewLongIdlePeriodState( | 69 IdleHelper::IdlePeriodState IdleHelper::ComputeNewLongIdlePeriodState( |
| 71 const base::TimeTicks now, | 70 const base::TimeTicks now, |
| 72 base::TimeDelta* next_long_idle_period_delay_out) { | 71 base::TimeDelta* next_long_idle_period_delay_out) { |
| 73 helper_->CheckOnValidThread(); | 72 helper_->CheckOnValidThread(); |
| 74 | 73 |
| 75 if (!delegate_->CanEnterLongIdlePeriod(now, | 74 if (!delegate_->CanEnterLongIdlePeriod(now, |
| 76 next_long_idle_period_delay_out)) { | 75 next_long_idle_period_delay_out)) { |
| 77 return IdlePeriodState::NOT_IN_IDLE_PERIOD; | 76 return IdlePeriodState::NOT_IN_IDLE_PERIOD; |
| 78 } | 77 } |
| 79 | 78 |
| 80 base::TimeTicks next_pending_delayed_task; | 79 base::TimeTicks next_pending_delayed_task = |
| 80 helper_->NextPendingDelayedTaskRunTime(); |
| 81 base::TimeDelta max_long_idle_period_duration = | 81 base::TimeDelta max_long_idle_period_duration = |
| 82 base::TimeDelta::FromMilliseconds(kMaximumIdlePeriodMillis); | 82 base::TimeDelta::FromMilliseconds(kMaximumIdlePeriodMillis); |
| 83 base::TimeDelta long_idle_period_duration; | 83 base::TimeDelta long_idle_period_duration; |
| 84 if (helper_->real_time_domain()->NextScheduledRunTime( | 84 if (next_pending_delayed_task.is_null()) { |
| 85 &next_pending_delayed_task)) { | 85 long_idle_period_duration = max_long_idle_period_duration; |
| 86 } else { |
| 86 // Limit the idle period duration to be before the next pending task. | 87 // Limit the idle period duration to be before the next pending task. |
| 87 long_idle_period_duration = std::min(next_pending_delayed_task - now, | 88 long_idle_period_duration = std::min(next_pending_delayed_task - now, |
| 88 max_long_idle_period_duration); | 89 max_long_idle_period_duration); |
| 89 } else { | |
| 90 long_idle_period_duration = max_long_idle_period_duration; | |
| 91 } | 90 } |
| 92 | 91 |
| 93 if (long_idle_period_duration >= | 92 if (long_idle_period_duration >= |
| 94 base::TimeDelta::FromMilliseconds(kMinimumIdlePeriodDurationMillis)) { | 93 base::TimeDelta::FromMilliseconds(kMinimumIdlePeriodDurationMillis)) { |
| 95 *next_long_idle_period_delay_out = long_idle_period_duration; | 94 *next_long_idle_period_delay_out = long_idle_period_duration; |
| 96 if (idle_queue_->IsQueueEmpty()) { | 95 if (idle_queue_->IsQueueEmpty()) { |
| 97 return IdlePeriodState::IN_LONG_IDLE_PERIOD_PAUSED; | 96 return IdlePeriodState::IN_LONG_IDLE_PERIOD_PAUSED; |
| 98 } else if (long_idle_period_duration == max_long_idle_period_duration) { | 97 } else if (long_idle_period_duration == max_long_idle_period_duration) { |
| 99 return IdlePeriodState::IN_LONG_IDLE_PERIOD_WITH_MAX_DEADLINE; | 98 return IdlePeriodState::IN_LONG_IDLE_PERIOD_WITH_MAX_DEADLINE; |
| 100 } else { | 99 } else { |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 return "in_long_idle_period_with_max_deadline"; | 474 return "in_long_idle_period_with_max_deadline"; |
| 476 case IdlePeriodState::IN_LONG_IDLE_PERIOD_PAUSED: | 475 case IdlePeriodState::IN_LONG_IDLE_PERIOD_PAUSED: |
| 477 return "in_long_idle_period_paused"; | 476 return "in_long_idle_period_paused"; |
| 478 default: | 477 default: |
| 479 NOTREACHED(); | 478 NOTREACHED(); |
| 480 return nullptr; | 479 return nullptr; |
| 481 } | 480 } |
| 482 } | 481 } |
| 483 | 482 |
| 484 } // namespace scheduler | 483 } // namespace scheduler |
| OLD | NEW |