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

Side by Side 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 unified diff | Download patch
OLDNEW
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"
10 #include "platform/WebFrameScheduler.h" 12 #include "platform/WebFrameScheduler.h"
11 #include "platform/WebTaskRunner.h" 13 #include "platform/WebTaskRunner.h"
12 #include "public/platform/Platform.h" 14 #include "public/platform/Platform.h"
13 #include "public/platform/WebThread.h" 15 #include "public/platform/WebThread.h"
14 16
15 namespace blink { 17 namespace blink {
16 18
17 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, LocalFrame* frame) { 19 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, LocalFrame* frame) {
18 // TODO(haraken): Optimize the mapping from TaskTypes to task runners. 20 // TODO(haraken): Optimize the mapping from TaskTypes to task runners.
19 switch (type) { 21 switch (type) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 NOTREACHED(); 59 NOTREACHED();
58 return nullptr; 60 return nullptr;
59 } 61 }
60 62
61 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, Document* document) { 63 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, Document* document) {
62 return Get(type, document ? document->GetFrame() : nullptr); 64 return Get(type, document ? document->GetFrame() : nullptr);
63 } 65 }
64 66
65 RefPtr<WebTaskRunner> TaskRunnerHelper::Get( 67 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(
66 TaskType type, 68 TaskType type,
67 ExecutionContext* execution_context) { 69 ExecutionContext* executionContext) {
68 return Get(type, execution_context && execution_context->IsDocument() 70 if (!executionContext)
69 ? static_cast<Document*>(execution_context) 71 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
70 : nullptr); 72 if (executionContext->IsDocument())
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));
haraken 2017/04/13 07:03:36 Ditto.
71 } 78 }
72 79
73 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, 80 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type,
74 ScriptState* script_state) { 81 ScriptState* script_state) {
75 return Get(type, 82 return Get(type,
76 script_state ? ExecutionContext::From(script_state) : nullptr); 83 script_state ? ExecutionContext::From(script_state) : nullptr);
77 } 84 }
78 85
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 should be throttled and move them
123 // into other task runners. See also comments in Get(LocalFrame).
124 return worker_thread->GetGlobalScopeScheduler()->UnthrottledTaskRunner();
125 }
126 NOTREACHED();
127 return nullptr;
128 }
129
79 } // namespace blink 130 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698