| 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/pollable_thread_safe_flag.h" | 11 #include "platform/scheduler/base/pollable_thread_safe_flag.h" |
| 12 #include "components/scheduler/base/queueing_time_estimator.h" | 12 #include "platform/scheduler/base/queueing_time_estimator.h" |
| 13 #include "components/scheduler/base/task_time_tracker.h" | 13 #include "platform/scheduler/base/task_time_tracker.h" |
| 14 #include "components/scheduler/child/idle_helper.h" | 14 #include "platform/scheduler/child/idle_helper.h" |
| 15 #include "components/scheduler/child/scheduler_helper.h" | 15 #include "platform/scheduler/child/scheduler_helper.h" |
| 16 #include "components/scheduler/renderer/deadline_task_runner.h" | 16 #include "platform/scheduler/renderer/deadline_task_runner.h" |
| 17 #include "components/scheduler/renderer/idle_time_estimator.h" | 17 #include "platform/scheduler/renderer/idle_time_estimator.h" |
| 18 #include "components/scheduler/renderer/render_widget_signals.h" | 18 #include "platform/scheduler/renderer/render_widget_signals.h" |
| 19 #include "components/scheduler/renderer/renderer_scheduler.h" | 19 #include "public/platform/scheduler/renderer/renderer_scheduler.h" |
| 20 #include "components/scheduler/renderer/task_cost_estimator.h" | 20 #include "platform/scheduler/renderer/task_cost_estimator.h" |
| 21 #include "components/scheduler/renderer/throttling_helper.h" | 21 #include "platform/scheduler/renderer/throttling_helper.h" |
| 22 #include "components/scheduler/renderer/user_model.h" | 22 #include "platform/scheduler/renderer/user_model.h" |
| 23 #include "components/scheduler/renderer/web_view_scheduler_impl.h" | 23 #include "platform/scheduler/renderer/web_view_scheduler_impl.h" |
| 24 #include "components/scheduler/scheduler_export.h" | |
| 25 | 24 |
| 26 namespace base { | 25 namespace base { |
| 27 namespace trace_event { | 26 namespace trace_event { |
| 28 class ConvertableToTraceFormat; | 27 class ConvertableToTraceFormat; |
| 29 } | 28 } |
| 30 } | 29 } |
| 31 | 30 |
| 31 namespace blink { |
| 32 namespace scheduler { | 32 namespace scheduler { |
| 33 class RenderWidgetSchedulingState; | 33 class RenderWidgetSchedulingState; |
| 34 class WebViewSchedulerImpl; | 34 class WebViewSchedulerImpl; |
| 35 class ThrottlingHelper; | 35 class ThrottlingHelper; |
| 36 | 36 |
| 37 class SCHEDULER_EXPORT RendererSchedulerImpl | 37 class BLINK_PLATFORM_EXPORT RendererSchedulerImpl |
| 38 : public RendererScheduler, | 38 : public RendererScheduler, |
| 39 public IdleHelper::Delegate, | 39 public IdleHelper::Delegate, |
| 40 public SchedulerHelper::Observer, | 40 public SchedulerHelper::Observer, |
| 41 public RenderWidgetSignals::Observer, | 41 public RenderWidgetSignals::Observer, |
| 42 public TaskTimeTracker, | 42 public TaskTimeTracker, |
| 43 public QueueingTimeEstimator::Client { | 43 public QueueingTimeEstimator::Client { |
| 44 public: | 44 public: |
| 45 // Keep RendererScheduler::UseCaseToString in sync with this enum. | 45 // Keep RendererScheduler::UseCaseToString in sync with this enum. |
| 46 enum class UseCase { | 46 enum class UseCase { |
| 47 // No active use case detected. | 47 // No active use case detected. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 71 USE_CASE_COUNT, | 71 USE_CASE_COUNT, |
| 72 FIRST_USE_CASE = NONE, | 72 FIRST_USE_CASE = NONE, |
| 73 }; | 73 }; |
| 74 static const char* UseCaseToString(UseCase use_case); | 74 static const char* UseCaseToString(UseCase use_case); |
| 75 static const char* RAILModeToString(v8::RAILMode rail_mode); | 75 static const char* RAILModeToString(v8::RAILMode rail_mode); |
| 76 | 76 |
| 77 RendererSchedulerImpl(scoped_refptr<SchedulerTqmDelegate> main_task_runner); | 77 RendererSchedulerImpl(scoped_refptr<SchedulerTqmDelegate> main_task_runner); |
| 78 ~RendererSchedulerImpl() override; | 78 ~RendererSchedulerImpl() override; |
| 79 | 79 |
| 80 // RendererScheduler implementation: | 80 // RendererScheduler implementation: |
| 81 std::unique_ptr<blink::WebThread> CreateMainThread() override; | 81 std::unique_ptr<WebThread> CreateMainThread() override; |
| 82 scoped_refptr<TaskQueue> DefaultTaskRunner() override; | 82 scoped_refptr<TaskQueue> DefaultTaskRunner() override; |
| 83 scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner() override; | 83 scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner() override; |
| 84 scoped_refptr<TaskQueue> CompositorTaskRunner() override; | 84 scoped_refptr<TaskQueue> CompositorTaskRunner() override; |
| 85 scoped_refptr<TaskQueue> LoadingTaskRunner() override; | 85 scoped_refptr<TaskQueue> LoadingTaskRunner() override; |
| 86 scoped_refptr<TaskQueue> TimerTaskRunner() override; | 86 scoped_refptr<TaskQueue> TimerTaskRunner() override; |
| 87 scoped_refptr<TaskQueue> NewLoadingTaskRunner(const char* name) override; | 87 scoped_refptr<TaskQueue> NewLoadingTaskRunner(const char* name) override; |
| 88 scoped_refptr<TaskQueue> NewTimerTaskRunner(const char* name) override; | 88 scoped_refptr<TaskQueue> NewTimerTaskRunner(const char* name) override; |
| 89 scoped_refptr<TaskQueue> NewUnthrottledTaskRunner(const char* name) override; | 89 scoped_refptr<TaskQueue> NewUnthrottledTaskRunner(const char* name) override; |
| 90 std::unique_ptr<RenderWidgetSchedulingState> NewRenderWidgetSchedulingState() | 90 std::unique_ptr<RenderWidgetSchedulingState> NewRenderWidgetSchedulingState() |
| 91 override; | 91 override; |
| 92 void WillBeginFrame(const cc::BeginFrameArgs& args) override; | 92 void WillBeginFrame(const cc::BeginFrameArgs& args) override; |
| 93 void BeginFrameNotExpectedSoon() override; | 93 void BeginFrameNotExpectedSoon() override; |
| 94 void DidCommitFrameToCompositor() override; | 94 void DidCommitFrameToCompositor() override; |
| 95 void DidHandleInputEventOnCompositorThread( | 95 void DidHandleInputEventOnCompositorThread( |
| 96 const blink::WebInputEvent& web_input_event, | 96 const WebInputEvent& web_input_event, |
| 97 InputEventState event_state) override; | 97 InputEventState event_state) override; |
| 98 void DidHandleInputEventOnMainThread( | 98 void DidHandleInputEventOnMainThread( |
| 99 const blink::WebInputEvent& web_input_event) override; | 99 const WebInputEvent& web_input_event) override; |
| 100 void DidAnimateForInputOnCompositorThread() override; | 100 void DidAnimateForInputOnCompositorThread() override; |
| 101 void OnRendererBackgrounded() override; | 101 void OnRendererBackgrounded() override; |
| 102 void OnRendererForegrounded() override; | 102 void OnRendererForegrounded() override; |
| 103 void SuspendRenderer() override; | 103 void SuspendRenderer() override; |
| 104 void AddPendingNavigation( | 104 void AddPendingNavigation(WebScheduler::NavigatingFrameType type) override; |
| 105 blink::WebScheduler::NavigatingFrameType type) override; | 105 void RemovePendingNavigation(WebScheduler::NavigatingFrameType type) override; |
| 106 void RemovePendingNavigation( | |
| 107 blink::WebScheduler::NavigatingFrameType type) override; | |
| 108 void OnNavigationStarted() override; | 106 void OnNavigationStarted() override; |
| 109 bool IsHighPriorityWorkAnticipated() override; | 107 bool IsHighPriorityWorkAnticipated() override; |
| 110 bool ShouldYieldForHighPriorityWork() override; | 108 bool ShouldYieldForHighPriorityWork() override; |
| 111 bool CanExceedIdleDeadlineIfRequired() const override; | 109 bool CanExceedIdleDeadlineIfRequired() const override; |
| 112 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override; | 110 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override; |
| 113 void RemoveTaskObserver( | 111 void RemoveTaskObserver( |
| 114 base::MessageLoop::TaskObserver* task_observer) override; | 112 base::MessageLoop::TaskObserver* task_observer) override; |
| 115 void Shutdown() override; | 113 void Shutdown() override; |
| 116 void SuspendTimerQueue() override; | 114 void SuspendTimerQueue() override; |
| 117 void ResumeTimerQueue() override; | 115 void ResumeTimerQueue() override; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 void OnIdlePeriodEnded() override; | 236 void OnIdlePeriodEnded() override; |
| 239 | 237 |
| 240 void EndIdlePeriod(); | 238 void EndIdlePeriod(); |
| 241 | 239 |
| 242 // Returns the serialized scheduler state for tracing. | 240 // Returns the serialized scheduler state for tracing. |
| 243 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue( | 241 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue( |
| 244 base::TimeTicks optional_now) const; | 242 base::TimeTicks optional_now) const; |
| 245 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValueLocked( | 243 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValueLocked( |
| 246 base::TimeTicks optional_now) const; | 244 base::TimeTicks optional_now) const; |
| 247 | 245 |
| 248 static bool ShouldPrioritizeInputEvent( | 246 static bool ShouldPrioritizeInputEvent(const WebInputEvent& web_input_event); |
| 249 const blink::WebInputEvent& web_input_event); | |
| 250 | 247 |
| 251 // The amount of time which idle periods can continue being scheduled when the | 248 // The amount of time which idle periods can continue being scheduled when the |
| 252 // renderer has been hidden, before going to sleep for good. | 249 // renderer has been hidden, before going to sleep for good. |
| 253 static const int kEndIdleWhenHiddenDelayMillis = 10000; | 250 static const int kEndIdleWhenHiddenDelayMillis = 10000; |
| 254 | 251 |
| 255 // The amount of time for which loading tasks will be prioritized over | 252 // The amount of time for which loading tasks will be prioritized over |
| 256 // other tasks during the initial page load. | 253 // other tasks during the initial page load. |
| 257 static const int kRailsInitialLoadingPrioritizationMillis = 1000; | 254 static const int kRailsInitialLoadingPrioritizationMillis = 1000; |
| 258 | 255 |
| 259 // The amount of time in milliseconds we have to respond to user input as | 256 // 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... |
| 305 // Helper for computing the use case. |expected_usecase_duration| will be | 302 // Helper for computing the use case. |expected_usecase_duration| will be |
| 306 // filled with the amount of time after which the use case should be updated | 303 // filled with the amount of time after which the use case should be updated |
| 307 // again. If the duration is zero, a new use case update should not be | 304 // again. If the duration is zero, a new use case update should not be |
| 308 // scheduled. Must be called with |any_thread_lock_| held. Can be called from | 305 // scheduled. Must be called with |any_thread_lock_| held. Can be called from |
| 309 // any thread. | 306 // any thread. |
| 310 UseCase ComputeCurrentUseCase( | 307 UseCase ComputeCurrentUseCase( |
| 311 base::TimeTicks now, | 308 base::TimeTicks now, |
| 312 base::TimeDelta* expected_use_case_duration) const; | 309 base::TimeDelta* expected_use_case_duration) const; |
| 313 | 310 |
| 314 // An input event of some sort happened, the policy may need updating. | 311 // An input event of some sort happened, the policy may need updating. |
| 315 void UpdateForInputEventOnCompositorThread(blink::WebInputEvent::Type type, | 312 void UpdateForInputEventOnCompositorThread(WebInputEvent::Type type, |
| 316 InputEventState input_event_state); | 313 InputEventState input_event_state); |
| 317 | 314 |
| 318 // Returns true if there has been at least one idle period in the last | 315 // Returns true if there has been at least one idle period in the last |
| 319 // |kIdlePeriodStarvationThresholdMillis|. | 316 // |kIdlePeriodStarvationThresholdMillis|. |
| 320 bool HadAnIdlePeriodRecently(base::TimeTicks now) const; | 317 bool HadAnIdlePeriodRecently(base::TimeTicks now) const; |
| 321 | 318 |
| 322 // Helpers for safely suspending/resuming the timer queue after a | 319 // Helpers for safely suspending/resuming the timer queue after a |
| 323 // background/foreground signal. | 320 // background/foreground signal. |
| 324 void SuspendTimerQueueWhenBackgrounded(); | 321 void SuspendTimerQueueWhenBackgrounded(); |
| 325 void ResumeTimerQueueWhenForegrounded(); | 322 void ResumeTimerQueueWhenForegrounded(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 bool begin_main_frame_on_critical_path; | 411 bool begin_main_frame_on_critical_path; |
| 415 bool last_gesture_was_compositor_driven; | 412 bool last_gesture_was_compositor_driven; |
| 416 bool default_gesture_prevented; | 413 bool default_gesture_prevented; |
| 417 bool have_seen_touchstart; | 414 bool have_seen_touchstart; |
| 418 }; | 415 }; |
| 419 | 416 |
| 420 struct CompositorThreadOnly { | 417 struct CompositorThreadOnly { |
| 421 CompositorThreadOnly(); | 418 CompositorThreadOnly(); |
| 422 ~CompositorThreadOnly(); | 419 ~CompositorThreadOnly(); |
| 423 | 420 |
| 424 blink::WebInputEvent::Type last_input_type; | 421 WebInputEvent::Type last_input_type; |
| 425 std::unique_ptr<base::ThreadChecker> compositor_thread_checker; | 422 std::unique_ptr<base::ThreadChecker> compositor_thread_checker; |
| 426 | 423 |
| 427 void CheckOnValidThread() { | 424 void CheckOnValidThread() { |
| 428 #if DCHECK_IS_ON() | 425 #if DCHECK_IS_ON() |
| 429 // We don't actually care which thread this called from, just so long as | 426 // We don't actually care which thread this called from, just so long as |
| 430 // its consistent. | 427 // its consistent. |
| 431 if (!compositor_thread_checker) | 428 if (!compositor_thread_checker) |
| 432 compositor_thread_checker.reset(new base::ThreadChecker()); | 429 compositor_thread_checker.reset(new base::ThreadChecker()); |
| 433 DCHECK(compositor_thread_checker->CalledOnValidThread()); | 430 DCHECK(compositor_thread_checker->CalledOnValidThread()); |
| 434 #endif | 431 #endif |
| (...skipping 30 matching lines...) Expand all Loading... |
| 465 return compositor_thread_only_; | 462 return compositor_thread_only_; |
| 466 } | 463 } |
| 467 | 464 |
| 468 PollableThreadSafeFlag policy_may_need_update_; | 465 PollableThreadSafeFlag policy_may_need_update_; |
| 469 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; | 466 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; |
| 470 | 467 |
| 471 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); | 468 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); |
| 472 }; | 469 }; |
| 473 | 470 |
| 474 } // namespace scheduler | 471 } // namespace scheduler |
| 472 } // namespace blink |
| 475 | 473 |
| 476 #endif // COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_IMPL_H_ | 474 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_RENDERER_SCHEDU
LER_IMPL_H_ |
| OLD | NEW |