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

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

Issue 1895773002: Move responsiblity of tab suspending from renderer to TabManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix time Created 4 years, 8 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 "components/scheduler/renderer/renderer_scheduler_impl.h" 5 #include "components/scheduler/renderer/renderer_scheduler_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/stack_trace.h" 8 #include "base/debug/stack_trace.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 main_thread_only_(compositor_task_runner_, 55 main_thread_only_(compositor_task_runner_,
56 helper_.scheduler_tqm_delegate().get()), 56 helper_.scheduler_tqm_delegate().get()),
57 policy_may_need_update_(&any_thread_lock_), 57 policy_may_need_update_(&any_thread_lock_),
58 weak_factory_(this) { 58 weak_factory_(this) {
59 throttling_helper_.reset(new ThrottlingHelper(this, "renderer.scheduler")); 59 throttling_helper_.reset(new ThrottlingHelper(this, "renderer.scheduler"));
60 update_policy_closure_ = base::Bind(&RendererSchedulerImpl::UpdatePolicy, 60 update_policy_closure_ = base::Bind(&RendererSchedulerImpl::UpdatePolicy,
61 weak_factory_.GetWeakPtr()); 61 weak_factory_.GetWeakPtr());
62 end_renderer_hidden_idle_period_closure_.Reset(base::Bind( 62 end_renderer_hidden_idle_period_closure_.Reset(base::Bind(
63 &RendererSchedulerImpl::EndIdlePeriod, weak_factory_.GetWeakPtr())); 63 &RendererSchedulerImpl::EndIdlePeriod, weak_factory_.GetWeakPtr()));
64 64
65 suspend_timers_when_backgrounded_closure_.Reset(
66 base::Bind(&RendererSchedulerImpl::SuspendTimerQueueWhenBackgrounded,
67 weak_factory_.GetWeakPtr()));
68
69 default_loading_task_runner_ = NewLoadingTaskRunner("default_loading_tq"); 65 default_loading_task_runner_ = NewLoadingTaskRunner("default_loading_tq");
70 default_timer_task_runner_ = NewTimerTaskRunner("default_timer_tq"); 66 default_timer_task_runner_ = NewTimerTaskRunner("default_timer_tq");
71 67
72 TRACE_EVENT_OBJECT_CREATED_WITH_ID( 68 TRACE_EVENT_OBJECT_CREATED_WITH_ID(
73 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "RendererScheduler", 69 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "RendererScheduler",
74 this); 70 this);
75 71
76 helper_.SetObserver(this); 72 helper_.SetObserver(this);
77 } 73 }
78 74
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 MainThreadOnly().has_visible_render_widget_with_touch_handler) 340 MainThreadOnly().has_visible_render_widget_with_touch_handler)
345 return; 341 return;
346 342
347 MainThreadOnly().has_visible_render_widget_with_touch_handler = 343 MainThreadOnly().has_visible_render_widget_with_touch_handler =
348 has_visible_render_widget_with_touch_handler; 344 has_visible_render_widget_with_touch_handler;
349 345
350 base::AutoLock lock(any_thread_lock_); 346 base::AutoLock lock(any_thread_lock_);
351 UpdatePolicyLocked(UpdateType::FORCE_UPDATE); 347 UpdatePolicyLocked(UpdateType::FORCE_UPDATE);
352 } 348 }
353 349
350 // TODO(hajimehoshi): This does nothing for now. Remove this handler.
354 void RendererSchedulerImpl::OnRendererBackgrounded() { 351 void RendererSchedulerImpl::OnRendererBackgrounded() {
355 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), 352 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"),
356 "RendererSchedulerImpl::OnRendererBackgrounded"); 353 "RendererSchedulerImpl::OnRendererBackgrounded");
357 helper_.CheckOnValidThread(); 354 helper_.CheckOnValidThread();
358 if (helper_.IsShutdown() || MainThreadOnly().renderer_backgrounded) 355 if (helper_.IsShutdown() || MainThreadOnly().renderer_backgrounded)
359 return; 356 return;
360 357
361 MainThreadOnly().renderer_backgrounded = true; 358 MainThreadOnly().renderer_backgrounded = true;
362 if (!MainThreadOnly().timer_queue_suspension_when_backgrounded_enabled)
363 return;
364
365 suspend_timers_when_backgrounded_closure_.Cancel();
366 base::TimeDelta suspend_timers_when_backgrounded_delay =
367 base::TimeDelta::FromMilliseconds(
368 kSuspendTimersWhenBackgroundedDelayMillis);
369 control_task_runner_->PostDelayedTask(
370 FROM_HERE, suspend_timers_when_backgrounded_closure_.callback(),
371 suspend_timers_when_backgrounded_delay);
372 } 359 }
373 360
374 void RendererSchedulerImpl::OnRendererForegrounded() { 361 void RendererSchedulerImpl::OnRendererForegrounded() {
375 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), 362 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"),
376 "RendererSchedulerImpl::OnRendererForegrounded"); 363 "RendererSchedulerImpl::OnRendererForegrounded");
377 helper_.CheckOnValidThread(); 364 helper_.CheckOnValidThread();
378 if (helper_.IsShutdown() || !MainThreadOnly().renderer_backgrounded) 365 if (helper_.IsShutdown() || !MainThreadOnly().renderer_backgrounded)
379 return; 366 return;
380 367
381 MainThreadOnly().renderer_backgrounded = false; 368 MainThreadOnly().renderer_backgrounded = false;
382 suspend_timers_when_backgrounded_closure_.Cancel();
383 ResumeTimerQueueWhenForegrounded(); 369 ResumeTimerQueueWhenForegrounded();
384 } 370 }
385 371
372 void RendererSchedulerImpl::OnRendererSuspend() {
373 helper_.CheckOnValidThread();
374 if (helper_.IsShutdown() || !MainThreadOnly().renderer_backgrounded)
375 return;
376 if (!MainThreadOnly().timer_queue_suspension_when_backgrounded_enabled)
377 return;
378 SuspendTimerQueueWhenBackgrounded();
379 }
380
386 void RendererSchedulerImpl::EndIdlePeriod() { 381 void RendererSchedulerImpl::EndIdlePeriod() {
387 if (MainThreadOnly().in_idle_period_for_testing) 382 if (MainThreadOnly().in_idle_period_for_testing)
388 return; 383 return;
389 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), 384 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"),
390 "RendererSchedulerImpl::EndIdlePeriod"); 385 "RendererSchedulerImpl::EndIdlePeriod");
391 helper_.CheckOnValidThread(); 386 helper_.CheckOnValidThread();
392 idle_helper_.EndIdlePeriod(); 387 idle_helper_.EndIdlePeriod();
393 } 388 }
394 389
395 void RendererSchedulerImpl::EndIdlePeriodForTesting( 390 void RendererSchedulerImpl::EndIdlePeriodForTesting(
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 } 1239 }
1245 MainThreadOnly().have_reported_blocking_intervention_since_navigation = 1240 MainThreadOnly().have_reported_blocking_intervention_since_navigation =
1246 true; 1241 true;
1247 BroadcastConsoleWarning( 1242 BroadcastConsoleWarning(
1248 "Deferred long-running timer task(s) to improve scrolling smoothness. " 1243 "Deferred long-running timer task(s) to improve scrolling smoothness. "
1249 "See crbug.com/574343."); 1244 "See crbug.com/574343.");
1250 } 1245 }
1251 } 1246 }
1252 1247
1253 } // namespace scheduler 1248 } // namespace scheduler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698