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 #include "core/dom/TaskRunnerHelper.h" | 5 #include "core/dom/TaskRunnerHelper.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/dom/ExecutionContext.h" | 8 #include "core/dom/ExecutionContext.h" |
9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
10 #include "core/workers/WorkerOrWorkletGlobalScope.h" | |
11 #include "core/workers/WorkerThread.h" | |
12 #include "platform/WebFrameScheduler.h" | 10 #include "platform/WebFrameScheduler.h" |
13 #include "platform/WebTaskRunner.h" | 11 #include "platform/WebTaskRunner.h" |
14 #include "public/platform/Platform.h" | 12 #include "public/platform/Platform.h" |
15 #include "public/platform/WebThread.h" | 13 #include "public/platform/WebThread.h" |
16 | 14 |
17 namespace blink { | 15 namespace blink { |
18 | 16 |
19 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, LocalFrame* frame) { | 17 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, LocalFrame* frame) { |
20 // TODO(haraken): Optimize the mapping from TaskTypes to task runners. | 18 // TODO(haraken): Optimize the mapping from TaskTypes to task runners. |
21 switch (type) { | 19 switch (type) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 NOTREACHED(); | 57 NOTREACHED(); |
60 return nullptr; | 58 return nullptr; |
61 } | 59 } |
62 | 60 |
63 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, Document* document) { | 61 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, Document* document) { |
64 return Get(type, document ? document->GetFrame() : nullptr); | 62 return Get(type, document ? document->GetFrame() : nullptr); |
65 } | 63 } |
66 | 64 |
67 RefPtr<WebTaskRunner> TaskRunnerHelper::Get( | 65 RefPtr<WebTaskRunner> TaskRunnerHelper::Get( |
68 TaskType type, | 66 TaskType type, |
69 ExecutionContext* executionContext) { | 67 ExecutionContext* execution_context) { |
70 if (!executionContext) | 68 return Get(type, execution_context && execution_context->IsDocument() |
71 return Get(type, ToDocument(executionContext)); | 69 ? static_cast<Document*>(execution_context) |
72 if (executionContext->IsDocument()) | 70 : nullptr); |
73 return Get(type, ToDocument(executionContext)); | |
74 if (executionContext->IsWorkerOrWorkletGlobalScope()) | |
75 return Get(type, ToWorkerOrWorkletGlobalScope(executionContext)); | |
76 executionContext = nullptr; | |
77 return Get(type, ToDocument(executionContext)); | |
78 } | 71 } |
79 | 72 |
80 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, | 73 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, |
81 ScriptState* script_state) { | 74 ScriptState* script_state) { |
82 return Get(type, | 75 return Get(type, |
83 script_state ? ExecutionContext::From(script_state) : nullptr); | 76 script_state ? ExecutionContext::From(script_state) : nullptr); |
84 } | 77 } |
85 | 78 |
86 RefPtr<WebTaskRunner> TaskRunnerHelper::Get( | |
87 TaskType type, | |
88 WorkerOrWorkletGlobalScope* global_scope) { | |
89 DCHECK(global_scope); | |
90 // TODO(nhiroki): Add |DCHECK(global_scope->IsContextThread())| here after | |
91 // https://crbug.com/694925 is fixed. | |
92 return Get(type, global_scope->GetThread()); | |
93 } | |
94 | |
95 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, | |
96 WorkerThread* worker_thread) { | |
97 switch (type) { | |
98 case TaskType::kDOMManipulation: | |
99 case TaskType::kUserInteraction: | |
100 case TaskType::kNetworking: | |
101 case TaskType::kHistoryTraversal: | |
102 case TaskType::kEmbed: | |
103 case TaskType::kMediaElementEvent: | |
104 case TaskType::kCanvasBlobSerialization: | |
105 case TaskType::kMicrotask: | |
106 case TaskType::kTimer: | |
107 case TaskType::kRemoteEvent: | |
108 case TaskType::kWebSocket: | |
109 case TaskType::kPostedMessage: | |
110 case TaskType::kUnshippedPortMessage: | |
111 case TaskType::kFileReading: | |
112 case TaskType::kDatabaseAccess: | |
113 case TaskType::kPresentation: | |
114 case TaskType::kSensor: | |
115 case TaskType::kPerformanceTimeline: | |
116 case TaskType::kWebGL: | |
117 case TaskType::kMiscPlatformAPI: | |
118 case TaskType::kUnspecedTimer: | |
119 case TaskType::kUnspecedLoading: | |
120 case TaskType::kUnthrottled: | |
121 // UnthrottledTaskRunner is generally discouraged in future. | |
122 // TODO(nhiroki): Identify which tasks can be throttled / suspendable and | |
123 // move them into other task runners. See also comments in | |
124 // Get(LocalFrame). (https://crbug.com/670534) | |
125 return worker_thread->GetGlobalScopeScheduler()->UnthrottledTaskRunner(); | |
126 } | |
127 NOTREACHED(); | |
128 return nullptr; | |
129 } | |
130 | |
131 } // namespace blink | 79 } // namespace blink |
OLD | NEW |