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

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

Issue 2806623004: Worker: Introduce per-global-scope task scheduler (Closed)
Patch Set: remove WorkerTaskRunners 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..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

Powered by Google App Engine
This is Rietveld 408576698