[renderer]: Inform the RendererScheduler when the Renderer is hidden.
[chromium-blink-merge.git] / content / renderer / scheduler / renderer_scheduler.h
blob25bec501f4d6acb43b1b4b217e01cf53f7fb4be9
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 CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_H_
6 #define CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_H_
8 #include "base/message_loop/message_loop.h"
9 #include "content/child/scheduler/single_thread_idle_task_runner.h"
10 #include "content/common/content_export.h"
11 #include "third_party/WebKit/public/web/WebInputEvent.h"
13 namespace cc {
14 struct BeginFrameArgs;
17 namespace content {
19 class CONTENT_EXPORT RendererScheduler {
20 public:
21 virtual ~RendererScheduler();
22 static scoped_ptr<RendererScheduler> Create();
24 // Returns the default task runner.
25 virtual scoped_refptr<base::SingleThreadTaskRunner> DefaultTaskRunner() = 0;
27 // Returns the compositor task runner.
28 virtual scoped_refptr<base::SingleThreadTaskRunner>
29 CompositorTaskRunner() = 0;
31 // Returns the idle task runner. Tasks posted to this runner may be reordered
32 // relative to other task types and may be starved for an arbitrarily long
33 // time if no idle time is available.
34 virtual scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner() = 0;
36 // Returns the loading task runner. This queue is intended for tasks related
37 // to resource dispatch, foreground HTML parsing, etc...
38 virtual scoped_refptr<base::SingleThreadTaskRunner> LoadingTaskRunner() = 0;
40 // Called to notify about the start of an extended period where no frames
41 // need to be drawn. Must be called from the main thread.
42 virtual void BeginFrameNotExpectedSoon() = 0;
44 // Called to notify about the start of a new frame. Must be called from the
45 // main thread.
46 virtual void WillBeginFrame(const cc::BeginFrameArgs& args) = 0;
48 // Called to notify that a previously begun frame was committed. Must be
49 // called from the main thread.
50 virtual void DidCommitFrameToCompositor() = 0;
52 // Tells the scheduler that the system received an input event. Called by the
53 // compositor (impl) thread.
54 virtual void DidReceiveInputEventOnCompositorThread(
55 const blink::WebInputEvent& web_input_event) = 0;
57 // Tells the scheduler that the system is displaying an input animation (e.g.
58 // a fling). Called by the compositor (impl) thread.
59 virtual void DidAnimateForInputOnCompositorThread() = 0;
61 // Tells the scheduler that all render widgets managed by this renderer
62 // process have been hidden. The renderer is assumed to be visible when the
63 // scheduler is constructed. Must be called on the main thread.
64 virtual void OnRendererHidden() = 0;
66 // Tells the scheduler that at least one render widget managed by this
67 // renderer process has become visible and the renderer is no longer hidden.
68 // The renderer is assumed to be visible when the scheduler is constructed.
69 // Must be called on the main thread.
70 virtual void OnRendererVisible() = 0;
72 // Returns true if the scheduler has reason to believe that high priority work
73 // may soon arrive on the main thread, e.g., if gesture events were observed
74 // recently.
75 // Must be called from the main thread.
76 virtual bool IsHighPriorityWorkAnticipated() = 0;
78 // Returns true if there is high priority work pending on the main thread
79 // and the caller should yield to let the scheduler service that work. Note
80 // that this is a stricter condition than |IsHighPriorityWorkAnticipated|,
81 // restricted to the case where real work is pending.
82 // Must be called from the main thread.
83 virtual bool ShouldYieldForHighPriorityWork() = 0;
85 // Returns true if a currently running idle task could exceed its deadline
86 // without impacting user experience too much. This should only be used if
87 // there is a task which cannot be pre-empted and is likely to take longer
88 // than the largest expected idle task deadline. It should NOT be polled to
89 // check whether more work can be performed on the current idle task after
90 // its deadline has expired - post a new idle task for the continuation of the
91 // work in this case.
92 // Must be called from the main thread.
93 virtual bool CanExceedIdleDeadlineIfRequired() const = 0;
95 // Adds or removes a task observer from the scheduler. The observer will be
96 // notified before and after every executed task. These functions can only be
97 // called on the main thread.
98 virtual void AddTaskObserver(
99 base::MessageLoop::TaskObserver* task_observer) = 0;
100 virtual void RemoveTaskObserver(
101 base::MessageLoop::TaskObserver* task_observer) = 0;
103 // Shuts down the scheduler by dropping any remaining pending work in the work
104 // queues. After this call any work posted to the task runners will be
105 // silently dropped.
106 virtual void Shutdown() = 0;
108 protected:
109 RendererScheduler();
110 DISALLOW_COPY_AND_ASSIGN(RendererScheduler);
113 } // namespace content
115 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_H_