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

Side by Side Diff: third_party/WebKit/Source/web/WebSharedWorkerImpl.cpp

Issue 2716853002: (WIP) Worker: Merge ParentFrameTaskRunners into TaskRunnerHelper
Patch Set: WIP Created 3 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "web/WebSharedWorkerImpl.h" 31 #include "web/WebSharedWorkerImpl.h"
32 32
33 #include <memory>
33 #include "core/dom/Document.h" 34 #include "core/dom/Document.h"
35 #include "core/dom/TaskRunnerHelper.h"
34 #include "core/events/MessageEvent.h" 36 #include "core/events/MessageEvent.h"
35 #include "core/inspector/ConsoleMessage.h" 37 #include "core/inspector/ConsoleMessage.h"
36 #include "core/inspector/InspectorInstrumentation.h" 38 #include "core/inspector/InspectorInstrumentation.h"
37 #include "core/loader/FrameLoadRequest.h" 39 #include "core/loader/FrameLoadRequest.h"
38 #include "core/loader/FrameLoader.h" 40 #include "core/loader/FrameLoader.h"
39 #include "core/workers/ParentFrameTaskRunners.h"
40 #include "core/workers/SharedWorkerGlobalScope.h" 41 #include "core/workers/SharedWorkerGlobalScope.h"
41 #include "core/workers/SharedWorkerThread.h" 42 #include "core/workers/SharedWorkerThread.h"
42 #include "core/workers/WorkerClients.h" 43 #include "core/workers/WorkerClients.h"
43 #include "core/workers/WorkerGlobalScope.h" 44 #include "core/workers/WorkerGlobalScope.h"
44 #include "core/workers/WorkerInspectorProxy.h" 45 #include "core/workers/WorkerInspectorProxy.h"
45 #include "core/workers/WorkerLoaderProxy.h" 46 #include "core/workers/WorkerLoaderProxy.h"
46 #include "core/workers/WorkerScriptLoader.h" 47 #include "core/workers/WorkerScriptLoader.h"
47 #include "core/workers/WorkerThreadStartupData.h" 48 #include "core/workers/WorkerThreadStartupData.h"
48 #include "platform/CrossThreadFunctional.h" 49 #include "platform/CrossThreadFunctional.h"
49 #include "platform/heap/Handle.h" 50 #include "platform/heap/Handle.h"
(...skipping 13 matching lines...) Expand all
63 #include "public/web/WebView.h" 64 #include "public/web/WebView.h"
64 #include "public/web/WebWorkerContentSettingsClientProxy.h" 65 #include "public/web/WebWorkerContentSettingsClientProxy.h"
65 #include "public/web/modules/serviceworker/WebServiceWorkerNetworkProvider.h" 66 #include "public/web/modules/serviceworker/WebServiceWorkerNetworkProvider.h"
66 #include "web/IndexedDBClientImpl.h" 67 #include "web/IndexedDBClientImpl.h"
67 #include "web/LocalFileSystemClient.h" 68 #include "web/LocalFileSystemClient.h"
68 #include "web/WebDataSourceImpl.h" 69 #include "web/WebDataSourceImpl.h"
69 #include "web/WebLocalFrameImpl.h" 70 #include "web/WebLocalFrameImpl.h"
70 #include "web/WorkerContentSettingsClient.h" 71 #include "web/WorkerContentSettingsClient.h"
71 #include "wtf/Functional.h" 72 #include "wtf/Functional.h"
72 #include "wtf/PtrUtil.h" 73 #include "wtf/PtrUtil.h"
73 #include <memory>
74 74
75 namespace blink { 75 namespace blink {
76 76
77 // TODO(toyoshim): Share implementation with WebEmbeddedWorkerImpl as much as 77 // TODO(toyoshim): Share implementation with WebEmbeddedWorkerImpl as much as
78 // possible. 78 // possible.
79 79
80 WebSharedWorkerImpl::WebSharedWorkerImpl(WebSharedWorkerClient* client) 80 WebSharedWorkerImpl::WebSharedWorkerImpl(WebSharedWorkerClient* client)
81 : m_webView(nullptr), 81 : m_webView(nullptr),
82 m_mainFrame(nullptr), 82 m_mainFrame(nullptr),
83 m_askedToTerminate(false), 83 m_askedToTerminate(false),
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 // The lifetime of this proxy is controlled by the worker context. 258 // The lifetime of this proxy is controlled by the worker context.
259 delete this; 259 delete this;
260 } 260 }
261 261
262 // WorkerLoaderProxyProvider ------------------------------------------------- 262 // WorkerLoaderProxyProvider -------------------------------------------------
263 263
264 void WebSharedWorkerImpl::postTaskToLoader( 264 void WebSharedWorkerImpl::postTaskToLoader(
265 const WebTraceLocation& location, 265 const WebTraceLocation& location,
266 std::unique_ptr<WTF::CrossThreadClosure> task) { 266 std::unique_ptr<WTF::CrossThreadClosure> task) {
267 DCHECK(m_workerThread->isCurrentThread()); 267 DCHECK(m_workerThread->isCurrentThread());
268 m_parentFrameTaskRunners->get(TaskType::Networking) 268 FrameTaskRunnerHelper::get(TaskType::Networking, m_workerThread.get())
269 ->postTask(FROM_HERE, std::move(task)); 269 ->postTask(FROM_HERE, std::move(task));
270 } 270 }
271 271
272 void WebSharedWorkerImpl::postTaskToWorkerGlobalScope( 272 void WebSharedWorkerImpl::postTaskToWorkerGlobalScope(
273 const WebTraceLocation& location, 273 const WebTraceLocation& location,
274 std::unique_ptr<WTF::CrossThreadClosure> task) { 274 std::unique_ptr<WTF::CrossThreadClosure> task) {
275 DCHECK(isMainThread()); 275 DCHECK(isMainThread());
276 m_workerThread->postTask(location, std::move(task)); 276 m_workerThread->postTask(location, std::move(task));
277 } 277 }
278 278
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 WorkerThreadStartupData::create( 364 WorkerThreadStartupData::create(
365 m_url, m_loadingDocument->userAgent(), m_mainScriptLoader->script(), 365 m_url, m_loadingDocument->userAgent(), m_mainScriptLoader->script(),
366 nullptr, startMode, 366 nullptr, startMode,
367 contentSecurityPolicy ? contentSecurityPolicy->headers().get() 367 contentSecurityPolicy ? contentSecurityPolicy->headers().get()
368 : nullptr, 368 : nullptr,
369 m_mainScriptLoader->getReferrerPolicy(), starterOrigin, workerClients, 369 m_mainScriptLoader->getReferrerPolicy(), starterOrigin, workerClients,
370 m_mainScriptLoader->responseAddressSpace(), 370 m_mainScriptLoader->responseAddressSpace(),
371 m_mainScriptLoader->originTrialTokens(), std::move(workerSettings), 371 m_mainScriptLoader->originTrialTokens(), std::move(workerSettings),
372 WorkerV8Settings::Default()); 372 WorkerV8Settings::Default());
373 373
374 // SharedWorker can sometimes run tasks that are initiated by/associated with
375 // a document's frame but these documents can be from a different process. So
376 // we intentionally populate the task runners with null document in order to
377 // use the thread's default task runner. Note that |m_document| should not be
378 // used as it's a dummy document for loading that doesn't represent the frame
379 // of any associated document.
380 m_parentFrameTaskRunners = ParentFrameTaskRunners::create(nullptr);
381
382 m_loaderProxy = WorkerLoaderProxy::create(this); 374 m_loaderProxy = WorkerLoaderProxy::create(this);
383 m_reportingProxy = new WebSharedWorkerReportingProxyImpl( 375 m_reportingProxy = new WebSharedWorkerReportingProxyImpl(this);
384 this, m_parentFrameTaskRunners.get());
385 m_workerThread = 376 m_workerThread =
386 SharedWorkerThread::create(m_name, m_loaderProxy, *m_reportingProxy); 377 SharedWorkerThread::create(m_name, m_loaderProxy, *m_reportingProxy);
387 InspectorInstrumentation::scriptImported(m_loadingDocument, 378 InspectorInstrumentation::scriptImported(m_loadingDocument,
388 m_mainScriptLoader->identifier(), 379 m_mainScriptLoader->identifier(),
389 m_mainScriptLoader->script()); 380 m_mainScriptLoader->script());
390 m_mainScriptLoader.clear(); 381 m_mainScriptLoader.clear();
391 382
392 workerThread()->start(std::move(startupData), m_parentFrameTaskRunners.get()); 383 // SharedWorker can sometimes run tasks that are initiated by/associated with
384 // a document's frame but these documents can be from a different process. So
385 // we intentionally populate the task runners with null document in order to
386 // use the thread's default task runner. Note that |m_document| should not be
387 // used as it's a dummy document for loading that doesn't represent the frame
388 // of any associated document.
389 workerThread()->start(std::move(startupData),
390 FrameTaskRunnersHolder::create(nullptr));
393 m_workerInspectorProxy->workerThreadCreated(toDocument(m_loadingDocument), 391 m_workerInspectorProxy->workerThreadCreated(toDocument(m_loadingDocument),
394 workerThread(), m_url); 392 workerThread(), m_url);
395 m_client->workerScriptLoaded(); 393 m_client->workerScriptLoaded();
396 } 394 }
397 395
398 void WebSharedWorkerImpl::terminateWorkerContext() { 396 void WebSharedWorkerImpl::terminateWorkerContext() {
399 DCHECK(isMainThread()); 397 DCHECK(isMainThread());
400 terminateWorkerThread(); 398 terminateWorkerThread();
401 } 399 }
402 400
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 if (devtoolsAgent) 434 if (devtoolsAgent)
437 devtoolsAgent->dispatchOnInspectorBackend(sessionId, callId, method, 435 devtoolsAgent->dispatchOnInspectorBackend(sessionId, callId, method,
438 message); 436 message);
439 } 437 }
440 438
441 WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client) { 439 WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client) {
442 return new WebSharedWorkerImpl(client); 440 return new WebSharedWorkerImpl(client);
443 } 441 }
444 442
445 } // namespace blink 443 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebSharedWorkerImpl.h ('k') | third_party/WebKit/Source/web/WebSharedWorkerReportingProxyImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698