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

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

Issue 2829683006: Threading: Add thread checks in TaskRunnerHelper
Patch Set: GlobalScopeScheduler / MessagePort fix (333 layout tests failed on linux_chromium_rel_ng) Created 3 years, 8 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 | « no previous file | 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/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/WorkerOrWorkletGlobalScope.h" 10 #include "core/workers/WorkerOrWorkletGlobalScope.h"
11 #include "core/workers/WorkerThread.h" 11 #include "core/workers/WorkerThread.h"
12 #include "platform/WebFrameScheduler.h" 12 #include "platform/WebFrameScheduler.h"
13 #include "platform/WebTaskRunner.h" 13 #include "platform/WebTaskRunner.h"
14 #include "public/platform/Platform.h" 14 #include "public/platform/Platform.h"
15 #include "public/platform/WebThread.h" 15 #include "public/platform/WebThread.h"
16 16
17 namespace blink { 17 namespace blink {
18 18
19 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, LocalFrame* frame) { 19 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, LocalFrame* frame) {
20 DCHECK(WTF::IsMainThread());
20 // TODO(haraken): Optimize the mapping from TaskTypes to task runners. 21 // TODO(haraken): Optimize the mapping from TaskTypes to task runners.
21 switch (type) { 22 switch (type) {
22 case TaskType::kTimer: 23 case TaskType::kTimer:
23 return frame ? frame->FrameScheduler()->TimerTaskRunner() 24 return frame ? frame->FrameScheduler()->TimerTaskRunner()
24 : Platform::Current()->CurrentThread()->GetWebTaskRunner(); 25 : Platform::Current()->CurrentThread()->GetWebTaskRunner();
25 case TaskType::kUnspecedLoading: 26 case TaskType::kUnspecedLoading:
26 case TaskType::kNetworking: 27 case TaskType::kNetworking:
27 return frame ? frame->FrameScheduler()->LoadingTaskRunner() 28 return frame ? frame->FrameScheduler()->LoadingTaskRunner()
28 : Platform::Current()->CurrentThread()->GetWebTaskRunner(); 29 : Platform::Current()->CurrentThread()->GetWebTaskRunner();
29 // Throttling following tasks may break existing web pages, so tentatively 30 // Throttling following tasks may break existing web pages, so tentatively
(...skipping 24 matching lines...) Expand all
54 case TaskType::kMiscPlatformAPI: 55 case TaskType::kMiscPlatformAPI:
55 case TaskType::kUnthrottled: 56 case TaskType::kUnthrottled:
56 return frame ? frame->FrameScheduler()->UnthrottledTaskRunner() 57 return frame ? frame->FrameScheduler()->UnthrottledTaskRunner()
57 : Platform::Current()->CurrentThread()->GetWebTaskRunner(); 58 : Platform::Current()->CurrentThread()->GetWebTaskRunner();
58 } 59 }
59 NOTREACHED(); 60 NOTREACHED();
60 return nullptr; 61 return nullptr;
61 } 62 }
62 63
63 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, Document* document) { 64 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, Document* document) {
65 DCHECK(!document || document->IsContextThread());
64 return Get(type, document ? document->GetFrame() : nullptr); 66 return Get(type, document ? document->GetFrame() : nullptr);
65 } 67 }
66 68
67 RefPtr<WebTaskRunner> TaskRunnerHelper::Get( 69 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(
68 TaskType type, 70 TaskType type,
69 ExecutionContext* executionContext) { 71 ExecutionContext* execution_context) {
70 if (!executionContext) 72 DCHECK(!execution_context || execution_context->IsContextThread());
71 return Get(type, ToDocument(executionContext)); 73 if (!execution_context || execution_context->IsDocument())
72 if (executionContext->IsDocument()) 74 return Get(type, ToDocument(execution_context));
73 return Get(type, ToDocument(executionContext)); 75 DCHECK(execution_context->IsWorkerOrWorkletGlobalScope());
74 if (executionContext->IsWorkerOrWorkletGlobalScope()) 76 return Get(type, ToWorkerOrWorkletGlobalScope(execution_context));
75 return Get(type, ToWorkerOrWorkletGlobalScope(executionContext));
76 executionContext = nullptr;
77 return Get(type, ToDocument(executionContext));
78 } 77 }
79 78
80 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type, 79 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(TaskType type,
81 ScriptState* script_state) { 80 ScriptState* script_state) {
82 return Get(type, 81 return Get(type,
83 script_state ? ExecutionContext::From(script_state) : nullptr); 82 script_state ? ExecutionContext::From(script_state) : nullptr);
84 } 83 }
85 84
86 RefPtr<WebTaskRunner> TaskRunnerHelper::Get( 85 RefPtr<WebTaskRunner> TaskRunnerHelper::Get(
87 TaskType type, 86 TaskType type,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // TODO(nhiroki): Identify which tasks can be throttled / suspendable and 120 // TODO(nhiroki): Identify which tasks can be throttled / suspendable and
122 // move them into other task runners. See also comments in 121 // move them into other task runners. See also comments in
123 // Get(LocalFrame). (https://crbug.com/670534) 122 // Get(LocalFrame). (https://crbug.com/670534)
124 return worker_thread->GetGlobalScopeScheduler()->UnthrottledTaskRunner(); 123 return worker_thread->GetGlobalScopeScheduler()->UnthrottledTaskRunner();
125 } 124 }
126 NOTREACHED(); 125 NOTREACHED();
127 return nullptr; 126 return nullptr;
128 } 127 }
129 128
130 } // namespace blink 129 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698