| 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(TaskRunnerType type, LocalFrame* frame) |
| 17 { |
| 18 // TODO(haraken): Optimize the mapping from TaskRunnerTypes to task runners. |
| 19 switch (type) { |
| 20 case DOMManipulationTask: |
| 21 case UserInteractionTask: |
| 22 case HistoryTraversalTask: |
| 23 case EmbedTask: |
| 24 case MediaElementEventTask: |
| 25 case CanvasBlobSerializationTask: |
| 26 case RemoteEventTask: |
| 27 case WebSocketTask: |
| 28 case MicrotaskTask: |
| 29 case PostedMessageTask: |
| 30 case UnshippedPortMessageTask: |
| 31 case TimerTask: |
| 32 case InternalTask: |
| 33 return frame ? frame->frameScheduler()->timerTaskRunner() : Platform::cu
rrent()->currentThread()->getWebTaskRunner(); |
| 34 case NetworkingTask: |
| 35 return frame ? frame->frameScheduler()->loadingTaskRunner() : Platform::
current()->currentThread()->getWebTaskRunner(); |
| 36 case IdleTask: |
| 37 // TODO(haraken): Implement this. We need to expose frameScheduler()->id
leTaskRunner(). |
| 38 NOTREACHED(); |
| 39 case UnthrottledTask: |
| 40 return frame ? frame->frameScheduler()->unthrottledTaskRunner() : Platfo
rm::current()->currentThread()->getWebTaskRunner(); |
| 41 default: |
| 42 NOTREACHED(); |
| 43 } |
| 44 } |
| 45 |
| 46 WebTaskRunner* TaskRunnerHelper::get(TaskRunnerType type, Document* document) |
| 47 { |
| 48 return get(type, document ? document->frame() : nullptr); |
| 49 } |
| 50 |
| 51 WebTaskRunner* TaskRunnerHelper::get(TaskRunnerType type, ExecutionContext* exec
utionContext) |
| 52 { |
| 53 return get(type, executionContext && executionContext->isDocument() ? static
_cast<Document*>(executionContext) : nullptr); |
| 54 } |
| 55 |
| 56 WebTaskRunner* TaskRunnerHelper::get(TaskRunnerType type, ScriptState* scriptSta
te) |
| 57 { |
| 58 return get(type, scriptState ? scriptState->getExecutionContext() : nullptr)
; |
| 59 } |
| 60 |
| 16 WebTaskRunner* TaskRunnerHelper::getUnthrottledTaskRunner(LocalFrame* frame) | 61 WebTaskRunner* TaskRunnerHelper::getUnthrottledTaskRunner(LocalFrame* frame) |
| 17 { | 62 { |
| 18 return frame ? frame->frameScheduler()->unthrottledTaskRunner() : Platform::
current()->currentThread()->getWebTaskRunner(); | 63 return frame ? frame->frameScheduler()->unthrottledTaskRunner() : Platform::
current()->currentThread()->getWebTaskRunner(); |
| 19 } | 64 } |
| 20 | 65 |
| 21 WebTaskRunner* TaskRunnerHelper::getTimerTaskRunner(LocalFrame* frame) | 66 WebTaskRunner* TaskRunnerHelper::getTimerTaskRunner(LocalFrame* frame) |
| 22 { | 67 { |
| 23 return frame ? frame->frameScheduler()->timerTaskRunner() : Platform::curren
t()->currentThread()->getWebTaskRunner(); | 68 return frame ? frame->frameScheduler()->timerTaskRunner() : Platform::curren
t()->currentThread()->getWebTaskRunner(); |
| 24 } | 69 } |
| 25 | 70 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 47 { | 92 { |
| 48 return getUnthrottledTaskRunner(executionContext && executionContext->isDocu
ment() ? static_cast<Document*>(executionContext) : nullptr); | 93 return getUnthrottledTaskRunner(executionContext && executionContext->isDocu
ment() ? static_cast<Document*>(executionContext) : nullptr); |
| 49 } | 94 } |
| 50 | 95 |
| 51 WebTaskRunner* TaskRunnerHelper::getUnthrottledTaskRunner(ScriptState* scriptSta
te) | 96 WebTaskRunner* TaskRunnerHelper::getUnthrottledTaskRunner(ScriptState* scriptSta
te) |
| 52 { | 97 { |
| 53 return getUnthrottledTaskRunner(scriptState ? scriptState->getExecutionConte
xt() : nullptr); | 98 return getUnthrottledTaskRunner(scriptState ? scriptState->getExecutionConte
xt() : nullptr); |
| 54 } | 99 } |
| 55 | 100 |
| 56 } // namespace blink | 101 } // namespace blink |
| OLD | NEW |