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

Side by Side Diff: Source/modules/serviceworkers/ServiceWorkerContainer.cpp

Issue 1317473002: ServiceWorker: Clean up ownership management of WebServiceWorkerRegistration (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: incorporate review comment Created 5 years, 3 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 | Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 #include "public/platform/modules/serviceworker/WebServiceWorkerRegistration.h" 57 #include "public/platform/modules/serviceworker/WebServiceWorkerRegistration.h"
58 58
59 namespace blink { 59 namespace blink {
60 60
61 class RegistrationCallback : public WebServiceWorkerProvider::WebServiceWorkerRe gistrationCallbacks { 61 class RegistrationCallback : public WebServiceWorkerProvider::WebServiceWorkerRe gistrationCallbacks {
62 public: 62 public:
63 explicit RegistrationCallback(ScriptPromiseResolver* resolver) 63 explicit RegistrationCallback(ScriptPromiseResolver* resolver)
64 : m_resolver(resolver) { } 64 : m_resolver(resolver) { }
65 ~RegistrationCallback() override { } 65 ~RegistrationCallback() override { }
66 66
67 void onSuccess(WebServiceWorkerRegistration* registration) override 67 // Takes ownership of |registrationRaw|.
68 void onSuccess(WebServiceWorkerRegistration* registrationRaw) override
68 { 69 {
70 OwnPtr<WebServiceWorkerRegistration> registration = adoptPtr(registratio nRaw);
69 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) 71 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped())
70 return; 72 return;
71 m_resolver->resolve(ServiceWorkerRegistration::take(m_resolver.get(), re gistration)); 73 m_resolver->resolve(ServiceWorkerRegistration::create(m_resolver->execut ionContext(), registration.release()));
72 } 74 }
73 75
74 // Takes ownership of |errorRaw|. 76 // Takes ownership of |errorRaw|.
75 void onError(WebServiceWorkerError* errorRaw) override 77 void onError(WebServiceWorkerError* errorRaw) override
76 { 78 {
77 OwnPtr<WebServiceWorkerError> error = adoptPtr(errorRaw); 79 OwnPtr<WebServiceWorkerError> error = adoptPtr(errorRaw);
78 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) 80 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped())
79 return; 81 return;
80 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), *error)); 82 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), *error));
81 } 83 }
82 84
83 private: 85 private:
84 Persistent<ScriptPromiseResolver> m_resolver; 86 Persistent<ScriptPromiseResolver> m_resolver;
85 WTF_MAKE_NONCOPYABLE(RegistrationCallback); 87 WTF_MAKE_NONCOPYABLE(RegistrationCallback);
86 }; 88 };
87 89
88 class GetRegistrationCallback : public WebServiceWorkerProvider::WebServiceWorke rGetRegistrationCallbacks { 90 class GetRegistrationCallback : public WebServiceWorkerProvider::WebServiceWorke rGetRegistrationCallbacks {
89 public: 91 public:
90 explicit GetRegistrationCallback(ScriptPromiseResolver* resolver) 92 explicit GetRegistrationCallback(ScriptPromiseResolver* resolver)
91 : m_resolver(resolver) { } 93 : m_resolver(resolver) { }
92 ~GetRegistrationCallback() override { } 94 ~GetRegistrationCallback() override { }
93 95
94 void onSuccess(WebServiceWorkerRegistration* registration) override 96 // Takes ownership of |registrationRaw|.
97 void onSuccess(WebServiceWorkerRegistration* registrationRaw) override
95 { 98 {
99 OwnPtr<WebServiceWorkerRegistration> registration = adoptPtr(registratio nRaw);
96 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) 100 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped())
97 return; 101 return;
98 if (!registration) { 102 if (!registration) {
99 // Resolve the promise with undefined. 103 // Resolve the promise with undefined.
100 m_resolver->resolve(); 104 m_resolver->resolve();
101 return; 105 return;
102 } 106 }
103 m_resolver->resolve(ServiceWorkerRegistration::take(m_resolver.get(), re gistration)); 107 m_resolver->resolve(ServiceWorkerRegistration::create(m_resolver->execut ionContext(), registration.release()));
104 } 108 }
105 109
106 // Takes ownership of |errorRaw|. 110 // Takes ownership of |errorRaw|.
107 void onError(WebServiceWorkerError* errorRaw) override 111 void onError(WebServiceWorkerError* errorRaw) override
108 { 112 {
109 OwnPtr<WebServiceWorkerError> error = adoptPtr(errorRaw); 113 OwnPtr<WebServiceWorkerError> error = adoptPtr(errorRaw);
110 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) 114 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped())
111 return; 115 return;
112 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), *error)); 116 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), *error));
113 } 117 }
(...skipping 30 matching lines...) Expand all
144 private: 148 private:
145 Persistent<ScriptPromiseResolver> m_resolver; 149 Persistent<ScriptPromiseResolver> m_resolver;
146 WTF_MAKE_NONCOPYABLE(GetRegistrationsCallback); 150 WTF_MAKE_NONCOPYABLE(GetRegistrationsCallback);
147 }; 151 };
148 152
149 class ServiceWorkerContainer::GetRegistrationForReadyCallback : public WebServic eWorkerProvider::WebServiceWorkerGetRegistrationForReadyCallbacks { 153 class ServiceWorkerContainer::GetRegistrationForReadyCallback : public WebServic eWorkerProvider::WebServiceWorkerGetRegistrationForReadyCallbacks {
150 public: 154 public:
151 explicit GetRegistrationForReadyCallback(ReadyProperty* ready) 155 explicit GetRegistrationForReadyCallback(ReadyProperty* ready)
152 : m_ready(ready) { } 156 : m_ready(ready) { }
153 ~GetRegistrationForReadyCallback() { } 157 ~GetRegistrationForReadyCallback() { }
154 void onSuccess(WebServiceWorkerRegistration* registration) override 158
159 // Takes ownership of |registrationRaw|.
160 void onSuccess(WebServiceWorkerRegistration* registrationRaw) override
155 { 161 {
156 ASSERT(registration); 162 ASSERT(registrationRaw);
157 ASSERT(m_ready->state() == ReadyProperty::Pending); 163 ASSERT(m_ready->state() == ReadyProperty::Pending);
164
165 OwnPtr<WebServiceWorkerRegistration> registration = adoptPtr(registratio nRaw);
158 if (m_ready->executionContext() && !m_ready->executionContext()->activeD OMObjectsAreStopped()) 166 if (m_ready->executionContext() && !m_ready->executionContext()->activeD OMObjectsAreStopped())
159 m_ready->resolve(ServiceWorkerRegistration::from(m_ready->executionC ontext(), registration)); 167 m_ready->resolve(ServiceWorkerRegistration::create(m_ready->executio nContext(), registration.release()));
160 } 168 }
169
161 private: 170 private:
162 Persistent<ReadyProperty> m_ready; 171 Persistent<ReadyProperty> m_ready;
163 WTF_MAKE_NONCOPYABLE(GetRegistrationForReadyCallback); 172 WTF_MAKE_NONCOPYABLE(GetRegistrationForReadyCallback);
164 }; 173 };
165 174
166 ServiceWorkerContainer* ServiceWorkerContainer::create(ExecutionContext* executi onContext) 175 ServiceWorkerContainer* ServiceWorkerContainer::create(ExecutionContext* executi onContext)
167 { 176 {
168 return new ServiceWorkerContainer(executionContext); 177 return new ServiceWorkerContainer(executionContext);
169 } 178 }
170 179
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 return; 406 return;
398 407
399 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) { 408 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) {
400 m_provider = client->provider(); 409 m_provider = client->provider();
401 if (m_provider) 410 if (m_provider)
402 m_provider->setClient(this); 411 m_provider->setClient(this);
403 } 412 }
404 } 413 }
405 414
406 } // namespace blink 415 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698