Chromium Code Reviews| 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 "public/platform/Platform.h" | 9 #include "public/platform/Platform.h" |
| 10 #include "public/platform/WebFrameScheduler.h" | 10 #include "public/platform/WebFrameScheduler.h" |
| 11 #include "public/platform/WebTaskRunner.h" | 11 #include "public/platform/WebTaskRunner.h" |
| 12 #include "public/platform/WebThread.h" | 12 #include "public/platform/WebThread.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 WebTaskRunner* TaskRunnerHelper::get(TaskType type, LocalFrame* frame) | |
| 17 { | |
| 18 // TODO(haraken): Optimize the mapping from TaskTypes to task runners. | |
| 19 switch (type) { | |
| 20 case TaskType::DOMManipulation: | |
| 21 case TaskType::UserInteraction: | |
| 22 case TaskType::HistoryTraversal: | |
| 23 case TaskType::Embed: | |
| 24 case TaskType::MediaElementEvent: | |
| 25 case TaskType::CanvasBlobSerialization: | |
| 26 case TaskType::RemoteEvent: | |
| 27 case TaskType::WebSocket: | |
|
kinuko
2016/08/11 14:21:58
IIRC some of WebSocket tasks are posted as loading
Sami
2016/08/11 14:52:46
Good point -- we probably want to fix that.
| |
| 28 case TaskType::Microtask: | |
| 29 case TaskType::PostedMessage: | |
| 30 case TaskType::UnshippedPortMessage: | |
| 31 case TaskType::Timer: | |
| 32 case TaskType::Internal: | |
| 33 return frame ? frame->frameScheduler()->timerTaskRunner() : Platform::cu rrent()->currentThread()->getWebTaskRunner(); | |
| 34 case TaskType::Networking: | |
| 35 return frame ? frame->frameScheduler()->loadingTaskRunner() : Platform:: current()->currentThread()->getWebTaskRunner(); | |
| 36 case TaskType::Unthrottled: | |
| 37 return frame ? frame->frameScheduler()->unthrottledTaskRunner() : Platfo rm::current()->currentThread()->getWebTaskRunner(); | |
| 38 default: | |
| 39 NOTREACHED(); | |
| 40 } | |
| 41 return nullptr; | |
| 42 } | |
| 43 | |
| 44 WebTaskRunner* TaskRunnerHelper::get(TaskType type, Document* document) | |
| 45 { | |
| 46 return get(type, document ? document->frame() : nullptr); | |
| 47 } | |
| 48 | |
| 49 WebTaskRunner* TaskRunnerHelper::get(TaskType type, ExecutionContext* executionC ontext) | |
| 50 { | |
| 51 return get(type, executionContext && executionContext->isDocument() ? static _cast<Document*>(executionContext) : nullptr); | |
| 52 } | |
| 53 | |
| 54 WebTaskRunner* TaskRunnerHelper::get(TaskType type, ScriptState* scriptState) | |
| 55 { | |
| 56 return get(type, scriptState ? scriptState->getExecutionContext() : nullptr) ; | |
| 57 } | |
| 58 | |
| 16 WebTaskRunner* TaskRunnerHelper::getUnthrottledTaskRunner(LocalFrame* frame) | 59 WebTaskRunner* TaskRunnerHelper::getUnthrottledTaskRunner(LocalFrame* frame) |
| 17 { | 60 { |
| 18 return frame ? frame->frameScheduler()->unthrottledTaskRunner() : Platform:: current()->currentThread()->getWebTaskRunner(); | 61 return frame ? frame->frameScheduler()->unthrottledTaskRunner() : Platform:: current()->currentThread()->getWebTaskRunner(); |
| 19 } | 62 } |
| 20 | 63 |
| 21 WebTaskRunner* TaskRunnerHelper::getTimerTaskRunner(LocalFrame* frame) | 64 WebTaskRunner* TaskRunnerHelper::getTimerTaskRunner(LocalFrame* frame) |
| 22 { | 65 { |
| 23 return frame ? frame->frameScheduler()->timerTaskRunner() : Platform::curren t()->currentThread()->getWebTaskRunner(); | 66 return frame ? frame->frameScheduler()->timerTaskRunner() : Platform::curren t()->currentThread()->getWebTaskRunner(); |
| 24 } | 67 } |
| 25 | 68 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 47 { | 90 { |
| 48 return getUnthrottledTaskRunner(executionContext && executionContext->isDocu ment() ? static_cast<Document*>(executionContext) : nullptr); | 91 return getUnthrottledTaskRunner(executionContext && executionContext->isDocu ment() ? static_cast<Document*>(executionContext) : nullptr); |
| 49 } | 92 } |
| 50 | 93 |
| 51 WebTaskRunner* TaskRunnerHelper::getUnthrottledTaskRunner(ScriptState* scriptSta te) | 94 WebTaskRunner* TaskRunnerHelper::getUnthrottledTaskRunner(ScriptState* scriptSta te) |
| 52 { | 95 { |
| 53 return getUnthrottledTaskRunner(scriptState ? scriptState->getExecutionConte xt() : nullptr); | 96 return getUnthrottledTaskRunner(scriptState ? scriptState->getExecutionConte xt() : nullptr); |
| 54 } | 97 } |
| 55 | 98 |
| 56 } // namespace blink | 99 } // namespace blink |
| OLD | NEW |