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

Side by Side Diff: third_party/WebKit/Source/core/dom/TaskRunnerHelper.cpp

Issue 2209023002: Introduce TaskRunnerHelper::get() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: temp Created 4 years, 4 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
« no previous file with comments | « third_party/WebKit/Source/core/dom/TaskRunnerHelper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/TaskRunnerHelper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698