Index: third_party/WebKit/Source/core/dom/TaskRunnerHelper.cpp |
diff --git a/third_party/WebKit/Source/core/dom/TaskRunnerHelper.cpp b/third_party/WebKit/Source/core/dom/TaskRunnerHelper.cpp |
index 1a1cd884f8c88fa051d8d28d5eb2e60333289e23..dc573a5973e0ff34a4ff4ca95b94235cd440c221 100644 |
--- a/third_party/WebKit/Source/core/dom/TaskRunnerHelper.cpp |
+++ b/third_party/WebKit/Source/core/dom/TaskRunnerHelper.cpp |
@@ -7,6 +7,8 @@ |
#include "core/dom/Document.h" |
#include "core/dom/ExecutionContext.h" |
#include "core/frame/LocalFrame.h" |
+#include "core/workers/WorkerOrWorkletGlobalScope.h" |
+#include "core/workers/WorkerThread.h" |
#include "platform/WebFrameScheduler.h" |
#include "platform/WebTaskRunner.h" |
#include "public/platform/Platform.h" |
@@ -64,10 +66,15 @@ RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, Document* document) { |
RefPtr<WebTaskRunner> TaskRunnerHelper::Get( |
TaskType type, |
- ExecutionContext* execution_context) { |
- return Get(type, execution_context && execution_context->IsDocument() |
- ? static_cast<Document*>(execution_context) |
- : nullptr); |
+ ExecutionContext* executionContext) { |
+ if (!executionContext) |
+ return Get(type, ToDocument(executionContext)); |
+ if (executionContext->IsDocument()) |
+ return Get(type, ToDocument(executionContext)); |
+ if (executionContext->IsWorkerOrWorkletGlobalScope()) |
+ return Get(type, ToWorkerOrWorkletGlobalScope(executionContext)); |
+ executionContext = nullptr; |
+ return Get(type, ToDocument(executionContext)); |
} |
RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, |
@@ -76,4 +83,49 @@ RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, |
script_state ? ExecutionContext::From(script_state) : nullptr); |
} |
+RefPtr<WebTaskRunner> TaskRunnerHelper::Get( |
+ TaskType type, |
+ WorkerOrWorkletGlobalScope* global_scope) { |
+ DCHECK(global_scope); |
+ // TODO(nhiroki): Add |DCHECK(global_scope->IsContextThread())| here after |
+ // https://crbug.com/694925 is fixed. |
+ return Get(type, global_scope->GetThread()); |
+} |
+ |
+RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, |
+ WorkerThread* worker_thread) { |
+ switch (type) { |
+ case TaskType::kDOMManipulation: |
+ case TaskType::kUserInteraction: |
+ case TaskType::kNetworking: |
+ case TaskType::kHistoryTraversal: |
+ case TaskType::kEmbed: |
+ case TaskType::kMediaElementEvent: |
+ case TaskType::kCanvasBlobSerialization: |
+ case TaskType::kMicrotask: |
+ case TaskType::kTimer: |
+ case TaskType::kRemoteEvent: |
+ case TaskType::kWebSocket: |
+ case TaskType::kPostedMessage: |
+ case TaskType::kUnshippedPortMessage: |
+ case TaskType::kFileReading: |
+ case TaskType::kDatabaseAccess: |
+ case TaskType::kPresentation: |
+ case TaskType::kSensor: |
+ case TaskType::kPerformanceTimeline: |
+ case TaskType::kWebGL: |
+ case TaskType::kMiscPlatformAPI: |
+ case TaskType::kUnspecedTimer: |
+ case TaskType::kUnspecedLoading: |
+ case TaskType::kUnthrottled: |
+ // UnthrottledTaskRunner is generally discouraged in future. |
+ // TODO(nhiroki): Identify which tasks can be throttled / suspendable and |
+ // move them into other task runners. See also comments in |
+ // Get(LocalFrame). (https://crbug.com/670534) |
+ return worker_thread->GetGlobalScopeScheduler()->UnthrottledTaskRunner(); |
+ } |
+ NOTREACHED(); |
+ return nullptr; |
+} |
+ |
} // namespace blink |