| 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 #ifndef COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_IMPL_H_ | 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_RENDERER_SCHEDULER
_IMPL_H_ |
| 6 #define COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_IMPL_H_ | 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_RENDERER_SCHEDULER
_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/atomicops.h" | 8 #include "base/atomicops.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 11 #include "components/scheduler/base/long_task_tracker.h" | 11 #include "platform/scheduler/base/long_task_tracker.h" |
| 12 #include "components/scheduler/base/pollable_thread_safe_flag.h" | 12 #include "platform/scheduler/base/pollable_thread_safe_flag.h" |
| 13 #include "components/scheduler/base/queueing_time_estimator.h" | 13 #include "platform/scheduler/base/queueing_time_estimator.h" |
| 14 #include "components/scheduler/base/task_time_tracker.h" | 14 #include "platform/scheduler/base/task_time_tracker.h" |
| 15 #include "components/scheduler/child/idle_helper.h" | 15 #include "platform/scheduler/child/idle_helper.h" |
| 16 #include "components/scheduler/child/scheduler_helper.h" | 16 #include "platform/scheduler/child/scheduler_helper.h" |
| 17 #include "components/scheduler/renderer/deadline_task_runner.h" | 17 #include "platform/scheduler/renderer/deadline_task_runner.h" |
| 18 #include "components/scheduler/renderer/idle_time_estimator.h" | 18 #include "platform/scheduler/renderer/idle_time_estimator.h" |
| 19 #include "components/scheduler/renderer/render_widget_signals.h" | 19 #include "platform/scheduler/renderer/render_widget_signals.h" |
| 20 #include "components/scheduler/renderer/renderer_scheduler.h" | 20 #include "public/platform/scheduler/renderer/renderer_scheduler.h" |
| 21 #include "components/scheduler/renderer/task_cost_estimator.h" | 21 #include "platform/scheduler/renderer/task_cost_estimator.h" |
| 22 #include "components/scheduler/renderer/throttling_helper.h" | 22 #include "platform/scheduler/renderer/throttling_helper.h" |
| 23 #include "components/scheduler/renderer/user_model.h" | 23 #include "platform/scheduler/renderer/user_model.h" |
| 24 #include "components/scheduler/renderer/web_view_scheduler_impl.h" | 24 #include "platform/scheduler/renderer/web_view_scheduler_impl.h" |
| 25 #include "components/scheduler/scheduler_export.h" | |
| 26 | 25 |
| 27 namespace base { | 26 namespace base { |
| 28 namespace trace_event { | 27 namespace trace_event { |
| 29 class ConvertableToTraceFormat; | 28 class ConvertableToTraceFormat; |
| 30 } | 29 } |
| 31 } | 30 } |
| 32 | 31 |
| 32 namespace blink { |
| 33 namespace scheduler { | 33 namespace scheduler { |
| 34 class AutoAdvancingVirtualTimeDomain; | 34 class AutoAdvancingVirtualTimeDomain; |
| 35 class RenderWidgetSchedulingState; | 35 class RenderWidgetSchedulingState; |
| 36 class WebViewSchedulerImpl; | 36 class WebViewSchedulerImpl; |
| 37 class ThrottlingHelper; | 37 class ThrottlingHelper; |
| 38 | 38 |
| 39 class SCHEDULER_EXPORT RendererSchedulerImpl | 39 class BLINK_PLATFORM_EXPORT RendererSchedulerImpl |
| 40 : public RendererScheduler, | 40 : public RendererScheduler, |
| 41 public IdleHelper::Delegate, | 41 public IdleHelper::Delegate, |
| 42 public SchedulerHelper::Observer, | 42 public SchedulerHelper::Observer, |
| 43 public RenderWidgetSignals::Observer, | 43 public RenderWidgetSignals::Observer, |
| 44 public TaskTimeTracker, | 44 public TaskTimeTracker, |
| 45 public QueueingTimeEstimator::Client { | 45 public QueueingTimeEstimator::Client { |
| 46 public: | 46 public: |
| 47 // Keep RendererScheduler::UseCaseToString in sync with this enum. | 47 // Keep RendererScheduler::UseCaseToString in sync with this enum. |
| 48 enum class UseCase { | 48 enum class UseCase { |
| 49 // No active use case detected. | 49 // No active use case detected. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 73 USE_CASE_COUNT, | 73 USE_CASE_COUNT, |
| 74 FIRST_USE_CASE = NONE, | 74 FIRST_USE_CASE = NONE, |
| 75 }; | 75 }; |
| 76 static const char* UseCaseToString(UseCase use_case); | 76 static const char* UseCaseToString(UseCase use_case); |
| 77 static const char* RAILModeToString(v8::RAILMode rail_mode); | 77 static const char* RAILModeToString(v8::RAILMode rail_mode); |
| 78 | 78 |
| 79 RendererSchedulerImpl(scoped_refptr<SchedulerTqmDelegate> main_task_runner); | 79 RendererSchedulerImpl(scoped_refptr<SchedulerTqmDelegate> main_task_runner); |
| 80 ~RendererSchedulerImpl() override; | 80 ~RendererSchedulerImpl() override; |
| 81 | 81 |
| 82 // RendererScheduler implementation: | 82 // RendererScheduler implementation: |
| 83 std::unique_ptr<blink::WebThread> CreateMainThread() override; | 83 std::unique_ptr<WebThread> CreateMainThread() override; |
| 84 scoped_refptr<TaskQueue> DefaultTaskRunner() override; | 84 scoped_refptr<TaskQueue> DefaultTaskRunner() override; |
| 85 scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner() override; | 85 scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner() override; |
| 86 scoped_refptr<TaskQueue> CompositorTaskRunner() override; | 86 scoped_refptr<TaskQueue> CompositorTaskRunner() override; |
| 87 scoped_refptr<TaskQueue> LoadingTaskRunner() override; | 87 scoped_refptr<TaskQueue> LoadingTaskRunner() override; |
| 88 scoped_refptr<TaskQueue> TimerTaskRunner() override; | 88 scoped_refptr<TaskQueue> TimerTaskRunner() override; |
| 89 scoped_refptr<TaskQueue> NewLoadingTaskRunner(const char* name) override; | 89 scoped_refptr<TaskQueue> NewLoadingTaskRunner(const char* name) override; |
| 90 scoped_refptr<TaskQueue> NewTimerTaskRunner(const char* name) override; | 90 scoped_refptr<TaskQueue> NewTimerTaskRunner(const char* name) override; |
| 91 scoped_refptr<TaskQueue> NewUnthrottledTaskRunner(const char* name) override; | 91 scoped_refptr<TaskQueue> NewUnthrottledTaskRunner(const char* name) override; |
| 92 std::unique_ptr<RenderWidgetSchedulingState> NewRenderWidgetSchedulingState() | 92 std::unique_ptr<RenderWidgetSchedulingState> NewRenderWidgetSchedulingState() |
| 93 override; | 93 override; |
| 94 void WillBeginFrame(const cc::BeginFrameArgs& args) override; | 94 void WillBeginFrame(const cc::BeginFrameArgs& args) override; |
| 95 void BeginFrameNotExpectedSoon() override; | 95 void BeginFrameNotExpectedSoon() override; |
| 96 void DidCommitFrameToCompositor() override; | 96 void DidCommitFrameToCompositor() override; |
| 97 void DidHandleInputEventOnCompositorThread( | 97 void DidHandleInputEventOnCompositorThread( |
| 98 const blink::WebInputEvent& web_input_event, | 98 const WebInputEvent& web_input_event, |
| 99 InputEventState event_state) override; | 99 InputEventState event_state) override; |
| 100 void DidHandleInputEventOnMainThread( | 100 void DidHandleInputEventOnMainThread( |
| 101 const blink::WebInputEvent& web_input_event) override; | 101 const WebInputEvent& web_input_event) override; |
| 102 void DidAnimateForInputOnCompositorThread() override; | 102 void DidAnimateForInputOnCompositorThread() override; |
| 103 void OnRendererBackgrounded() override; | 103 void OnRendererBackgrounded() override; |
| 104 void OnRendererForegrounded() override; | 104 void OnRendererForegrounded() override; |
| 105 void SuspendRenderer() override; | 105 void SuspendRenderer() override; |
| 106 void AddPendingNavigation( | 106 void AddPendingNavigation(WebScheduler::NavigatingFrameType type) override; |
| 107 blink::WebScheduler::NavigatingFrameType type) override; | 107 void RemovePendingNavigation(WebScheduler::NavigatingFrameType type) override; |
| 108 void RemovePendingNavigation( | |
| 109 blink::WebScheduler::NavigatingFrameType type) override; | |
| 110 void OnNavigationStarted() override; | 108 void OnNavigationStarted() override; |
| 111 bool IsHighPriorityWorkAnticipated() override; | 109 bool IsHighPriorityWorkAnticipated() override; |
| 112 bool ShouldYieldForHighPriorityWork() override; | 110 bool ShouldYieldForHighPriorityWork() override; |
| 113 bool CanExceedIdleDeadlineIfRequired() const override; | 111 bool CanExceedIdleDeadlineIfRequired() const override; |
| 114 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override; | 112 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override; |
| 115 void RemoveTaskObserver( | 113 void RemoveTaskObserver( |
| 116 base::MessageLoop::TaskObserver* task_observer) override; | 114 base::MessageLoop::TaskObserver* task_observer) override; |
| 117 void Shutdown() override; | 115 void Shutdown() override; |
| 118 void SuspendTimerQueue() override; | 116 void SuspendTimerQueue() override; |
| 119 void ResumeTimerQueue() override; | 117 void ResumeTimerQueue() override; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 void OnIdlePeriodEnded() override; | 246 void OnIdlePeriodEnded() override; |
| 249 | 247 |
| 250 void EndIdlePeriod(); | 248 void EndIdlePeriod(); |
| 251 | 249 |
| 252 // Returns the serialized scheduler state for tracing. | 250 // Returns the serialized scheduler state for tracing. |
| 253 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue( | 251 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue( |
| 254 base::TimeTicks optional_now) const; | 252 base::TimeTicks optional_now) const; |
| 255 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValueLocked( | 253 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValueLocked( |
| 256 base::TimeTicks optional_now) const; | 254 base::TimeTicks optional_now) const; |
| 257 | 255 |
| 258 static bool ShouldPrioritizeInputEvent( | 256 static bool ShouldPrioritizeInputEvent(const WebInputEvent& web_input_event); |
| 259 const blink::WebInputEvent& web_input_event); | |
| 260 | 257 |
| 261 // The amount of time which idle periods can continue being scheduled when the | 258 // The amount of time which idle periods can continue being scheduled when the |
| 262 // renderer has been hidden, before going to sleep for good. | 259 // renderer has been hidden, before going to sleep for good. |
| 263 static const int kEndIdleWhenHiddenDelayMillis = 10000; | 260 static const int kEndIdleWhenHiddenDelayMillis = 10000; |
| 264 | 261 |
| 265 // The amount of time for which loading tasks will be prioritized over | 262 // The amount of time for which loading tasks will be prioritized over |
| 266 // other tasks during the initial page load. | 263 // other tasks during the initial page load. |
| 267 static const int kRailsInitialLoadingPrioritizationMillis = 1000; | 264 static const int kRailsInitialLoadingPrioritizationMillis = 1000; |
| 268 | 265 |
| 269 // The amount of time in milliseconds we have to respond to user input as | 266 // The amount of time in milliseconds we have to respond to user input as |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 // Helper for computing the use case. |expected_usecase_duration| will be | 312 // Helper for computing the use case. |expected_usecase_duration| will be |
| 316 // filled with the amount of time after which the use case should be updated | 313 // filled with the amount of time after which the use case should be updated |
| 317 // again. If the duration is zero, a new use case update should not be | 314 // again. If the duration is zero, a new use case update should not be |
| 318 // scheduled. Must be called with |any_thread_lock_| held. Can be called from | 315 // scheduled. Must be called with |any_thread_lock_| held. Can be called from |
| 319 // any thread. | 316 // any thread. |
| 320 UseCase ComputeCurrentUseCase( | 317 UseCase ComputeCurrentUseCase( |
| 321 base::TimeTicks now, | 318 base::TimeTicks now, |
| 322 base::TimeDelta* expected_use_case_duration) const; | 319 base::TimeDelta* expected_use_case_duration) const; |
| 323 | 320 |
| 324 // An input event of some sort happened, the policy may need updating. | 321 // An input event of some sort happened, the policy may need updating. |
| 325 void UpdateForInputEventOnCompositorThread(blink::WebInputEvent::Type type, | 322 void UpdateForInputEventOnCompositorThread(WebInputEvent::Type type, |
| 326 InputEventState input_event_state); | 323 InputEventState input_event_state); |
| 327 | 324 |
| 328 // Returns true if there has been at least one idle period in the last | 325 // Returns true if there has been at least one idle period in the last |
| 329 // |kIdlePeriodStarvationThresholdMillis|. | 326 // |kIdlePeriodStarvationThresholdMillis|. |
| 330 bool HadAnIdlePeriodRecently(base::TimeTicks now) const; | 327 bool HadAnIdlePeriodRecently(base::TimeTicks now) const; |
| 331 | 328 |
| 332 // Helpers for safely suspending/resuming the timer queue after a | 329 // Helpers for safely suspending/resuming the timer queue after a |
| 333 // background/foreground signal. | 330 // background/foreground signal. |
| 334 void SuspendTimerQueueWhenBackgrounded(); | 331 void SuspendTimerQueueWhenBackgrounded(); |
| 335 void ResumeTimerQueueWhenForegrounded(); | 332 void ResumeTimerQueueWhenForegrounded(); |
| 336 | 333 |
| 337 // The task cost estimators and the UserModel need to be reset upon page | 334 // The task cost estimators and the UserModel need to be reset upon page |
| 338 // nagigation. This function does that. Must be called from the main thread. | 335 // nagigation. This function does that. Must be called from the main thread. |
| 339 void ResetForNavigationLocked(); | 336 void ResetForNavigationLocked(); |
| 340 | 337 |
| 341 // Estimates the maximum task length that won't cause a jank based on the | 338 // Estimates the maximum task length that won't cause a jank based on the |
| 342 // current system state. Must be called from the main thread. | 339 // current system state. Must be called from the main thread. |
| 343 base::TimeDelta EstimateLongestJankFreeTaskDuration() const; | 340 base::TimeDelta EstimateLongestJankFreeTaskDuration() const; |
| 344 | 341 |
| 345 // Log a console warning message to all WebViews in this process. | 342 // Report an intervention to all WebViews in this process. |
| 346 void BroadcastConsoleWarning(const std::string& message); | 343 void BroadcastIntervention(const std::string& message); |
| 347 | 344 |
| 348 void ApplyTaskQueuePolicy(TaskQueue* task_queue, | 345 void ApplyTaskQueuePolicy(TaskQueue* task_queue, |
| 349 const TaskQueuePolicy& old_task_queue_policy, | 346 const TaskQueuePolicy& old_task_queue_policy, |
| 350 const TaskQueuePolicy& new_task_queue_policy) const; | 347 const TaskQueuePolicy& new_task_queue_policy) const; |
| 351 | 348 |
| 352 static const char* ExpensiveTaskPolicyToString( | 349 static const char* ExpensiveTaskPolicyToString( |
| 353 ExpensiveTaskPolicy expensive_task_policy); | 350 ExpensiveTaskPolicy expensive_task_policy); |
| 354 | 351 |
| 355 SchedulerHelper helper_; | 352 SchedulerHelper helper_; |
| 356 IdleHelper idle_helper_; | 353 IdleHelper idle_helper_; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 bool begin_main_frame_on_critical_path; | 427 bool begin_main_frame_on_critical_path; |
| 431 bool last_gesture_was_compositor_driven; | 428 bool last_gesture_was_compositor_driven; |
| 432 bool default_gesture_prevented; | 429 bool default_gesture_prevented; |
| 433 bool have_seen_touchstart; | 430 bool have_seen_touchstart; |
| 434 }; | 431 }; |
| 435 | 432 |
| 436 struct CompositorThreadOnly { | 433 struct CompositorThreadOnly { |
| 437 CompositorThreadOnly(); | 434 CompositorThreadOnly(); |
| 438 ~CompositorThreadOnly(); | 435 ~CompositorThreadOnly(); |
| 439 | 436 |
| 440 blink::WebInputEvent::Type last_input_type; | 437 WebInputEvent::Type last_input_type; |
| 441 std::unique_ptr<base::ThreadChecker> compositor_thread_checker; | 438 std::unique_ptr<base::ThreadChecker> compositor_thread_checker; |
| 442 | 439 |
| 443 void CheckOnValidThread() { | 440 void CheckOnValidThread() { |
| 444 #if DCHECK_IS_ON() | 441 #if DCHECK_IS_ON() |
| 445 // We don't actually care which thread this called from, just so long as | 442 // We don't actually care which thread this called from, just so long as |
| 446 // its consistent. | 443 // its consistent. |
| 447 if (!compositor_thread_checker) | 444 if (!compositor_thread_checker) |
| 448 compositor_thread_checker.reset(new base::ThreadChecker()); | 445 compositor_thread_checker.reset(new base::ThreadChecker()); |
| 449 DCHECK(compositor_thread_checker->CalledOnValidThread()); | 446 DCHECK(compositor_thread_checker->CalledOnValidThread()); |
| 450 #endif | 447 #endif |
| (...skipping 30 matching lines...) Expand all Loading... |
| 481 return compositor_thread_only_; | 478 return compositor_thread_only_; |
| 482 } | 479 } |
| 483 | 480 |
| 484 PollableThreadSafeFlag policy_may_need_update_; | 481 PollableThreadSafeFlag policy_may_need_update_; |
| 485 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; | 482 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; |
| 486 | 483 |
| 487 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); | 484 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); |
| 488 }; | 485 }; |
| 489 | 486 |
| 490 } // namespace scheduler | 487 } // namespace scheduler |
| 488 } // namespace blink |
| 491 | 489 |
| 492 #endif // COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_IMPL_H_ | 490 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_RENDERER_SCHEDU
LER_IMPL_H_ |
| OLD | NEW |