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

Side by Side Diff: third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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/ServiceWorkerGlobalScopeProxy.h" 31 #include "web/ServiceWorkerGlobalScopeProxy.h"
32 32
33 #include <memory>
34 #include <utility>
33 #include "bindings/core/v8/SourceLocation.h" 35 #include "bindings/core/v8/SourceLocation.h"
34 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" 36 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
35 #include "core/dom/Document.h" 37 #include "core/dom/Document.h"
36 #include "core/dom/ExecutionContext.h" 38 #include "core/dom/ExecutionContext.h"
37 #include "core/dom/ExecutionContextTask.h" 39 #include "core/dom/ExecutionContextTask.h"
38 #include "core/dom/MessagePort.h" 40 #include "core/dom/MessagePort.h"
41 #include "core/dom/TaskRunnerHelper.h"
39 #include "core/inspector/ConsoleMessage.h" 42 #include "core/inspector/ConsoleMessage.h"
40 #include "core/origin_trials/OriginTrials.h" 43 #include "core/origin_trials/OriginTrials.h"
41 #include "core/workers/ParentFrameTaskRunners.h"
42 #include "core/workers/WorkerGlobalScope.h" 44 #include "core/workers/WorkerGlobalScope.h"
43 #include "core/workers/WorkerThread.h" 45 #include "core/workers/WorkerThread.h"
44 #include "modules/background_sync/SyncEvent.h" 46 #include "modules/background_sync/SyncEvent.h"
45 #include "modules/fetch/Headers.h" 47 #include "modules/fetch/Headers.h"
46 #include "modules/notifications/Notification.h" 48 #include "modules/notifications/Notification.h"
47 #include "modules/notifications/NotificationEvent.h" 49 #include "modules/notifications/NotificationEvent.h"
48 #include "modules/notifications/NotificationEventInit.h" 50 #include "modules/notifications/NotificationEventInit.h"
49 #include "modules/payments/PaymentAppRequest.h" 51 #include "modules/payments/PaymentAppRequest.h"
50 #include "modules/payments/PaymentAppRequestConversion.h" 52 #include "modules/payments/PaymentAppRequestConversion.h"
51 #include "modules/payments/PaymentRequestEvent.h" 53 #include "modules/payments/PaymentRequestEvent.h"
(...skipping 11 matching lines...) Expand all
63 #include "platform/RuntimeEnabledFeatures.h" 65 #include "platform/RuntimeEnabledFeatures.h"
64 #include "public/platform/modules/notifications/WebNotificationData.h" 66 #include "public/platform/modules/notifications/WebNotificationData.h"
65 #include "public/platform/modules/serviceworker/WebServiceWorkerEventResult.h" 67 #include "public/platform/modules/serviceworker/WebServiceWorkerEventResult.h"
66 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h" 68 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h"
67 #include "public/web/WebSerializedScriptValue.h" 69 #include "public/web/WebSerializedScriptValue.h"
68 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h" 70 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h"
69 #include "web/WebEmbeddedWorkerImpl.h" 71 #include "web/WebEmbeddedWorkerImpl.h"
70 #include "wtf/Assertions.h" 72 #include "wtf/Assertions.h"
71 #include "wtf/Functional.h" 73 #include "wtf/Functional.h"
72 #include "wtf/PtrUtil.h" 74 #include "wtf/PtrUtil.h"
73 #include <memory>
74 #include <utility>
75 75
76 namespace blink { 76 namespace blink {
77 77
78 ServiceWorkerGlobalScopeProxy* ServiceWorkerGlobalScopeProxy::create( 78 ServiceWorkerGlobalScopeProxy* ServiceWorkerGlobalScopeProxy::create(
79 WebEmbeddedWorkerImpl& embeddedWorker, 79 WebEmbeddedWorkerImpl& embeddedWorker,
80 Document& document, 80 Document& document,
81 WebServiceWorkerContextClient& client) { 81 WebServiceWorkerContextClient& client) {
82 return new ServiceWorkerGlobalScopeProxy(embeddedWorker, document, client); 82 return new ServiceWorkerGlobalScopeProxy(embeddedWorker, document, client);
83 } 83 }
84 84
85 ServiceWorkerGlobalScopeProxy::~ServiceWorkerGlobalScopeProxy() { 85 ServiceWorkerGlobalScopeProxy::~ServiceWorkerGlobalScopeProxy() {
86 // Verify that the proxy has been detached. 86 // Verify that the proxy has been detached.
87 DCHECK(!m_embeddedWorker); 87 DCHECK(!m_embeddedWorker);
88 } 88 }
89 89
90 DEFINE_TRACE(ServiceWorkerGlobalScopeProxy) { 90 DEFINE_TRACE(ServiceWorkerGlobalScopeProxy) {
91 visitor->trace(m_document); 91 visitor->trace(m_document);
92 visitor->trace(m_parentFrameTaskRunners);
93 visitor->trace(m_pendingPreloadFetchEvents); 92 visitor->trace(m_pendingPreloadFetchEvents);
94 } 93 }
95 94
96 void ServiceWorkerGlobalScopeProxy::setRegistration( 95 void ServiceWorkerGlobalScopeProxy::setRegistration(
97 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle) { 96 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle) {
98 workerGlobalScope()->setRegistration(std::move(handle)); 97 workerGlobalScope()->setRegistration(std::move(handle));
99 } 98 }
100 99
101 void ServiceWorkerGlobalScopeProxy::dispatchActivateEvent(int eventID) { 100 void ServiceWorkerGlobalScopeProxy::dispatchActivateEvent(int eventID) {
102 WaitUntilObserver* observer = WaitUntilObserver::create( 101 WaitUntilObserver* observer = WaitUntilObserver::create(
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 SourceLocation* location) { 382 SourceLocation* location) {
384 client().reportConsoleMessage(source, level, message, location->lineNumber(), 383 client().reportConsoleMessage(source, level, message, location->lineNumber(),
385 location->url()); 384 location->url());
386 } 385 }
387 386
388 void ServiceWorkerGlobalScopeProxy::postMessageToPageInspector( 387 void ServiceWorkerGlobalScopeProxy::postMessageToPageInspector(
389 const String& message) { 388 const String& message) {
390 DCHECK(m_embeddedWorker); 389 DCHECK(m_embeddedWorker);
391 // The TaskType of Inspector tasks need to be Unthrottled because they need to 390 // The TaskType of Inspector tasks need to be Unthrottled because they need to
392 // run even on a suspended page. 391 // run even on a suspended page.
393 m_parentFrameTaskRunners->get(TaskType::Unthrottled) 392 FrameTaskRunnerHelper::get(TaskType::Unthrottled, m_workerGlobalScope.get())
394 ->postTask( 393 ->postTask(
395 BLINK_FROM_HERE, 394 BLINK_FROM_HERE,
396 crossThreadBind(&WebEmbeddedWorkerImpl::postMessageToPageInspector, 395 crossThreadBind(&WebEmbeddedWorkerImpl::postMessageToPageInspector,
397 crossThreadUnretained(m_embeddedWorker), message)); 396 crossThreadUnretained(m_embeddedWorker), message));
398 } 397 }
399 398
400 void ServiceWorkerGlobalScopeProxy::didCreateWorkerGlobalScope( 399 void ServiceWorkerGlobalScopeProxy::didCreateWorkerGlobalScope(
401 WorkerOrWorkletGlobalScope* workerGlobalScope) { 400 WorkerOrWorkletGlobalScope* workerGlobalScope) {
402 DCHECK(!m_workerGlobalScope); 401 DCHECK(!m_workerGlobalScope);
403 m_workerGlobalScope = 402 m_workerGlobalScope =
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 } 449 }
451 450
452 ServiceWorkerGlobalScopeProxy::ServiceWorkerGlobalScopeProxy( 451 ServiceWorkerGlobalScopeProxy::ServiceWorkerGlobalScopeProxy(
453 WebEmbeddedWorkerImpl& embeddedWorker, 452 WebEmbeddedWorkerImpl& embeddedWorker,
454 Document& document, 453 Document& document,
455 WebServiceWorkerContextClient& client) 454 WebServiceWorkerContextClient& client)
456 : m_embeddedWorker(&embeddedWorker), 455 : m_embeddedWorker(&embeddedWorker),
457 m_document(&document), 456 m_document(&document),
458 m_client(&client), 457 m_client(&client),
459 m_workerGlobalScope(nullptr) { 458 m_workerGlobalScope(nullptr) {
460 // ServiceWorker can sometimes run tasks that are initiated by/associated with
461 // a document's frame but these documents can be from a different process. So
462 // we intentionally populate the task runners with null document in order to
463 // use the thread's default task runner. Note that |m_document| should not be
464 // used as it's a dummy document for loading that doesn't represent the frame
465 // of any associated document.
466 m_parentFrameTaskRunners = ParentFrameTaskRunners::create(nullptr);
467 } 459 }
468 460
469 void ServiceWorkerGlobalScopeProxy::detach() { 461 void ServiceWorkerGlobalScopeProxy::detach() {
470 m_embeddedWorker = nullptr; 462 m_embeddedWorker = nullptr;
471 m_document = nullptr; 463 m_document = nullptr;
472 m_client = nullptr; 464 m_client = nullptr;
473 m_workerGlobalScope = nullptr; 465 m_workerGlobalScope = nullptr;
474 } 466 }
475 467
476 WebServiceWorkerContextClient& ServiceWorkerGlobalScopeProxy::client() const { 468 WebServiceWorkerContextClient& ServiceWorkerGlobalScopeProxy::client() const {
477 DCHECK(m_client); 469 DCHECK(m_client);
478 return *m_client; 470 return *m_client;
479 } 471 }
480 472
481 Document& ServiceWorkerGlobalScopeProxy::document() const { 473 Document& ServiceWorkerGlobalScopeProxy::document() const {
482 DCHECK(m_document); 474 DCHECK(m_document);
483 return *m_document; 475 return *m_document;
484 } 476 }
485 477
486 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope() 478 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope()
487 const { 479 const {
488 DCHECK(m_workerGlobalScope); 480 DCHECK(m_workerGlobalScope);
489 return m_workerGlobalScope; 481 return m_workerGlobalScope;
490 } 482 }
491 483
492 } // namespace blink 484 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.h ('k') | third_party/WebKit/Source/web/WebEmbeddedWorkerImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698