Chromium Code Reviews| 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 "platform/scheduler/child/idle_helper.h" | 5 #include "platform/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 "platform/scheduler/base/real_time_domain.h" | 10 #include "platform/scheduler/base/real_time_domain.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 weak_factory_(this) { | 40 weak_factory_(this) { |
| 41 weak_idle_helper_ptr_ = weak_factory_.GetWeakPtr(); | 41 weak_idle_helper_ptr_ = weak_factory_.GetWeakPtr(); |
| 42 enable_next_long_idle_period_closure_.Reset( | 42 enable_next_long_idle_period_closure_.Reset( |
| 43 base::Bind(&IdleHelper::EnableLongIdlePeriod, weak_idle_helper_ptr_)); | 43 base::Bind(&IdleHelper::EnableLongIdlePeriod, weak_idle_helper_ptr_)); |
| 44 on_idle_task_posted_closure_.Reset(base::Bind( | 44 on_idle_task_posted_closure_.Reset(base::Bind( |
| 45 &IdleHelper::OnIdleTaskPostedOnMainThread, weak_idle_helper_ptr_)); | 45 &IdleHelper::OnIdleTaskPostedOnMainThread, weak_idle_helper_ptr_)); |
| 46 | 46 |
| 47 idle_task_runner_ = make_scoped_refptr( | 47 idle_task_runner_ = make_scoped_refptr( |
| 48 new SingleThreadIdleTaskRunner(idle_queue_, this, tracing_category)); | 48 new SingleThreadIdleTaskRunner(idle_queue_, this, tracing_category)); |
| 49 | 49 |
| 50 idle_queue_->SetQueueEnabled(false); | 50 idle_queue_->InsertFence(TaskQueue::InsertFencePosition::BEGINNING_OF_TIME); |
|
alex clarke (OOO till 29th)
2016/11/25 16:20:49
Please add a comment explaining this blocks any id
altimin
2016/11/25 16:59:25
Done.
| |
| 51 idle_queue_->SetQueuePriority(TaskQueue::BEST_EFFORT_PRIORITY); | 51 idle_queue_->SetQueuePriority(TaskQueue::BEST_EFFORT_PRIORITY); |
| 52 | 52 |
| 53 helper_->AddTaskObserver(this); | 53 helper_->AddTaskObserver(this); |
| 54 } | 54 } |
| 55 | 55 |
| 56 IdleHelper::~IdleHelper() { | 56 IdleHelper::~IdleHelper() { |
| 57 Shutdown(); | 57 Shutdown(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void IdleHelper::Shutdown() { | 60 void IdleHelper::Shutdown() { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 if (idle_period_duration < | 177 if (idle_period_duration < |
| 178 base::TimeDelta::FromMilliseconds(kMinimumIdlePeriodDurationMillis)) { | 178 base::TimeDelta::FromMilliseconds(kMinimumIdlePeriodDurationMillis)) { |
| 179 TRACE_EVENT1(disabled_by_default_tracing_category_, | 179 TRACE_EVENT1(disabled_by_default_tracing_category_, |
| 180 "NotStartingIdlePeriodBecauseDeadlineIsTooClose", | 180 "NotStartingIdlePeriodBecauseDeadlineIsTooClose", |
| 181 "idle_period_duration_ms", | 181 "idle_period_duration_ms", |
| 182 idle_period_duration.InMillisecondsF()); | 182 idle_period_duration.InMillisecondsF()); |
| 183 return; | 183 return; |
| 184 } | 184 } |
| 185 | 185 |
| 186 TRACE_EVENT0(disabled_by_default_tracing_category_, "StartIdlePeriod"); | 186 TRACE_EVENT0(disabled_by_default_tracing_category_, "StartIdlePeriod"); |
| 187 idle_queue_->SetQueueEnabled(true); | |
| 188 // Use a fence to make sure any idle tasks posted after this point do not run | 187 // Use a fence to make sure any idle tasks posted after this point do not run |
| 189 // until the next idle period. | 188 // until the next idle period and unblock existing tasks. |
| 190 idle_queue_->InsertFence(); | 189 idle_queue_->InsertFence(TaskQueue::InsertFencePosition::NOW); |
| 191 | 190 |
| 192 state_.UpdateState(new_state, idle_period_deadline, now); | 191 state_.UpdateState(new_state, idle_period_deadline, now); |
| 193 } | 192 } |
| 194 | 193 |
| 195 void IdleHelper::EndIdlePeriod() { | 194 void IdleHelper::EndIdlePeriod() { |
| 196 if (is_shutdown_) | 195 if (is_shutdown_) |
| 197 return; | 196 return; |
| 198 | 197 |
| 199 helper_->CheckOnValidThread(); | 198 helper_->CheckOnValidThread(); |
| 200 TRACE_EVENT0(disabled_by_default_tracing_category_, "EndIdlePeriod"); | 199 TRACE_EVENT0(disabled_by_default_tracing_category_, "EndIdlePeriod"); |
| 201 | 200 |
| 202 enable_next_long_idle_period_closure_.Cancel(); | 201 enable_next_long_idle_period_closure_.Cancel(); |
| 203 on_idle_task_posted_closure_.Cancel(); | 202 on_idle_task_posted_closure_.Cancel(); |
| 204 | 203 |
| 205 // If we weren't already within an idle period then early-out. | 204 // If we weren't already within an idle period then early-out. |
| 206 if (!IsInIdlePeriod(state_.idle_period_state())) | 205 if (!IsInIdlePeriod(state_.idle_period_state())) |
| 207 return; | 206 return; |
| 208 | 207 |
| 209 idle_queue_->SetQueueEnabled(false); | 208 idle_queue_->InsertFence(TaskQueue::InsertFencePosition::BEGINNING_OF_TIME); |
|
alex clarke (OOO till 29th)
2016/11/25 16:20:49
Please add a comment explaining this blocks any id
altimin
2016/11/25 16:59:26
Done.
| |
| 210 state_.UpdateState(IdlePeriodState::NOT_IN_IDLE_PERIOD, base::TimeTicks(), | 209 state_.UpdateState(IdlePeriodState::NOT_IN_IDLE_PERIOD, base::TimeTicks(), |
| 211 base::TimeTicks()); | 210 base::TimeTicks()); |
| 212 } | 211 } |
| 213 | 212 |
| 214 void IdleHelper::WillProcessTask(const base::PendingTask& pending_task) { | 213 void IdleHelper::WillProcessTask(const base::PendingTask& pending_task) { |
| 215 DCHECK(!is_shutdown_); | 214 DCHECK(!is_shutdown_); |
| 216 } | 215 } |
| 217 | 216 |
| 218 void IdleHelper::DidProcessTask(const base::PendingTask& pending_task) { | 217 void IdleHelper::DidProcessTask(const base::PendingTask& pending_task) { |
| 219 helper_->CheckOnValidThread(); | 218 helper_->CheckOnValidThread(); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 case IdlePeriodState::IN_LONG_IDLE_PERIOD_PAUSED: | 492 case IdlePeriodState::IN_LONG_IDLE_PERIOD_PAUSED: |
| 494 return "in_long_idle_period_paused"; | 493 return "in_long_idle_period_paused"; |
| 495 default: | 494 default: |
| 496 NOTREACHED(); | 495 NOTREACHED(); |
| 497 return nullptr; | 496 return nullptr; |
| 498 } | 497 } |
| 499 } | 498 } |
| 500 | 499 |
| 501 } // namespace scheduler | 500 } // namespace scheduler |
| 502 } // namespace blink | 501 } // namespace blink |
| OLD | NEW |