| 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/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/MainThreadWorkletGlobalScope.h" | 10 #include "core/workers/MainThreadWorkletGlobalScope.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 return Get(type, document ? document->GetFrame() : nullptr); | 73 return Get(type, document ? document->GetFrame() : nullptr); |
| 74 } | 74 } |
| 75 | 75 |
| 76 RefPtr<WebTaskRunner> TaskRunnerHelper::Get( | 76 RefPtr<WebTaskRunner> TaskRunnerHelper::Get( |
| 77 TaskType type, | 77 TaskType type, |
| 78 ExecutionContext* execution_context) { | 78 ExecutionContext* execution_context) { |
| 79 if (!execution_context) | 79 if (!execution_context) |
| 80 return Get(type, ToDocument(execution_context)); | 80 return Get(type, ToDocument(execution_context)); |
| 81 if (execution_context->IsDocument()) | 81 if (execution_context->IsDocument()) |
| 82 return Get(type, ToDocument(execution_context)); | 82 return Get(type, ToDocument(execution_context)); |
| 83 if (execution_context->IsMainThreadWorkletGlobalScope()) { | |
| 84 return Get(type, | |
| 85 ToMainThreadWorkletGlobalScope(execution_context)->GetFrame()); | |
| 86 } | |
| 87 if (execution_context->IsWorkerOrWorkletGlobalScope()) | 83 if (execution_context->IsWorkerOrWorkletGlobalScope()) |
| 88 return Get(type, ToWorkerOrWorkletGlobalScope(execution_context)); | 84 return Get(type, ToWorkerOrWorkletGlobalScope(execution_context)); |
| 89 execution_context = nullptr; | 85 execution_context = nullptr; |
| 90 return Get(type, ToDocument(execution_context)); | 86 return Get(type, ToDocument(execution_context)); |
| 91 } | 87 } |
| 92 | 88 |
| 93 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, | 89 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, |
| 94 ScriptState* script_state) { | 90 ScriptState* script_state) { |
| 95 return Get(type, | 91 return Get(type, |
| 96 script_state ? ExecutionContext::From(script_state) : nullptr); | 92 script_state ? ExecutionContext::From(script_state) : nullptr); |
| 97 } | 93 } |
| 98 | 94 |
| 99 RefPtr<WebTaskRunner> TaskRunnerHelper::Get( | 95 RefPtr<WebTaskRunner> TaskRunnerHelper::Get( |
| 100 TaskType type, | 96 TaskType type, |
| 101 WorkerOrWorkletGlobalScope* global_scope) { | 97 WorkerOrWorkletGlobalScope* global_scope) { |
| 102 DCHECK(global_scope); | 98 DCHECK(global_scope); |
| 103 DCHECK(global_scope->IsContextThread()); | 99 DCHECK(global_scope->IsContextThread()); |
| 100 if (global_scope->IsMainThreadWorkletGlobalScope()) |
| 101 return Get(type, ToMainThreadWorkletGlobalScope(global_scope)->GetFrame()); |
| 104 return Get(type, global_scope->GetThread()); | 102 return Get(type, global_scope->GetThread()); |
| 105 } | 103 } |
| 106 | 104 |
| 107 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, | 105 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, |
| 108 WorkerThread* worker_thread) { | 106 WorkerThread* worker_thread) { |
| 109 switch (type) { | 107 switch (type) { |
| 110 case TaskType::kDOMManipulation: | 108 case TaskType::kDOMManipulation: |
| 111 case TaskType::kUserInteraction: | 109 case TaskType::kUserInteraction: |
| 112 case TaskType::kNetworking: | 110 case TaskType::kNetworking: |
| 113 case TaskType::kHistoryTraversal: | 111 case TaskType::kHistoryTraversal: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 134 // TODO(nhiroki): Identify which tasks can be throttled / suspendable and | 132 // TODO(nhiroki): Identify which tasks can be throttled / suspendable and |
| 135 // move them into other task runners. See also comments in | 133 // move them into other task runners. See also comments in |
| 136 // Get(LocalFrame). (https://crbug.com/670534) | 134 // Get(LocalFrame). (https://crbug.com/670534) |
| 137 return worker_thread->GetGlobalScopeScheduler()->UnthrottledTaskRunner(); | 135 return worker_thread->GetGlobalScopeScheduler()->UnthrottledTaskRunner(); |
| 138 } | 136 } |
| 139 NOTREACHED(); | 137 NOTREACHED(); |
| 140 return nullptr; | 138 return nullptr; |
| 141 } | 139 } |
| 142 | 140 |
| 143 } // namespace blink | 141 } // namespace blink |
| OLD | NEW |