Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Unified Diff: third_party/WebKit/Source/core/dom/TaskRunnerHelper.cpp

Issue 2806623004: Worker: Introduce per-global-scope task scheduler (Closed)
Patch Set: remove unnecessary comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « third_party/WebKit/Source/core/dom/TaskRunnerHelper.h ('k') | third_party/WebKit/Source/core/loader/ThreadableLoaderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698