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

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: Rename for Sami Created 5 years, 2 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 default_queue_priority(TaskQueue::NORMAL_PRIORITY) {} 95 default_queue_priority(TaskQueue::NORMAL_PRIORITY) {}
96 96
97 RendererSchedulerImpl::MainThreadOnly::MainThreadOnly() 97 RendererSchedulerImpl::MainThreadOnly::MainThreadOnly()
98 : loading_task_cost_estimator(kLoadingTaskEstimationSampleCount, 98 : loading_task_cost_estimator(kLoadingTaskEstimationSampleCount,
99 kLoadingTaskEstimationPercentile), 99 kLoadingTaskEstimationPercentile),
100 timer_task_cost_estimator(kTimerTaskEstimationSampleCount, 100 timer_task_cost_estimator(kTimerTaskEstimationSampleCount,
101 kTimerTaskEstimationPercentile), 101 kTimerTaskEstimationPercentile),
102 short_idle_period_duration(kShortIdlePeriodDurationSampleCount), 102 short_idle_period_duration(kShortIdlePeriodDurationSampleCount),
103 current_use_case(UseCase::NONE), 103 current_use_case(UseCase::NONE),
104 timer_queue_suspend_count(0), 104 timer_queue_suspend_count(0),
105 navigation_task_expected_count(0),
105 renderer_hidden(false), 106 renderer_hidden(false),
106 renderer_backgrounded(false), 107 renderer_backgrounded(false),
107 timer_queue_suspension_when_backgrounded_enabled(false), 108 timer_queue_suspension_when_backgrounded_enabled(false),
108 timer_queue_suspended_when_backgrounded(false), 109 timer_queue_suspended_when_backgrounded(false),
109 was_shutdown(false), 110 was_shutdown(false),
110 loading_tasks_seem_expensive(false), 111 loading_tasks_seem_expensive(false),
111 timer_tasks_seem_expensive(false), 112 timer_tasks_seem_expensive(false),
112 touchstart_expected_soon(false), 113 touchstart_expected_soon(false),
113 have_seen_a_begin_main_frame(false) {} 114 have_seen_a_begin_main_frame(false) {}
114 115
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 break; 625 break;
625 626
626 default: 627 default:
627 NOTREACHED(); 628 NOTREACHED();
628 } 629 }
629 630
630 // Don't block expensive tasks unless we have actually seen something. 631 // Don't block expensive tasks unless we have actually seen something.
631 if (!MainThreadOnly().have_seen_a_begin_main_frame) 632 if (!MainThreadOnly().have_seen_a_begin_main_frame)
632 block_expensive_tasks = false; 633 block_expensive_tasks = false;
633 634
635 // Don't block expensive tasks if we are expecting a navigation.
636 if (MainThreadOnly().navigation_task_expected_count > 0)
637 block_expensive_tasks = false;
638
634 if (block_expensive_tasks && loading_tasks_seem_expensive) 639 if (block_expensive_tasks && loading_tasks_seem_expensive)
635 new_policy.loading_queue_priority = TaskQueue::DISABLED_PRIORITY; 640 new_policy.loading_queue_priority = TaskQueue::DISABLED_PRIORITY;
636 641
637 if ((block_expensive_tasks && timer_tasks_seem_expensive) || 642 if ((block_expensive_tasks && timer_tasks_seem_expensive) ||
638 MainThreadOnly().timer_queue_suspend_count != 0 || 643 MainThreadOnly().timer_queue_suspend_count != 0 ||
639 MainThreadOnly().timer_queue_suspended_when_backgrounded) { 644 MainThreadOnly().timer_queue_suspended_when_backgrounded) {
640 new_policy.timer_queue_priority = TaskQueue::DISABLED_PRIORITY; 645 new_policy.timer_queue_priority = TaskQueue::DISABLED_PRIORITY;
641 } 646 }
642 647
643 // Tracing is done before the early out check, because it's quite possible we 648 // Tracing is done before the early out check, because it's quite possible we
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 MainThreadOnly().renderer_backgrounded); 814 MainThreadOnly().renderer_backgrounded);
810 state->SetBoolean("timer_queue_suspended_when_backgrounded", 815 state->SetBoolean("timer_queue_suspended_when_backgrounded",
811 MainThreadOnly().timer_queue_suspended_when_backgrounded); 816 MainThreadOnly().timer_queue_suspended_when_backgrounded);
812 state->SetInteger("timer_queue_suspend_count", 817 state->SetInteger("timer_queue_suspend_count",
813 MainThreadOnly().timer_queue_suspend_count); 818 MainThreadOnly().timer_queue_suspend_count);
814 state->SetDouble("now", (optional_now - base::TimeTicks()).InMillisecondsF()); 819 state->SetDouble("now", (optional_now - base::TimeTicks()).InMillisecondsF());
815 state->SetDouble( 820 state->SetDouble(
816 "rails_loading_priority_deadline", 821 "rails_loading_priority_deadline",
817 (AnyThread().rails_loading_priority_deadline - base::TimeTicks()) 822 (AnyThread().rails_loading_priority_deadline - base::TimeTicks())
818 .InMillisecondsF()); 823 .InMillisecondsF());
824 state->SetInteger("navigation_task_expected_count",
825 MainThreadOnly().navigation_task_expected_count);
819 state->SetDouble("last_idle_period_end_time", 826 state->SetDouble("last_idle_period_end_time",
820 (AnyThread().last_idle_period_end_time - base::TimeTicks()) 827 (AnyThread().last_idle_period_end_time - base::TimeTicks())
821 .InMillisecondsF()); 828 .InMillisecondsF());
822 state->SetBoolean("awaiting_touch_start_response", 829 state->SetBoolean("awaiting_touch_start_response",
823 AnyThread().awaiting_touch_start_response); 830 AnyThread().awaiting_touch_start_response);
824 state->SetBoolean("begin_main_frame_on_critical_path", 831 state->SetBoolean("begin_main_frame_on_critical_path",
825 AnyThread().begin_main_frame_on_critical_path); 832 AnyThread().begin_main_frame_on_critical_path);
826 state->SetDouble("expected_loading_task_duration", 833 state->SetDouble("expected_loading_task_duration",
827 MainThreadOnly() 834 MainThreadOnly()
828 .loading_task_cost_estimator.expected_task_duration() 835 .loading_task_cost_estimator.expected_task_duration()
(...skipping 22 matching lines...) Expand all
851 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED); 858 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED);
852 } 859 }
853 860
854 void RendererSchedulerImpl::OnIdlePeriodEnded() { 861 void RendererSchedulerImpl::OnIdlePeriodEnded() {
855 base::AutoLock lock(any_thread_lock_); 862 base::AutoLock lock(any_thread_lock_);
856 AnyThread().last_idle_period_end_time = helper_.Now(); 863 AnyThread().last_idle_period_end_time = helper_.Now();
857 AnyThread().in_idle_period = false; 864 AnyThread().in_idle_period = false;
858 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED); 865 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED);
859 } 866 }
860 867
861 void RendererSchedulerImpl::OnPageLoadStarted() { 868 void RendererSchedulerImpl::AddPendingNavigation() {
869 helper_.CheckOnValidThread();
870 MainThreadOnly().navigation_task_expected_count++;
871 UpdatePolicy();
872 }
873
874 void RendererSchedulerImpl::RemovePendingNavigation() {
875 helper_.CheckOnValidThread();
876 DCHECK_GT(MainThreadOnly().navigation_task_expected_count, 0);
877 if (MainThreadOnly().navigation_task_expected_count > 0)
878 MainThreadOnly().navigation_task_expected_count--;
879 UpdatePolicy();
880 }
881
882 void RendererSchedulerImpl::OnNavigationStarted() {
862 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), 883 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"),
863 "RendererSchedulerImpl::OnPageLoadStarted"); 884 "RendererSchedulerImpl::OnNavigationStarted");
864 base::AutoLock lock(any_thread_lock_); 885 base::AutoLock lock(any_thread_lock_);
865 AnyThread().rails_loading_priority_deadline = 886 AnyThread().rails_loading_priority_deadline =
866 helper_.Now() + base::TimeDelta::FromMilliseconds( 887 helper_.Now() + base::TimeDelta::FromMilliseconds(
867 kRailsInitialLoadingPrioritizationMillis); 888 kRailsInitialLoadingPrioritizationMillis);
868 ResetForNavigationLocked(); 889 ResetForNavigationLocked();
869 } 890 }
870 891
871 bool RendererSchedulerImpl::HadAnIdlePeriodRecently(base::TimeTicks now) const { 892 bool RendererSchedulerImpl::HadAnIdlePeriodRecently(base::TimeTicks now) const {
872 return (now - AnyThread().last_idle_period_end_time) <= 893 return (now - AnyThread().last_idle_period_end_time) <=
873 base::TimeDelta::FromMilliseconds( 894 base::TimeDelta::FromMilliseconds(
(...skipping 26 matching lines...) Expand all
900 MainThreadOnly().short_idle_period_duration.Clear(); 921 MainThreadOnly().short_idle_period_duration.Clear();
901 // Make sure that we don't initially assume there is no idle time. 922 // Make sure that we don't initially assume there is no idle time.
902 MainThreadOnly().short_idle_period_duration.InsertSample( 923 MainThreadOnly().short_idle_period_duration.InsertSample(
903 cc::BeginFrameArgs::DefaultInterval()); 924 cc::BeginFrameArgs::DefaultInterval());
904 AnyThread().user_model.Reset(); 925 AnyThread().user_model.Reset();
905 MainThreadOnly().have_seen_a_begin_main_frame = false; 926 MainThreadOnly().have_seen_a_begin_main_frame = false;
906 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED); 927 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED);
907 } 928 }
908 929
909 } // namespace scheduler 930 } // namespace scheduler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698