OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 TaskRunnerHelper_h | 5 #ifndef TaskRunnerHelper_h |
6 #define TaskRunnerHelper_h | 6 #define TaskRunnerHelper_h |
7 | 7 |
8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
9 #include "platform/wtf/Allocator.h" | 9 #include "platform/wtf/Allocator.h" |
10 #include "platform/wtf/HashTraits.h" | 10 #include "platform/wtf/HashTraits.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 class Document; | 14 class Document; |
15 class ExecutionContext; | 15 class ExecutionContext; |
16 class LocalFrame; | 16 class LocalFrame; |
17 class ScriptState; | 17 class ScriptState; |
18 class WebTaskRunner; | 18 class WebTaskRunner; |
| 19 class WorkerOrWorkletGlobalScope; |
19 | 20 |
20 enum class TaskType : unsigned { | 21 enum class TaskType : unsigned { |
21 // Speced tasks and related internal tasks should be posted to one of | 22 // Speced tasks and related internal tasks should be posted to one of |
22 // the following task runners. These task runners may be throttled. | 23 // the following task runners. These task runners may be throttled. |
23 | 24 |
24 // https://html.spec.whatwg.org/multipage/webappapis.html#generic-task-sources | 25 // https://html.spec.whatwg.org/multipage/webappapis.html#generic-task-sources |
25 // | 26 // |
26 // This task source is used for features that react to DOM manipulations, such | 27 // This task source is used for features that react to DOM manipulations, such |
27 // as things that happen in a non-blocking fashion when an element is inserted | 28 // as things that happen in a non-blocking fashion when an element is inserted |
28 // into the document. | 29 // into the document. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 // may be throttled. | 115 // may be throttled. |
115 // | 116 // |
116 // UnspecedLoading type should be used for all tasks associated with | 117 // UnspecedLoading type should be used for all tasks associated with |
117 // loading page content, UnspecedTimer should be used for all other purposes. | 118 // loading page content, UnspecedTimer should be used for all other purposes. |
118 kUnspecedTimer, | 119 kUnspecedTimer, |
119 kUnspecedLoading, | 120 kUnspecedLoading, |
120 | 121 |
121 // Tasks that must not be throttled should be posted here, but the usage | 122 // Tasks that must not be throttled should be posted here, but the usage |
122 // should be very limited. | 123 // should be very limited. |
123 kUnthrottled, | 124 kUnthrottled, |
| 125 |
| 126 // A new task type should be added before this. |
| 127 kNumberOfTaskTypes, |
124 }; | 128 }; |
125 | 129 |
126 // HashTraits for TaskType. | 130 // HashTraits for TaskType. |
127 struct TaskTypeTraits : WTF::GenericHashTraits<TaskType> { | 131 struct TaskTypeTraits : WTF::GenericHashTraits<TaskType> { |
128 static const bool kEmptyValueIsZero = false; | 132 static const bool kEmptyValueIsZero = false; |
129 static TaskType EmptyValue() { return static_cast<TaskType>(-1); } | 133 static TaskType EmptyValue() { return static_cast<TaskType>(-1); } |
130 static void ConstructDeletedValue(TaskType& slot, bool) { | 134 static void ConstructDeletedValue(TaskType& slot, bool) { |
131 slot = static_cast<TaskType>(-2); | 135 slot = static_cast<TaskType>(-2); |
132 } | 136 } |
133 static bool IsDeletedValue(TaskType value) { | 137 static bool IsDeletedValue(TaskType value) { |
134 return value == static_cast<TaskType>(-2); | 138 return value == static_cast<TaskType>(-2); |
135 } | 139 } |
136 }; | 140 }; |
137 | 141 |
138 // A set of helper functions to get a WebTaskRunner for TaskType and a context | 142 // A set of helper functions to get a WebTaskRunner for TaskType and a context |
139 // object. The posted tasks are guaranteed to run in a sequence if they have the | 143 // object. The posted tasks are guaranteed to run in a sequence if they have the |
140 // same TaskType and the context objects belong to the same frame. | 144 // same TaskType and the context objects belong to the same frame. |
141 class CORE_EXPORT TaskRunnerHelper final { | 145 class CORE_EXPORT TaskRunnerHelper final { |
142 STATIC_ONLY(TaskRunnerHelper); | 146 STATIC_ONLY(TaskRunnerHelper); |
143 | 147 |
144 public: | 148 public: |
145 static RefPtr<WebTaskRunner> Get(TaskType, LocalFrame*); | 149 static RefPtr<WebTaskRunner> Get(TaskType, LocalFrame*); |
146 static RefPtr<WebTaskRunner> Get(TaskType, Document*); | 150 static RefPtr<WebTaskRunner> Get(TaskType, Document*); |
147 static RefPtr<WebTaskRunner> Get(TaskType, ExecutionContext*); | 151 static RefPtr<WebTaskRunner> Get(TaskType, ExecutionContext*); |
148 static RefPtr<WebTaskRunner> Get(TaskType, ScriptState*); | 152 static RefPtr<WebTaskRunner> Get(TaskType, ScriptState*); |
| 153 |
| 154 static RefPtr<WebTaskRunner> Get(TaskType, WorkerOrWorkletGlobalScope*); |
149 }; | 155 }; |
150 | 156 |
151 } // namespace blink | 157 } // namespace blink |
152 | 158 |
153 #endif | 159 #endif |
OLD | NEW |