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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_H_
6 #define COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_H_
8 #include "base/message_loop/message_loop.h"
9 #include "components/scheduler/child/child_scheduler.h"
10 #include "components/scheduler/child/single_thread_idle_task_runner.h"
11 #include "components/scheduler/scheduler_export.h"
12 #include "third_party/WebKit/public/web/WebInputEvent.h"
15 struct BeginFrameArgs
;
20 class SCHEDULER_EXPORT RendererScheduler
: public ChildScheduler
{
22 ~RendererScheduler() override
;
23 static scoped_ptr
<RendererScheduler
> Create();
25 // Returns the compositor task runner.
26 virtual scoped_refptr
<base::SingleThreadTaskRunner
>
27 CompositorTaskRunner() = 0;
29 // Keep RendererScheduler::UseCaseToString in sync with this enum.
36 // Must be the last entry.
38 FIRST_USE_CASE
= NONE
,
40 static const char* UseCaseToString(UseCase use_case
);
42 // Returns the loading task runner. This queue is intended for tasks related
43 // to resource dispatch, foreground HTML parsing, etc...
44 virtual scoped_refptr
<base::SingleThreadTaskRunner
> LoadingTaskRunner() = 0;
46 // Returns the timer task runner. This queue is intended for DOM Timers.
47 virtual scoped_refptr
<TaskQueue
> TimerTaskRunner() = 0;
49 // Called to notify about the start of an extended period where no frames
50 // need to be drawn. Must be called from the main thread.
51 virtual void BeginFrameNotExpectedSoon() = 0;
53 // Called to notify about the start of a new frame. Must be called from the
55 virtual void WillBeginFrame(const cc::BeginFrameArgs
& args
) = 0;
57 // Called to notify that a previously begun frame was committed. Must be
58 // called from the main thread.
59 virtual void DidCommitFrameToCompositor() = 0;
61 // Keep RendererScheduler::InputEventStateToString in sync with this enum.
62 enum class InputEventState
{
63 EVENT_CONSUMED_BY_COMPOSITOR
,
64 EVENT_FORWARDED_TO_MAIN_THREAD
,
66 static const char* InputEventStateToString(InputEventState input_event_state
);
68 // Tells the scheduler that the system processed an input event. Called by the
69 // compositor (impl) thread. Note it's expected that every call to
70 // DidHandleInputEventOnCompositorThread where |event_state| is
71 // EVENT_FORWARDED_TO_MAIN_THREAD will be followed by a corresponding call
72 // to DidHandleInputEventOnMainThread.
73 virtual void DidHandleInputEventOnCompositorThread(
74 const blink::WebInputEvent
& web_input_event
,
75 InputEventState event_state
) = 0;
77 // Tells the scheduler that the system processed an input event. Must be
78 // called from the main thread.
79 virtual void DidHandleInputEventOnMainThread(
80 const blink::WebInputEvent
& web_input_event
) = 0;
82 // Tells the scheduler that the system is displaying an input animation (e.g.
83 // a fling). Called by the compositor (impl) thread.
84 virtual void DidAnimateForInputOnCompositorThread() = 0;
86 // Tells the scheduler that all render widgets managed by this renderer
87 // process have been hidden. The renderer is assumed to be visible when the
88 // scheduler is constructed. Must be called on the main thread.
89 virtual void OnRendererHidden() = 0;
91 // Tells the scheduler that at least one render widget managed by this
92 // renderer process has become visible and the renderer is no longer hidden.
93 // The renderer is assumed to be visible when the scheduler is constructed.
94 // Must be called on the main thread.
95 virtual void OnRendererVisible() = 0;
97 // Tells the scheduler that the renderer process has been backgrounded, i.e.,
98 // there are no critical, user facing activities (visual, audio, etc...)
99 // driven by this process. A stricter condition than |OnRendererHidden()|, the
100 // process is assumed to be foregrounded when the scheduler is constructed.
101 // Must be called on the main thread.
102 virtual void OnRendererBackgrounded() = 0;
104 // Tells the scheduler that the renderer process has been foregrounded.
105 // This is the assumed state when the scheduler is constructed.
106 // Must be called on the main thread.
107 virtual void OnRendererForegrounded() = 0;
109 // Tells the scheduler that a page load has started. The scheduler will
110 // prioritize loading tasks for a short duration afterwards.
111 // Must be called from the main thread.
112 virtual void OnPageLoadStarted() = 0;
114 // Returns true if the scheduler has reason to believe that high priority work
115 // may soon arrive on the main thread, e.g., if gesture events were observed
117 // Must be called from the main thread.
118 virtual bool IsHighPriorityWorkAnticipated() = 0;
120 // Suspends the timer queue and increments the timer queue suspension count.
121 // May only be called from the main thread.
122 virtual void SuspendTimerQueue() = 0;
124 // Decrements the timer queue suspension count and re-enables the timer queue
125 // if the suspension count is zero and the current schduler policy allows it.
126 virtual void ResumeTimerQueue() = 0;
128 // Sets whether to allow suspension of timers after the backgrounded signal is
129 // received via OnRendererBackgrounded. Defaults to disabled.
130 virtual void SetTimerQueueSuspensionWhenBackgroundedEnabled(bool enabled
) = 0;
134 DISALLOW_COPY_AND_ASSIGN(RendererScheduler
);
137 } // namespace scheduler
139 #endif // COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_H_