| 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 "wtf/Allocator.h" | 9 #include "wtf/Allocator.h" |
| 10 #include "wtf/HashTraits.h" |
| 10 | 11 |
| 11 namespace blink { | 12 namespace blink { |
| 12 | 13 |
| 13 class Document; | 14 class Document; |
| 14 class ExecutionContext; | 15 class ExecutionContext; |
| 15 class LocalFrame; | 16 class LocalFrame; |
| 16 class ScriptState; | 17 class ScriptState; |
| 17 class WebTaskRunner; | 18 class WebTaskRunner; |
| 18 | 19 |
| 19 enum class TaskType { | 20 enum class TaskType : unsigned { |
| 20 // Speced tasks and related internal tasks should be posted to one of | 21 // Speced tasks and related internal tasks should be posted to one of |
| 21 // the following task runners. These task runners may be throttled. | 22 // the following task runners. These task runners may be throttled. |
| 22 DOMManipulation, | 23 DOMManipulation, |
| 23 UserInteraction, | 24 UserInteraction, |
| 24 Networking, | 25 Networking, |
| 25 HistoryTraversal, | 26 HistoryTraversal, |
| 26 Embed, | 27 Embed, |
| 27 MediaElementEvent, | 28 MediaElementEvent, |
| 28 CanvasBlobSerialization, | 29 CanvasBlobSerialization, |
| 29 Microtask, | 30 Microtask, |
| 30 Timer, | 31 Timer, |
| 31 RemoteEvent, | 32 RemoteEvent, |
| 32 WebSocket, | 33 WebSocket, |
| 33 PostedMessage, | 34 PostedMessage, |
| 34 UnshippedPortMessage, | 35 UnshippedPortMessage, |
| 35 | 36 |
| 36 // Other internal tasks that cannot fit any of the above task runners | 37 // Other internal tasks that cannot fit any of the above task runners |
| 37 // can be posted here, but the usage is not encouraged. The task runner | 38 // can be posted here, but the usage is not encouraged. The task runner |
| 38 // may be throttled. | 39 // may be throttled. |
| 39 Internal, | 40 Internal, |
| 40 | 41 |
| 41 // Tasks that must not be throttled should be posted here, but the usage | 42 // Tasks that must not be throttled should be posted here, but the usage |
| 42 // should be very limited. | 43 // should be very limited. |
| 43 Unthrottled, | 44 Unthrottled, |
| 44 }; | 45 }; |
| 45 | 46 |
| 47 // HashTraits for TaskType. |
| 48 struct TaskTypeTraits : WTF::GenericHashTraits<TaskType> { |
| 49 static const bool emptyValueIsZero = false; |
| 50 static TaskType emptyValue() { return static_cast<TaskType>(-1); } |
| 51 static void constructDeletedValue(TaskType& slot, bool) { slot = static_cast
<TaskType>(-2); } |
| 52 static bool isDeletedValue(TaskType value) { return value == static_cast<Tas
kType>(-2); } |
| 53 }; |
| 54 |
| 46 class CORE_EXPORT TaskRunnerHelper final { | 55 class CORE_EXPORT TaskRunnerHelper final { |
| 47 STATIC_ONLY(TaskRunnerHelper); | 56 STATIC_ONLY(TaskRunnerHelper); |
| 48 public: | 57 public: |
| 49 static WebTaskRunner* get(TaskType, LocalFrame*); | 58 static WebTaskRunner* get(TaskType, LocalFrame*); |
| 50 static WebTaskRunner* get(TaskType, Document*); | 59 static WebTaskRunner* get(TaskType, Document*); |
| 51 static WebTaskRunner* get(TaskType, ExecutionContext*); | 60 static WebTaskRunner* get(TaskType, ExecutionContext*); |
| 52 static WebTaskRunner* get(TaskType, ScriptState*); | 61 static WebTaskRunner* get(TaskType, ScriptState*); |
| 53 | 62 |
| 54 // TODO(haraken): Remove the following APIs. | 63 // TODO(haraken): Remove the following APIs. |
| 55 static WebTaskRunner* getUnthrottledTaskRunner(LocalFrame*); | 64 static WebTaskRunner* getUnthrottledTaskRunner(LocalFrame*); |
| 56 static WebTaskRunner* getTimerTaskRunner(LocalFrame*); | 65 static WebTaskRunner* getTimerTaskRunner(LocalFrame*); |
| 57 static WebTaskRunner* getLoadingTaskRunner(LocalFrame*); | 66 static WebTaskRunner* getLoadingTaskRunner(LocalFrame*); |
| 58 static WebTaskRunner* getUnthrottledTaskRunner(Document*); | 67 static WebTaskRunner* getUnthrottledTaskRunner(Document*); |
| 59 static WebTaskRunner* getTimerTaskRunner(Document*); | 68 static WebTaskRunner* getTimerTaskRunner(Document*); |
| 60 static WebTaskRunner* getLoadingTaskRunner(Document*); | 69 static WebTaskRunner* getLoadingTaskRunner(Document*); |
| 61 static WebTaskRunner* getUnthrottledTaskRunner(ExecutionContext*); | 70 static WebTaskRunner* getUnthrottledTaskRunner(ExecutionContext*); |
| 62 static WebTaskRunner* getUnthrottledTaskRunner(ScriptState*); | 71 static WebTaskRunner* getUnthrottledTaskRunner(ScriptState*); |
| 63 }; | 72 }; |
| 64 | 73 |
| 65 } // namespace blink | 74 } // namespace blink |
| 66 | 75 |
| 67 #endif | 76 #endif |
| OLD | NEW |