Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(677)

Side by Side Diff: content/renderer/scheduler/renderer_scheduler_impl.cc

Issue 994833003: Prevent multiple pending UpdatePolicy tasks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweak Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/renderer/scheduler/renderer_scheduler_impl.h" 5 #include "content/renderer/scheduler/renderer_scheduler_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "base/trace_event/trace_event_argument.h" 10 #include "base/trace_event/trace_event_argument.h"
(...skipping 13 matching lines...) Expand all
24 control_task_runner_( 24 control_task_runner_(
25 task_queue_manager_->TaskRunnerForQueue(CONTROL_TASK_QUEUE)), 25 task_queue_manager_->TaskRunnerForQueue(CONTROL_TASK_QUEUE)),
26 control_task_after_wakeup_runner_(task_queue_manager_->TaskRunnerForQueue( 26 control_task_after_wakeup_runner_(task_queue_manager_->TaskRunnerForQueue(
27 CONTROL_TASK_AFTER_WAKEUP_QUEUE)), 27 CONTROL_TASK_AFTER_WAKEUP_QUEUE)),
28 default_task_runner_( 28 default_task_runner_(
29 task_queue_manager_->TaskRunnerForQueue(DEFAULT_TASK_QUEUE)), 29 task_queue_manager_->TaskRunnerForQueue(DEFAULT_TASK_QUEUE)),
30 compositor_task_runner_( 30 compositor_task_runner_(
31 task_queue_manager_->TaskRunnerForQueue(COMPOSITOR_TASK_QUEUE)), 31 task_queue_manager_->TaskRunnerForQueue(COMPOSITOR_TASK_QUEUE)),
32 loading_task_runner_( 32 loading_task_runner_(
33 task_queue_manager_->TaskRunnerForQueue(LOADING_TASK_QUEUE)), 33 task_queue_manager_->TaskRunnerForQueue(LOADING_TASK_QUEUE)),
34 pending_non_delayed_update_policy_(false),
34 current_policy_(Policy::NORMAL), 35 current_policy_(Policy::NORMAL),
35 last_input_type_(blink::WebInputEvent::Undefined), 36 last_input_type_(blink::WebInputEvent::Undefined),
36 input_stream_state_(InputStreamState::INACTIVE), 37 input_stream_state_(InputStreamState::INACTIVE),
37 policy_may_need_update_(&incoming_signals_lock_), 38 policy_may_need_update_(&incoming_signals_lock_),
38 weak_factory_(this) { 39 weak_factory_(this) {
39 weak_renderer_scheduler_ptr_ = weak_factory_.GetWeakPtr(); 40 weak_renderer_scheduler_ptr_ = weak_factory_.GetWeakPtr();
40 update_policy_closure_ = base::Bind(&RendererSchedulerImpl::UpdatePolicy, 41 update_policy_closure_ = base::Bind(&RendererSchedulerImpl::UpdatePolicy,
41 weak_renderer_scheduler_ptr_); 42 weak_renderer_scheduler_ptr_, true);
42 end_idle_period_closure_.Reset(base::Bind( 43 end_idle_period_closure_.Reset(base::Bind(
43 &RendererSchedulerImpl::EndIdlePeriod, weak_renderer_scheduler_ptr_)); 44 &RendererSchedulerImpl::EndIdlePeriod, weak_renderer_scheduler_ptr_));
45 delayed_update_policy_closure_.Reset(
46 base::Bind(&RendererSchedulerImpl::UpdatePolicy,
47 weak_renderer_scheduler_ptr_, false));
44 idle_task_runner_ = make_scoped_refptr(new SingleThreadIdleTaskRunner( 48 idle_task_runner_ = make_scoped_refptr(new SingleThreadIdleTaskRunner(
45 task_queue_manager_->TaskRunnerForQueue(IDLE_TASK_QUEUE), 49 task_queue_manager_->TaskRunnerForQueue(IDLE_TASK_QUEUE),
46 control_task_after_wakeup_runner_, 50 control_task_after_wakeup_runner_,
47 base::Bind(&RendererSchedulerImpl::CurrentIdleTaskDeadlineCallback, 51 base::Bind(&RendererSchedulerImpl::CurrentIdleTaskDeadlineCallback,
48 weak_renderer_scheduler_ptr_))); 52 weak_renderer_scheduler_ptr_)));
49 53
50 renderer_task_queue_selector_->SetQueuePriority( 54 renderer_task_queue_selector_->SetQueuePriority(
51 CONTROL_TASK_QUEUE, RendererTaskQueueSelector::CONTROL_PRIORITY); 55 CONTROL_TASK_QUEUE, RendererTaskQueueSelector::CONTROL_PRIORITY);
52 56
53 renderer_task_queue_selector_->SetQueuePriority( 57 renderer_task_queue_selector_->SetQueuePriority(
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 blink::WebInputEvent::Type type) { 183 blink::WebInputEvent::Type type) {
180 base::AutoLock lock(incoming_signals_lock_); 184 base::AutoLock lock(incoming_signals_lock_);
181 185
182 InputStreamState new_input_stream_state = 186 InputStreamState new_input_stream_state =
183 ComputeNewInputStreamState(input_stream_state_, type, last_input_type_); 187 ComputeNewInputStreamState(input_stream_state_, type, last_input_type_);
184 188
185 if (input_stream_state_ != new_input_stream_state) { 189 if (input_stream_state_ != new_input_stream_state) {
186 // Update scheduler policy if we should start a new policy mode. 190 // Update scheduler policy if we should start a new policy mode.
187 input_stream_state_ = new_input_stream_state; 191 input_stream_state_ = new_input_stream_state;
188 policy_may_need_update_.SetWhileLocked(true); 192 policy_may_need_update_.SetWhileLocked(true);
189 PostUpdatePolicyOnControlRunner(base::TimeDelta()); 193 PostUpdatePolicyOnControlRunnerLocked(base::TimeDelta());
190 } 194 }
191 last_input_receipt_time_on_compositor_ = Now(); 195 last_input_receipt_time_on_compositor_ = Now();
192 // Clear the last known input processing time so that we know an input event 196 // Clear the last known input processing time so that we know an input event
193 // is still queued up. This timestamp will be updated the next time the 197 // is still queued up. This timestamp will be updated the next time the
194 // compositor commits or becomes quiescent. Note that this function is always 198 // compositor commits or becomes quiescent. Note that this function is always
195 // called before the input event is processed either on the compositor or 199 // called before the input event is processed either on the compositor or
196 // main threads. 200 // main threads.
197 last_input_process_time_on_main_ = base::TimeTicks(); 201 last_input_process_time_on_main_ = base::TimeTicks();
198 last_input_type_ = type; 202 last_input_type_ = type;
199 } 203 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 } 261 }
258 262
259 RendererSchedulerImpl::Policy RendererSchedulerImpl::SchedulerPolicy() const { 263 RendererSchedulerImpl::Policy RendererSchedulerImpl::SchedulerPolicy() const {
260 DCHECK(main_thread_checker_.CalledOnValidThread()); 264 DCHECK(main_thread_checker_.CalledOnValidThread());
261 return current_policy_; 265 return current_policy_;
262 } 266 }
263 267
264 void RendererSchedulerImpl::MaybeUpdatePolicy() { 268 void RendererSchedulerImpl::MaybeUpdatePolicy() {
265 DCHECK(main_thread_checker_.CalledOnValidThread()); 269 DCHECK(main_thread_checker_.CalledOnValidThread());
266 if (policy_may_need_update_.IsSet()) { 270 if (policy_may_need_update_.IsSet()) {
267 UpdatePolicy(); 271 UpdatePolicy(false);
268 } 272 }
269 } 273 }
270 274
271 void RendererSchedulerImpl::PostUpdatePolicyOnControlRunner( 275 void RendererSchedulerImpl::PostUpdatePolicyOnControlRunnerLocked(
272 base::TimeDelta delay) { 276 base::TimeDelta delay) {
273 control_task_runner_->PostDelayedTask( 277 incoming_signals_lock_.AssertAcquired();
274 FROM_HERE, update_policy_closure_, delay); 278 if (delay > base::TimeDelta()) {
279 // Only allow one pending delayed UpdatePolicy task.
280 delayed_update_policy_closure_.Cancel();
281 control_task_runner_->PostDelayedTask(
282 FROM_HERE, delayed_update_policy_closure_.callback(), delay);
283 } else {
284 // Only allow one pending non-delayed UpdatePolicy task.
285 if (!pending_non_delayed_update_policy_) {
286 pending_non_delayed_update_policy_ = true;
287 control_task_runner_->PostDelayedTask(FROM_HERE, update_policy_closure_,
288 base::TimeDelta());
289 }
290 }
275 } 291 }
276 292
277 void RendererSchedulerImpl::UpdatePolicy() { 293 void RendererSchedulerImpl::UpdatePolicy(
294 bool clear_pending_non_delayed_update_policy) {
278 DCHECK(main_thread_checker_.CalledOnValidThread()); 295 DCHECK(main_thread_checker_.CalledOnValidThread());
279 if (!task_queue_manager_) 296 if (!task_queue_manager_)
280 return; 297 return;
281 298
282 base::AutoLock lock(incoming_signals_lock_); 299 base::AutoLock lock(incoming_signals_lock_);
283 base::TimeTicks now; 300 base::TimeTicks now;
284 policy_may_need_update_.SetWhileLocked(false); 301 policy_may_need_update_.SetWhileLocked(false);
302 if (clear_pending_non_delayed_update_policy)
303 pending_non_delayed_update_policy_ = false;
rmcilroy 2015/03/10 16:08:39 I don't think the pending_non_delayed_update_polic
Sami 2015/03/10 16:19:38 Yeah, I'm all for simplicity too. I was thinking w
alex clarke (OOO till 29th) 2015/03/10 16:21:41 Currently they only get sent when the input_stream
285 304
286 base::TimeDelta new_policy_duration; 305 base::TimeDelta new_policy_duration;
287 Policy new_policy = ComputeNewPolicy(&new_policy_duration); 306 Policy new_policy = ComputeNewPolicy(&new_policy_duration);
288 if (new_policy_duration > base::TimeDelta()) 307 if (new_policy_duration > base::TimeDelta())
289 PostUpdatePolicyOnControlRunner(new_policy_duration); 308 PostUpdatePolicyOnControlRunnerLocked(new_policy_duration);
290 309
291 if (new_policy == current_policy_) 310 if (new_policy == current_policy_)
292 return; 311 return;
293 312
294 switch (new_policy) { 313 switch (new_policy) {
295 case Policy::COMPOSITOR_PRIORITY: 314 case Policy::COMPOSITOR_PRIORITY:
296 renderer_task_queue_selector_->SetQueuePriority( 315 renderer_task_queue_selector_->SetQueuePriority(
297 COMPOSITOR_TASK_QUEUE, RendererTaskQueueSelector::HIGH_PRIORITY); 316 COMPOSITOR_TASK_QUEUE, RendererTaskQueueSelector::HIGH_PRIORITY);
298 // TODO(scheduler-dev): Add a task priority between HIGH and BEST_EFFORT 317 // TODO(scheduler-dev): Add a task priority between HIGH and BEST_EFFORT
299 // that still has some guarantee of running. 318 // that still has some guarantee of running.
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 } 574 }
556 575
557 void RendererSchedulerImpl::RemoveTaskObserver( 576 void RendererSchedulerImpl::RemoveTaskObserver(
558 base::MessageLoop::TaskObserver* task_observer) { 577 base::MessageLoop::TaskObserver* task_observer) {
559 DCHECK(main_thread_checker_.CalledOnValidThread()); 578 DCHECK(main_thread_checker_.CalledOnValidThread());
560 if (task_queue_manager_) 579 if (task_queue_manager_)
561 task_queue_manager_->RemoveTaskObserver(task_observer); 580 task_queue_manager_->RemoveTaskObserver(task_observer);
562 } 581 }
563 582
564 } // namespace content 583 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698