OLD | NEW |
---|---|
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/frame/LocalFrame.h" | 8 #include "core/frame/LocalFrame.h" |
9 #include "core/workers/WorkerOrWorkletGlobalScope.h" | |
10 #include "core/workers/WorkerThread.h" | |
9 #include "platform/WebFrameScheduler.h" | 11 #include "platform/WebFrameScheduler.h" |
10 #include "platform/WebTaskRunner.h" | 12 #include "platform/WebTaskRunner.h" |
11 #include "public/platform/Platform.h" | 13 #include "public/platform/Platform.h" |
12 #include "public/platform/WebThread.h" | 14 #include "public/platform/WebThread.h" |
13 | 15 |
14 namespace blink { | 16 namespace blink { |
15 | 17 |
16 RefPtr<WebTaskRunner> TaskRunnerHelper::get(TaskType type, LocalFrame* frame) { | 18 RefPtr<WebTaskRunner> TaskRunnerHelper::get(TaskType type, LocalFrame* frame) { |
17 // TODO(haraken): Optimize the mapping from TaskTypes to task runners. | 19 // TODO(haraken): Optimize the mapping from TaskTypes to task runners. |
18 switch (type) { | 20 switch (type) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 return nullptr; | 57 return nullptr; |
56 } | 58 } |
57 | 59 |
58 RefPtr<WebTaskRunner> TaskRunnerHelper::get(TaskType type, Document* document) { | 60 RefPtr<WebTaskRunner> TaskRunnerHelper::get(TaskType type, Document* document) { |
59 return get(type, document ? document->frame() : nullptr); | 61 return get(type, document ? document->frame() : nullptr); |
60 } | 62 } |
61 | 63 |
62 RefPtr<WebTaskRunner> TaskRunnerHelper::get( | 64 RefPtr<WebTaskRunner> TaskRunnerHelper::get( |
63 TaskType type, | 65 TaskType type, |
64 ExecutionContext* executionContext) { | 66 ExecutionContext* executionContext) { |
65 return get(type, executionContext && executionContext->isDocument() | 67 if (!executionContext) |
66 ? static_cast<Document*>(executionContext) | 68 return get(type, static_cast<Document*>(nullptr)); |
kinuko
2017/04/10 06:30:06
You can/should use ToDocument instead.
nhiroki
2017/04/11 10:47:54
Done.
| |
67 : nullptr); | 69 if (executionContext->isDocument()) |
70 return get(type, static_cast<Document*>(executionContext)); | |
71 if (executionContext->isWorkerOrWorkletGlobalScope()) { | |
72 return get( | |
73 type, | |
74 static_cast<WorkerOrWorkletGlobalScope*>(executionContext)->thread()); | |
75 } | |
76 return get(type, static_cast<Document*>(nullptr)); | |
68 } | 77 } |
69 | 78 |
70 RefPtr<WebTaskRunner> TaskRunnerHelper::get(TaskType type, | 79 RefPtr<WebTaskRunner> TaskRunnerHelper::get(TaskType type, |
71 ScriptState* scriptState) { | 80 ScriptState* scriptState) { |
72 return get(type, scriptState ? scriptState->getExecutionContext() : nullptr); | 81 return get(type, scriptState ? scriptState->getExecutionContext() : nullptr); |
73 } | 82 } |
74 | 83 |
84 RefPtr<WebTaskRunner> TaskRunnerHelper::get(TaskType type, | |
85 WorkerThread* workerThread) { | |
kinuko
2017/04/10 06:30:06
Could this just take WorkerOrWorkletGlobalScope in
nhiroki
2017/04/11 10:47:54
We could do the same thing as ParentFrameTaskRunne
kinuko
2017/04/12 09:47:44
Sorry my comment was probably unclear, what I felt
| |
86 switch (type) { | |
87 case TaskType::Timer: | |
88 case TaskType::UnspecedLoading: | |
89 case TaskType::Networking: | |
90 case TaskType::DatabaseAccess: | |
91 case TaskType::DOMManipulation: | |
92 case TaskType::UserInteraction: | |
93 case TaskType::HistoryTraversal: | |
94 case TaskType::Embed: | |
95 case TaskType::MediaElementEvent: | |
96 case TaskType::CanvasBlobSerialization: | |
97 case TaskType::RemoteEvent: | |
98 case TaskType::WebSocket: | |
99 case TaskType::Microtask: | |
100 case TaskType::PostedMessage: | |
101 case TaskType::UnshippedPortMessage: | |
102 case TaskType::FileReading: | |
103 case TaskType::Presentation: | |
104 case TaskType::Sensor: | |
105 case TaskType::PerformanceTimeline: | |
106 case TaskType::WebGL: | |
107 case TaskType::UnspecedTimer: | |
108 case TaskType::MiscPlatformAPI: | |
109 case TaskType::Unthrottled: | |
110 return workerThread->globalScopeScheduler()->unthrottledTaskRunner(); | |
kinuko
2017/04/10 06:30:06
Would be nice to have some comments as 'unthrottle
Sami
2017/04/10 16:58:10
+1
| |
111 } | |
112 NOTREACHED(); | |
113 return nullptr; | |
114 } | |
115 | |
75 } // namespace blink | 116 } // namespace blink |
OLD | NEW |