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

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

Issue 2513413003: Worker: Provide a way to access parent frame task runners from a worker thread (Closed)
Patch Set: update comments Created 4 years 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 20 matching lines...) Expand all
31 #include "web/ServiceWorkerGlobalScopeProxy.h" 31 #include "web/ServiceWorkerGlobalScopeProxy.h"
32 32
33 #include "bindings/core/v8/SourceLocation.h" 33 #include "bindings/core/v8/SourceLocation.h"
34 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" 34 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
35 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
36 #include "core/dom/ExecutionContext.h" 36 #include "core/dom/ExecutionContext.h"
37 #include "core/dom/ExecutionContextTask.h" 37 #include "core/dom/ExecutionContextTask.h"
38 #include "core/dom/MessagePort.h" 38 #include "core/dom/MessagePort.h"
39 #include "core/inspector/ConsoleMessage.h" 39 #include "core/inspector/ConsoleMessage.h"
40 #include "core/origin_trials/OriginTrials.h" 40 #include "core/origin_trials/OriginTrials.h"
41 #include "core/workers/ParentFrameTaskRunners.h"
41 #include "core/workers/WorkerGlobalScope.h" 42 #include "core/workers/WorkerGlobalScope.h"
42 #include "core/workers/WorkerThread.h" 43 #include "core/workers/WorkerThread.h"
43 #include "modules/background_sync/SyncEvent.h" 44 #include "modules/background_sync/SyncEvent.h"
44 #include "modules/fetch/Headers.h" 45 #include "modules/fetch/Headers.h"
45 #include "modules/notifications/Notification.h" 46 #include "modules/notifications/Notification.h"
46 #include "modules/notifications/NotificationEvent.h" 47 #include "modules/notifications/NotificationEvent.h"
47 #include "modules/notifications/NotificationEventInit.h" 48 #include "modules/notifications/NotificationEventInit.h"
48 #include "modules/push_messaging/PushEvent.h" 49 #include "modules/push_messaging/PushEvent.h"
49 #include "modules/push_messaging/PushMessageData.h" 50 #include "modules/push_messaging/PushMessageData.h"
50 #include "modules/serviceworkers/ExtendableEvent.h" 51 #include "modules/serviceworkers/ExtendableEvent.h"
(...skipping 28 matching lines...) Expand all
79 return new ServiceWorkerGlobalScopeProxy(embeddedWorker, document, client); 80 return new ServiceWorkerGlobalScopeProxy(embeddedWorker, document, client);
80 } 81 }
81 82
82 ServiceWorkerGlobalScopeProxy::~ServiceWorkerGlobalScopeProxy() { 83 ServiceWorkerGlobalScopeProxy::~ServiceWorkerGlobalScopeProxy() {
83 // Verify that the proxy has been detached. 84 // Verify that the proxy has been detached.
84 DCHECK(!m_embeddedWorker); 85 DCHECK(!m_embeddedWorker);
85 } 86 }
86 87
87 DEFINE_TRACE(ServiceWorkerGlobalScopeProxy) { 88 DEFINE_TRACE(ServiceWorkerGlobalScopeProxy) {
88 visitor->trace(m_document); 89 visitor->trace(m_document);
90 visitor->trace(m_parentFrameTaskRunners);
89 visitor->trace(m_pendingPreloadFetchEvents); 91 visitor->trace(m_pendingPreloadFetchEvents);
90 } 92 }
91 93
92 void ServiceWorkerGlobalScopeProxy::setRegistration( 94 void ServiceWorkerGlobalScopeProxy::setRegistration(
93 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle) { 95 std::unique_ptr<WebServiceWorkerRegistration::Handle> handle) {
94 workerGlobalScope()->setRegistration(std::move(handle)); 96 workerGlobalScope()->setRegistration(std::move(handle));
95 } 97 }
96 98
97 void ServiceWorkerGlobalScopeProxy::dispatchActivateEvent(int eventID) { 99 void ServiceWorkerGlobalScopeProxy::dispatchActivateEvent(int eventID) {
98 WaitUntilObserver* observer = WaitUntilObserver::create( 100 WaitUntilObserver* observer = WaitUntilObserver::create(
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 352
351 void ServiceWorkerGlobalScopeProxy::postMessageToPageInspector( 353 void ServiceWorkerGlobalScopeProxy::postMessageToPageInspector(
352 const String& message) { 354 const String& message) {
353 DCHECK(m_embeddedWorker); 355 DCHECK(m_embeddedWorker);
354 document().postInspectorTask( 356 document().postInspectorTask(
355 BLINK_FROM_HERE, 357 BLINK_FROM_HERE,
356 createCrossThreadTask(&WebEmbeddedWorkerImpl::postMessageToPageInspector, 358 createCrossThreadTask(&WebEmbeddedWorkerImpl::postMessageToPageInspector,
357 crossThreadUnretained(m_embeddedWorker), message)); 359 crossThreadUnretained(m_embeddedWorker), message));
358 } 360 }
359 361
362 ParentFrameTaskRunners*
363 ServiceWorkerGlobalScopeProxy::getParentFrameTaskRunners() {
364 return m_parentFrameTaskRunners.get();
365 }
366
360 void ServiceWorkerGlobalScopeProxy::didCreateWorkerGlobalScope( 367 void ServiceWorkerGlobalScopeProxy::didCreateWorkerGlobalScope(
361 WorkerOrWorkletGlobalScope* workerGlobalScope) { 368 WorkerOrWorkletGlobalScope* workerGlobalScope) {
362 DCHECK(!m_workerGlobalScope); 369 DCHECK(!m_workerGlobalScope);
363 m_workerGlobalScope = 370 m_workerGlobalScope =
364 static_cast<ServiceWorkerGlobalScope*>(workerGlobalScope); 371 static_cast<ServiceWorkerGlobalScope*>(workerGlobalScope);
365 client().workerContextStarted(this); 372 client().workerContextStarted(this);
366 } 373 }
367 374
368 void ServiceWorkerGlobalScopeProxy::didInitializeWorkerContext() { 375 void ServiceWorkerGlobalScopeProxy::didInitializeWorkerContext() {
369 ScriptState::Scope scope( 376 ScriptState::Scope scope(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 client().workerContextDestroyed(); 416 client().workerContextDestroyed();
410 } 417 }
411 418
412 ServiceWorkerGlobalScopeProxy::ServiceWorkerGlobalScopeProxy( 419 ServiceWorkerGlobalScopeProxy::ServiceWorkerGlobalScopeProxy(
413 WebEmbeddedWorkerImpl& embeddedWorker, 420 WebEmbeddedWorkerImpl& embeddedWorker,
414 Document& document, 421 Document& document,
415 WebServiceWorkerContextClient& client) 422 WebServiceWorkerContextClient& client)
416 : m_embeddedWorker(&embeddedWorker), 423 : m_embeddedWorker(&embeddedWorker),
417 m_document(&document), 424 m_document(&document),
418 m_client(&client), 425 m_client(&client),
419 m_workerGlobalScope(nullptr) {} 426 m_workerGlobalScope(nullptr) {
427 // ServiceWorker is never associated with any document's frame. We have a
falken 2016/11/28 01:37:44 "never associated" may be confusing since typicall
nhiroki 2016/11/28 02:26:59 Updated the comments.
428 // dummy document for loading but it doesn't really represent the frame of
429 // associated document(s). Here we intentionally populate the task runners
430 // with null document that will end up using the thread's default task runner.
431 m_parentFrameTaskRunners = ParentFrameTaskRunners::create(nullptr);
432 }
420 433
421 void ServiceWorkerGlobalScopeProxy::detach() { 434 void ServiceWorkerGlobalScopeProxy::detach() {
422 m_embeddedWorker = nullptr; 435 m_embeddedWorker = nullptr;
423 m_document = nullptr; 436 m_document = nullptr;
424 m_client = nullptr; 437 m_client = nullptr;
425 m_workerGlobalScope = nullptr; 438 m_workerGlobalScope = nullptr;
426 } 439 }
427 440
428 WebServiceWorkerContextClient& ServiceWorkerGlobalScopeProxy::client() const { 441 WebServiceWorkerContextClient& ServiceWorkerGlobalScopeProxy::client() const {
429 DCHECK(m_client); 442 DCHECK(m_client);
430 return *m_client; 443 return *m_client;
431 } 444 }
432 445
433 Document& ServiceWorkerGlobalScopeProxy::document() const { 446 Document& ServiceWorkerGlobalScopeProxy::document() const {
434 DCHECK(m_document); 447 DCHECK(m_document);
435 return *m_document; 448 return *m_document;
436 } 449 }
437 450
438 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope() 451 ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeProxy::workerGlobalScope()
439 const { 452 const {
440 DCHECK(m_workerGlobalScope); 453 DCHECK(m_workerGlobalScope);
441 return m_workerGlobalScope; 454 return m_workerGlobalScope;
442 } 455 }
443 456
444 } // namespace blink 457 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.h ('k') | third_party/WebKit/Source/web/WebSharedWorkerImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698