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..cc5a87f6641c51a5c0389d8abf1d2ff39215c0a4 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)); |
haraken
2017/04/13 07:03:36
Can we simply pass nullptr?
nhiroki
2017/04/13 08:23:50
Hmmm... the clang compiler complains about the usa
|
+ if (executionContext->IsDocument()) |
+ return Get(type, ToDocument(executionContext)); |
+ if (executionContext->IsWorkerOrWorkletGlobalScope()) |
+ return Get(type, ToWorkerOrWorkletGlobalScope(executionContext)); |
+ executionContext = nullptr; |
+ return Get(type, ToDocument(executionContext)); |
haraken
2017/04/13 07:03:36
Ditto.
|
} |
RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, |
@@ -76,4 +83,48 @@ 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 should be throttled and move them |
+ // into other task runners. See also comments in Get(LocalFrame). |
+ return worker_thread->GetGlobalScopeScheduler()->UnthrottledTaskRunner(); |
+ } |
+ NOTREACHED(); |
+ return nullptr; |
+} |
+ |
} // namespace blink |