OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef WebScheduler_h | |
6 #define WebScheduler_h | |
7 | |
8 #include "WebCommon.h" | |
9 #include "WebString.h" | |
10 #include "public/platform/WebThread.h" | |
11 #include "public/platform/WebTraceLocation.h" | |
12 #include "public/platform/WebViewScheduler.h" | |
13 | |
14 #include <memory> | |
15 | |
16 namespace blink { | |
17 | |
18 class WebTaskRunner; | |
19 | |
20 // This class is used to submit tasks and pass other information from Blink to | |
21 // the platform's scheduler. | |
22 // TODO(skyostil): Replace this class with RendererScheduler. | |
23 class BLINK_PLATFORM_EXPORT WebScheduler { | |
24 public: | |
25 class BLINK_PLATFORM_EXPORT InterventionReporter { | |
26 public: | |
27 virtual ~InterventionReporter() {} | |
28 | |
29 // The scheduler has performed an intervention, described by |message|, | |
30 // which should be reported to the developer. | |
31 virtual void ReportIntervention(const WebString& message) = 0; | |
32 }; | |
33 | |
34 virtual ~WebScheduler() {} | |
35 | |
36 // Called to prevent any more pending tasks from running. Must be called on | |
37 // the associated WebThread. | |
38 virtual void Shutdown() = 0; | |
39 | |
40 // Returns true if there is high priority work pending on the associated | |
41 // WebThread and the caller should yield to let the scheduler service that | |
42 // work. Must be called on the associated WebThread. | |
43 virtual bool ShouldYieldForHighPriorityWork() = 0; | |
44 | |
45 // Returns true if a currently running idle task could exceed its deadline | |
46 // without impacting user experience too much. This should only be used if | |
47 // there is a task which cannot be pre-empted and is likely to take longer | |
48 // than the largest expected idle task deadline. It should NOT be polled to | |
49 // check whether more work can be performed on the current idle task after | |
50 // its deadline has expired - post a new idle task for the continuation of | |
51 // the work in this case. | |
52 // Must be called from the associated WebThread. | |
53 virtual bool CanExceedIdleDeadlineIfRequired() = 0; | |
54 | |
55 // Schedule an idle task to run the associated WebThread. For non-critical | |
56 // tasks which may be reordered relative to other task types and may be | |
57 // starved for an arbitrarily long time if no idle time is available. | |
58 // Takes ownership of |IdleTask|. Can be called from any thread. | |
59 virtual void PostIdleTask(const WebTraceLocation&, WebThread::IdleTask*) = 0; | |
60 | |
61 // Like postIdleTask but guarantees that the posted task will not run | |
62 // nested within an already-running task. Posting an idle task as | |
63 // non-nestable may not affect when the task gets run, or it could | |
64 // make it run later than it normally would, but it won't make it | |
65 // run earlier than it normally would. | |
66 virtual void PostNonNestableIdleTask(const WebTraceLocation&, | |
67 WebThread::IdleTask*) = 0; | |
68 | |
69 // Returns a WebTaskRunner for loading tasks. Can be called from any thread. | |
70 virtual WebTaskRunner* LoadingTaskRunner() = 0; | |
71 | |
72 // Returns a WebTaskRunner for timer tasks. Can be called from any thread. | |
73 virtual WebTaskRunner* TimerTaskRunner() = 0; | |
74 | |
75 // Creates a new WebViewScheduler for a given WebView. Must be called from | |
76 // the associated WebThread. | |
77 virtual std::unique_ptr<WebViewScheduler> CreateWebViewScheduler( | |
78 InterventionReporter*, | |
79 WebViewScheduler::WebViewSchedulerSettings*) = 0; | |
80 | |
81 // Suspends the timer queue and increments the timer queue suspension count. | |
82 // May only be called from the main thread. | |
83 virtual void SuspendTimerQueue() = 0; | |
84 | |
85 // Decrements the timer queue suspension count and re-enables the timer queue | |
86 // if the suspension count is zero and the current scheduler policy allows it. | |
87 virtual void ResumeTimerQueue() = 0; | |
88 | |
89 enum class NavigatingFrameType { kMainFrame, kChildFrame }; | |
90 | |
91 // Tells the scheduler that a navigation task is pending. | |
92 // TODO(alexclarke): Long term should this be a task trait? | |
93 virtual void AddPendingNavigation(NavigatingFrameType) = 0; | |
94 | |
95 // Tells the scheduler that a navigation task is no longer pending. | |
96 virtual void RemovePendingNavigation(NavigatingFrameType) = 0; | |
97 | |
98 #ifdef INSIDE_BLINK | |
99 // Helpers for posting bound functions as tasks. | |
100 typedef Function<void(double deadline_seconds)> IdleTask; | |
101 | |
102 void PostIdleTask(const WebTraceLocation&, std::unique_ptr<IdleTask>); | |
103 void PostNonNestableIdleTask(const WebTraceLocation&, | |
104 std::unique_ptr<IdleTask>); | |
105 #endif | |
106 }; | |
107 | |
108 } // namespace blink | |
109 | |
110 #endif // WebScheduler_h | |
OLD | NEW |