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

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

Issue 1368643002: Add a signal to the scheduler that a navigation is expected (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Requested changes Created 5 years, 3 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/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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 current_use_case(UseCase::NONE), 104 current_use_case(UseCase::NONE),
105 timer_queue_suspend_count(0), 105 timer_queue_suspend_count(0),
106 renderer_hidden(false), 106 renderer_hidden(false),
107 renderer_backgrounded(false), 107 renderer_backgrounded(false),
108 timer_queue_suspension_when_backgrounded_enabled(false), 108 timer_queue_suspension_when_backgrounded_enabled(false),
109 timer_queue_suspended_when_backgrounded(false), 109 timer_queue_suspended_when_backgrounded(false),
110 was_shutdown(false), 110 was_shutdown(false),
111 loading_tasks_seem_expensive(false), 111 loading_tasks_seem_expensive(false),
112 timer_tasks_seem_expensive(false), 112 timer_tasks_seem_expensive(false),
113 touchstart_expected_soon(false), 113 touchstart_expected_soon(false),
114 have_seen_a_begin_main_frame(false) {} 114 have_seen_a_begin_main_frame(false),
115 navigation_expected(false) {}
115 116
116 RendererSchedulerImpl::MainThreadOnly::~MainThreadOnly() {} 117 RendererSchedulerImpl::MainThreadOnly::~MainThreadOnly() {}
117 118
118 RendererSchedulerImpl::AnyThread::AnyThread() 119 RendererSchedulerImpl::AnyThread::AnyThread()
119 : awaiting_touch_start_response(false), 120 : awaiting_touch_start_response(false),
120 in_idle_period(false), 121 in_idle_period(false),
121 begin_main_frame_on_critical_path(false) {} 122 begin_main_frame_on_critical_path(false) {}
122 123
123 RendererSchedulerImpl::CompositorThreadOnly::CompositorThreadOnly() 124 RendererSchedulerImpl::CompositorThreadOnly::CompositorThreadOnly()
124 : last_input_type(blink::WebInputEvent::Undefined) {} 125 : last_input_type(blink::WebInputEvent::Undefined) {}
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 break; 587 break;
587 588
588 default: 589 default:
589 NOTREACHED(); 590 NOTREACHED();
590 } 591 }
591 592
592 // Don't block expensive tasks unless we have actually seen something. 593 // Don't block expensive tasks unless we have actually seen something.
593 if (!MainThreadOnly().have_seen_a_begin_main_frame) 594 if (!MainThreadOnly().have_seen_a_begin_main_frame)
594 block_expensive_tasks = false; 595 block_expensive_tasks = false;
595 596
597 // Don't block expensive tasks if we are expecting a navigation.
598 if (MainThreadOnly().navigation_expected)
599 block_expensive_tasks = false;
600
596 if (block_expensive_tasks && loading_tasks_seem_expensive) 601 if (block_expensive_tasks && loading_tasks_seem_expensive)
597 new_policy.loading_queue_priority = TaskQueue::DISABLED_PRIORITY; 602 new_policy.loading_queue_priority = TaskQueue::DISABLED_PRIORITY;
598 603
599 if ((block_expensive_tasks && timer_tasks_seem_expensive) || 604 if ((block_expensive_tasks && timer_tasks_seem_expensive) ||
600 MainThreadOnly().timer_queue_suspend_count != 0 || 605 MainThreadOnly().timer_queue_suspend_count != 0 ||
601 MainThreadOnly().timer_queue_suspended_when_backgrounded) { 606 MainThreadOnly().timer_queue_suspended_when_backgrounded) {
602 new_policy.timer_queue_priority = TaskQueue::DISABLED_PRIORITY; 607 new_policy.timer_queue_priority = TaskQueue::DISABLED_PRIORITY;
603 } 608 }
604 609
605 // Tracing is done before the early out check, because it's quite possible we 610 // Tracing is done before the early out check, because it's quite possible we
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 MainThreadOnly().renderer_backgrounded); 767 MainThreadOnly().renderer_backgrounded);
763 state->SetBoolean("timer_queue_suspended_when_backgrounded", 768 state->SetBoolean("timer_queue_suspended_when_backgrounded",
764 MainThreadOnly().timer_queue_suspended_when_backgrounded); 769 MainThreadOnly().timer_queue_suspended_when_backgrounded);
765 state->SetInteger("timer_queue_suspend_count", 770 state->SetInteger("timer_queue_suspend_count",
766 MainThreadOnly().timer_queue_suspend_count); 771 MainThreadOnly().timer_queue_suspend_count);
767 state->SetDouble("now", (optional_now - base::TimeTicks()).InMillisecondsF()); 772 state->SetDouble("now", (optional_now - base::TimeTicks()).InMillisecondsF());
768 state->SetDouble( 773 state->SetDouble(
769 "rails_loading_priority_deadline", 774 "rails_loading_priority_deadline",
770 (AnyThread().rails_loading_priority_deadline - base::TimeTicks()) 775 (AnyThread().rails_loading_priority_deadline - base::TimeTicks())
771 .InMillisecondsF()); 776 .InMillisecondsF());
777 state->SetBoolean("navigation_expected",
778 MainThreadOnly().navigation_expected);
772 state->SetDouble("last_idle_period_end_time", 779 state->SetDouble("last_idle_period_end_time",
773 (AnyThread().last_idle_period_end_time - base::TimeTicks()) 780 (AnyThread().last_idle_period_end_time - base::TimeTicks())
774 .InMillisecondsF()); 781 .InMillisecondsF());
775 state->SetBoolean("awaiting_touch_start_response", 782 state->SetBoolean("awaiting_touch_start_response",
776 AnyThread().awaiting_touch_start_response); 783 AnyThread().awaiting_touch_start_response);
777 state->SetBoolean("begin_main_frame_on_critical_path", 784 state->SetBoolean("begin_main_frame_on_critical_path",
778 AnyThread().begin_main_frame_on_critical_path); 785 AnyThread().begin_main_frame_on_critical_path);
779 state->SetDouble("expected_loading_task_duration", 786 state->SetDouble("expected_loading_task_duration",
780 MainThreadOnly() 787 MainThreadOnly()
781 .loading_task_cost_estimator.expected_task_duration() 788 .loading_task_cost_estimator.expected_task_duration()
(...skipping 22 matching lines...) Expand all
804 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED); 811 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED);
805 } 812 }
806 813
807 void RendererSchedulerImpl::OnIdlePeriodEnded() { 814 void RendererSchedulerImpl::OnIdlePeriodEnded() {
808 base::AutoLock lock(any_thread_lock_); 815 base::AutoLock lock(any_thread_lock_);
809 AnyThread().last_idle_period_end_time = helper_.Now(); 816 AnyThread().last_idle_period_end_time = helper_.Now();
810 AnyThread().in_idle_period = false; 817 AnyThread().in_idle_period = false;
811 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED); 818 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED);
812 } 819 }
813 820
814 void RendererSchedulerImpl::OnPageLoadStarted() { 821 void RendererSchedulerImpl::OnNavigationExpected() {
822 helper_.CheckOnValidThread();
823 base::AutoLock lock(any_thread_lock_);
Sami 2015/09/24 15:16:15 nit: Just call UpdatePolicy() to avoid some boiler
alex clarke (OOO till 29th) 2015/09/24 15:37:14 Done.
824 MainThreadOnly().navigation_expected = true;
825 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED);
826 }
827
828 void RendererSchedulerImpl::OnNavigationCanceled() {
829 helper_.CheckOnValidThread();
830 base::AutoLock lock(any_thread_lock_);
Sami 2015/09/24 15:16:15 Ditto.
alex clarke (OOO till 29th) 2015/09/24 15:37:14 Done.
831 MainThreadOnly().navigation_expected = false;
832 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED);
833 }
834
835 void RendererSchedulerImpl::OnNavigationStarted() {
815 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), 836 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"),
816 "RendererSchedulerImpl::OnPageLoadStarted"); 837 "RendererSchedulerImpl::OnNavigationStarted");
817 base::AutoLock lock(any_thread_lock_); 838 base::AutoLock lock(any_thread_lock_);
818 AnyThread().rails_loading_priority_deadline = 839 AnyThread().rails_loading_priority_deadline =
819 helper_.Now() + base::TimeDelta::FromMilliseconds( 840 helper_.Now() + base::TimeDelta::FromMilliseconds(
820 kRailsInitialLoadingPrioritizationMillis); 841 kRailsInitialLoadingPrioritizationMillis);
821 ResetForNavigationLocked(); 842 ResetForNavigationLocked();
822 } 843 }
823 844
824 bool RendererSchedulerImpl::HadAnIdlePeriodRecently(base::TimeTicks now) const { 845 bool RendererSchedulerImpl::HadAnIdlePeriodRecently(base::TimeTicks now) const {
825 return (now - AnyThread().last_idle_period_end_time) <= 846 return (now - AnyThread().last_idle_period_end_time) <=
826 base::TimeDelta::FromMilliseconds( 847 base::TimeDelta::FromMilliseconds(
(...skipping 20 matching lines...) Expand all
847 868
848 void RendererSchedulerImpl::ResetForNavigationLocked() { 869 void RendererSchedulerImpl::ResetForNavigationLocked() {
849 helper_.CheckOnValidThread(); 870 helper_.CheckOnValidThread();
850 any_thread_lock_.AssertAcquired(); 871 any_thread_lock_.AssertAcquired();
851 MainThreadOnly().loading_task_cost_estimator.Clear(); 872 MainThreadOnly().loading_task_cost_estimator.Clear();
852 MainThreadOnly().timer_task_cost_estimator.Clear(); 873 MainThreadOnly().timer_task_cost_estimator.Clear();
853 MainThreadOnly().short_idle_period_duration.Clear(); 874 MainThreadOnly().short_idle_period_duration.Clear();
854 // Make sure that we don't initially assume there is no idle time. 875 // Make sure that we don't initially assume there is no idle time.
855 MainThreadOnly().short_idle_period_duration.InsertSample( 876 MainThreadOnly().short_idle_period_duration.InsertSample(
856 cc::BeginFrameArgs::DefaultInterval()); 877 cc::BeginFrameArgs::DefaultInterval());
878 MainThreadOnly().navigation_expected = false;
857 AnyThread().user_model.Reset(); 879 AnyThread().user_model.Reset();
858 MainThreadOnly().have_seen_a_begin_main_frame = false; 880 MainThreadOnly().have_seen_a_begin_main_frame = false;
859 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED); 881 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED);
860 } 882 }
861 883
862 } // namespace scheduler 884 } // namespace scheduler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698