Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 | 115 |
| 116 RendererSchedulerImpl::MainThreadOnly::~MainThreadOnly() {} | 116 RendererSchedulerImpl::MainThreadOnly::~MainThreadOnly() {} |
| 117 | 117 |
| 118 RendererSchedulerImpl::AnyThread::AnyThread() | 118 RendererSchedulerImpl::AnyThread::AnyThread() |
| 119 : awaiting_touch_start_response(false), | 119 : navigation_expected(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) {} |
| 125 | 126 |
| 126 RendererSchedulerImpl::CompositorThreadOnly::~CompositorThreadOnly() { | 127 RendererSchedulerImpl::CompositorThreadOnly::~CompositorThreadOnly() { |
| 127 } | 128 } |
| 128 | 129 |
| 129 void RendererSchedulerImpl::Shutdown() { | 130 void RendererSchedulerImpl::Shutdown() { |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 (AnyThread().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 Loading... | |
| 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", AnyThread().navigation_expected); | |
| 772 state->SetDouble("last_idle_period_end_time", | 778 state->SetDouble("last_idle_period_end_time", |
| 773 (AnyThread().last_idle_period_end_time - base::TimeTicks()) | 779 (AnyThread().last_idle_period_end_time - base::TimeTicks()) |
| 774 .InMillisecondsF()); | 780 .InMillisecondsF()); |
| 775 state->SetBoolean("awaiting_touch_start_response", | 781 state->SetBoolean("awaiting_touch_start_response", |
| 776 AnyThread().awaiting_touch_start_response); | 782 AnyThread().awaiting_touch_start_response); |
| 777 state->SetBoolean("begin_main_frame_on_critical_path", | 783 state->SetBoolean("begin_main_frame_on_critical_path", |
| 778 AnyThread().begin_main_frame_on_critical_path); | 784 AnyThread().begin_main_frame_on_critical_path); |
| 779 state->SetDouble("expected_loading_task_duration", | 785 state->SetDouble("expected_loading_task_duration", |
| 780 MainThreadOnly() | 786 MainThreadOnly() |
| 781 .loading_task_cost_estimator.expected_task_duration() | 787 .loading_task_cost_estimator.expected_task_duration() |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 804 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED); | 810 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED); |
| 805 } | 811 } |
| 806 | 812 |
| 807 void RendererSchedulerImpl::OnIdlePeriodEnded() { | 813 void RendererSchedulerImpl::OnIdlePeriodEnded() { |
| 808 base::AutoLock lock(any_thread_lock_); | 814 base::AutoLock lock(any_thread_lock_); |
| 809 AnyThread().last_idle_period_end_time = helper_.Now(); | 815 AnyThread().last_idle_period_end_time = helper_.Now(); |
| 810 AnyThread().in_idle_period = false; | 816 AnyThread().in_idle_period = false; |
| 811 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED); | 817 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED); |
| 812 } | 818 } |
| 813 | 819 |
| 814 void RendererSchedulerImpl::OnPageLoadStarted() { | 820 void RendererSchedulerImpl::OnNavigationExpected() { |
| 821 base::AutoLock lock(any_thread_lock_); | |
|
Sami
2015/09/24 14:15:04
nit: helper_.CheckOnValidThread();
alex clarke (OOO till 29th)
2015/09/24 14:53:10
Done.
| |
| 822 AnyThread().navigation_expected = true; | |
| 823 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED); | |
| 824 } | |
| 825 | |
| 826 void RendererSchedulerImpl::OnNavigationCanceled() { | |
| 827 base::AutoLock lock(any_thread_lock_); | |
|
Sami
2015/09/24 14:15:04
Ditto.
alex clarke (OOO till 29th)
2015/09/24 14:53:10
Done.
| |
| 828 AnyThread().navigation_expected = false; | |
| 829 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED); | |
| 830 } | |
| 831 | |
| 832 void RendererSchedulerImpl::OnNavigationStarted() { | |
| 815 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), | 833 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), |
| 816 "RendererSchedulerImpl::OnPageLoadStarted"); | 834 "RendererSchedulerImpl::OnNavigationStarted"); |
| 817 base::AutoLock lock(any_thread_lock_); | 835 base::AutoLock lock(any_thread_lock_); |
| 818 AnyThread().rails_loading_priority_deadline = | 836 AnyThread().rails_loading_priority_deadline = |
| 819 helper_.Now() + base::TimeDelta::FromMilliseconds( | 837 helper_.Now() + base::TimeDelta::FromMilliseconds( |
| 820 kRailsInitialLoadingPrioritizationMillis); | 838 kRailsInitialLoadingPrioritizationMillis); |
| 821 ResetForNavigationLocked(); | 839 ResetForNavigationLocked(); |
| 822 } | 840 } |
| 823 | 841 |
| 824 bool RendererSchedulerImpl::HadAnIdlePeriodRecently(base::TimeTicks now) const { | 842 bool RendererSchedulerImpl::HadAnIdlePeriodRecently(base::TimeTicks now) const { |
| 825 return (now - AnyThread().last_idle_period_end_time) <= | 843 return (now - AnyThread().last_idle_period_end_time) <= |
| 826 base::TimeDelta::FromMilliseconds( | 844 base::TimeDelta::FromMilliseconds( |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 847 | 865 |
| 848 void RendererSchedulerImpl::ResetForNavigationLocked() { | 866 void RendererSchedulerImpl::ResetForNavigationLocked() { |
| 849 helper_.CheckOnValidThread(); | 867 helper_.CheckOnValidThread(); |
| 850 any_thread_lock_.AssertAcquired(); | 868 any_thread_lock_.AssertAcquired(); |
| 851 MainThreadOnly().loading_task_cost_estimator.Clear(); | 869 MainThreadOnly().loading_task_cost_estimator.Clear(); |
| 852 MainThreadOnly().timer_task_cost_estimator.Clear(); | 870 MainThreadOnly().timer_task_cost_estimator.Clear(); |
| 853 MainThreadOnly().short_idle_period_duration.Clear(); | 871 MainThreadOnly().short_idle_period_duration.Clear(); |
| 854 // Make sure that we don't initially assume there is no idle time. | 872 // Make sure that we don't initially assume there is no idle time. |
| 855 MainThreadOnly().short_idle_period_duration.InsertSample( | 873 MainThreadOnly().short_idle_period_duration.InsertSample( |
| 856 cc::BeginFrameArgs::DefaultInterval()); | 874 cc::BeginFrameArgs::DefaultInterval()); |
| 875 AnyThread().navigation_expected = false; | |
| 857 AnyThread().user_model.Reset(); | 876 AnyThread().user_model.Reset(); |
| 858 MainThreadOnly().have_seen_a_begin_main_frame = false; | 877 MainThreadOnly().have_seen_a_begin_main_frame = false; |
| 859 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED); | 878 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED); |
| 860 } | 879 } |
| 861 | 880 |
| 862 } // namespace scheduler | 881 } // namespace scheduler |
| OLD | NEW |