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

Unified Diff: third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainerClient.cpp

Issue 1518323002: Canonicalize creation of ServiceWorkerContainerClient supplement. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: compile fix Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainerTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainerClient.cpp
diff --git a/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainerClient.cpp b/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainerClient.cpp
index 13d91c7fed2d70c4dd60ed60e46526a591a93e85..964ad6f09bd44fe1e6f6fad73f496968e1f429a3 100644
--- a/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainerClient.cpp
+++ b/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainerClient.cpp
@@ -19,6 +19,11 @@ PassOwnPtrWillBeRawPtr<ServiceWorkerContainerClient> ServiceWorkerContainerClien
return adoptPtrWillBeNoop(new ServiceWorkerContainerClient(provider));
}
+ServiceWorkerContainerClient::ServiceWorkerContainerClient(PassOwnPtr<WebServiceWorkerProvider> provider)
+ : m_provider(provider)
+{
+}
+
ServiceWorkerContainerClient::~ServiceWorkerContainerClient()
{
}
@@ -30,28 +35,21 @@ const char* ServiceWorkerContainerClient::supplementName()
ServiceWorkerContainerClient* ServiceWorkerContainerClient::from(ExecutionContext* context)
{
- if (context->isDocument()) {
- Document* document = toDocument(context);
- if (!document->frame())
- return 0;
-
- ServiceWorkerContainerClient* client = static_cast<ServiceWorkerContainerClient*>(WillBeHeapSupplement<Document>::from(document, supplementName()));
- if (client)
- return client;
-
- // If it's not provided yet, create it lazily.
- document->WillBeHeapSupplementable<Document>::provideSupplement(ServiceWorkerContainerClient::supplementName(), ServiceWorkerContainerClient::create(document->frame()->loader().client()->createServiceWorkerProvider()));
- return static_cast<ServiceWorkerContainerClient*>(WillBeHeapSupplement<Document>::from(document, supplementName()));
+ if (context->isWorkerGlobalScope()) {
+ WorkerClients* clients = toWorkerGlobalScope(context)->clients();
+ ASSERT(clients);
+ return static_cast<ServiceWorkerContainerClient*>(WillBeHeapSupplement<WorkerClients>::from(clients, supplementName()));
}
-
- WorkerClients* clients = toWorkerGlobalScope(context)->clients();
- ASSERT(clients);
- return static_cast<ServiceWorkerContainerClient*>(WillBeHeapSupplement<WorkerClients>::from(clients, supplementName()));
-}
-
-ServiceWorkerContainerClient::ServiceWorkerContainerClient(PassOwnPtr<WebServiceWorkerProvider> provider)
- : m_provider(provider)
-{
+ Document* document = toDocument(context);
+ if (!document->frame())
+ return nullptr;
+
+ ServiceWorkerContainerClient* client = static_cast<ServiceWorkerContainerClient*>(WillBeHeapSupplement<Document>::from(document, supplementName()));
+ if (!client) {
+ client = new ServiceWorkerContainerClient(document->frame()->loader().client()->createServiceWorkerProvider());
+ WillBeHeapSupplement<Document>::provideTo(*document, supplementName(), adoptPtrWillBeNoop(client));
+ }
+ return client;
}
void provideServiceWorkerContainerClientToWorker(WorkerClients* clients, PassOwnPtr<WebServiceWorkerProvider> provider)
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698