Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 30 matching lines...) Expand all Loading... | |
| 41 #include "core/dom/MessagePort.h" | 41 #include "core/dom/MessagePort.h" |
| 42 #include "core/events/MessageEvent.h" | 42 #include "core/events/MessageEvent.h" |
| 43 #include "modules/serviceworkers/RegistrationOptionList.h" | 43 #include "modules/serviceworkers/RegistrationOptionList.h" |
| 44 #include "modules/serviceworkers/ServiceWorker.h" | 44 #include "modules/serviceworkers/ServiceWorker.h" |
| 45 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" | 45 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" |
| 46 #include "modules/serviceworkers/ServiceWorkerError.h" | 46 #include "modules/serviceworkers/ServiceWorkerError.h" |
| 47 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | 47 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
| 48 #include "platform/RuntimeEnabledFeatures.h" | 48 #include "platform/RuntimeEnabledFeatures.h" |
| 49 #include "public/platform/WebServiceWorker.h" | 49 #include "public/platform/WebServiceWorker.h" |
| 50 #include "public/platform/WebServiceWorkerProvider.h" | 50 #include "public/platform/WebServiceWorkerProvider.h" |
| 51 #include "public/platform/WebServiceWorkerRegistration.h" | |
| 51 #include "public/platform/WebString.h" | 52 #include "public/platform/WebString.h" |
| 52 #include "public/platform/WebURL.h" | 53 #include "public/platform/WebURL.h" |
| 53 | 54 |
| 54 using blink::WebServiceWorker; | |
| 55 using blink::WebServiceWorkerProvider; | |
| 56 | |
| 57 namespace blink { | 55 namespace blink { |
| 58 | 56 |
| 59 PassRefPtrWillBeRawPtr<ServiceWorkerContainer> ServiceWorkerContainer::create(Ex ecutionContext* executionContext) | 57 PassRefPtrWillBeRawPtr<ServiceWorkerContainer> ServiceWorkerContainer::create(Ex ecutionContext* executionContext) |
| 60 { | 58 { |
| 61 return adoptRefWillBeNoop(new ServiceWorkerContainer(executionContext)); | 59 return adoptRefWillBeNoop(new ServiceWorkerContainer(executionContext)); |
| 62 } | 60 } |
| 63 | 61 |
| 64 ServiceWorkerContainer::~ServiceWorkerContainer() | 62 ServiceWorkerContainer::~ServiceWorkerContainer() |
| 65 { | 63 { |
| 66 ASSERT(!m_provider); | 64 ASSERT(!m_provider); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 | 209 |
| 212 // If the WebServiceWorker is up for adoption (does not have a | 210 // If the WebServiceWorker is up for adoption (does not have a |
| 213 // WebServiceWorkerProxy owner), rejects the adoption by deleting the | 211 // WebServiceWorkerProxy owner), rejects the adoption by deleting the |
| 214 // WebServiceWorker. | 212 // WebServiceWorker. |
| 215 static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker) | 213 static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker) |
| 216 { | 214 { |
| 217 if (serviceWorker && !serviceWorker->proxy()) | 215 if (serviceWorker && !serviceWorker->proxy()) |
| 218 delete serviceWorker; | 216 delete serviceWorker; |
| 219 } | 217 } |
| 220 | 218 |
| 219 static void deleteIfNoExistingOwner(WebServiceWorkerRegistration* registration) | |
| 220 { | |
| 221 if (registration && !registration->proxy()) | |
| 222 delete registration; | |
| 223 } | |
| 224 | |
| 225 void ServiceWorkerContainer::setReady(WebServiceWorkerRegistration* registration ) | |
|
michaeln
2014/09/03 22:27:29
should there be an assertion here that registratio
nhiroki
2014/09/04 08:55:58
Done.
| |
| 226 { | |
| 227 if (!executionContext()) { | |
| 228 deleteIfNoExistingOwner(registration); | |
| 229 return; | |
| 230 } | |
| 231 | |
| 232 RefPtrWillBeRawPtr<ServiceWorkerRegistration> previousReadyRegistration = m_ readyRegistration; | |
|
michaeln
2014/09/03 22:27:29
is it ever expected that the previous reg is not n
nhiroki
2014/09/04 08:55:58
I think the previous reg could be non-null, for ex
nhiroki
2014/09/04 10:45:10
Ah, you're right! The previous reg should always b
nhiroki
2014/09/04 13:06:57
Done. Removed checkReadyChanged() and added ASSERT
| |
| 233 m_readyRegistration = ServiceWorkerRegistration::from(executionContext(), re gistration); | |
| 234 checkReadyChanged(previousReadyRegistration.release()); | |
| 235 } | |
| 236 | |
| 221 void ServiceWorkerContainer::setActive(WebServiceWorker* serviceWorker) | 237 void ServiceWorkerContainer::setActive(WebServiceWorker* serviceWorker) |
| 222 { | 238 { |
| 223 if (!executionContext()) { | 239 if (!executionContext()) { |
| 224 deleteIfNoExistingOwner(serviceWorker); | 240 deleteIfNoExistingOwner(serviceWorker); |
| 225 return; | 241 return; |
| 226 } | 242 } |
| 227 RefPtrWillBeRawPtr<ServiceWorker> previousReadyWorker = m_active; | |
| 228 m_active = ServiceWorker::from(executionContext(), serviceWorker); | 243 m_active = ServiceWorker::from(executionContext(), serviceWorker); |
| 229 checkReadyChanged(previousReadyWorker.release()); | |
| 230 } | 244 } |
| 231 | 245 |
| 232 void ServiceWorkerContainer::checkReadyChanged(PassRefPtrWillBeRawPtr<ServiceWor ker> previousReadyWorker) | 246 void ServiceWorkerContainer::checkReadyChanged(PassRefPtrWillBeRawPtr<ServiceWor kerRegistration> previousReadyRegistration) |
| 233 { | 247 { |
| 234 ServiceWorker* currentReadyWorker = m_active.get(); | 248 ServiceWorkerRegistration* currentReadyRegistration = m_readyRegistration.ge t(); |
| 235 | 249 |
| 236 if (previousReadyWorker == currentReadyWorker) | 250 if (previousReadyRegistration == currentReadyRegistration) |
| 237 return; | 251 return; |
| 238 | 252 |
| 239 if (m_ready->state() != ReadyProperty::Pending) { | 253 if (m_ready->state() != ReadyProperty::Pending) { |
| 240 // Already resolved Promises are now stale because the | 254 // Already resolved Promises are now stale because the |
| 241 // ready worker changed | 255 // ready registration changed |
| 242 m_ready = createReadyProperty(); | 256 m_ready = createReadyProperty(); |
| 243 } | 257 } |
| 244 | 258 |
| 245 if (currentReadyWorker) | 259 if (currentReadyRegistration) |
| 246 m_ready->resolve(currentReadyWorker); | 260 m_ready->resolve(currentReadyRegistration); |
| 247 } | 261 } |
| 248 | 262 |
| 249 void ServiceWorkerContainer::setController(WebServiceWorker* serviceWorker) | 263 void ServiceWorkerContainer::setController(WebServiceWorker* serviceWorker) |
| 250 { | 264 { |
| 251 if (!executionContext()) { | 265 if (!executionContext()) { |
| 252 deleteIfNoExistingOwner(serviceWorker); | 266 deleteIfNoExistingOwner(serviceWorker); |
| 253 return; | 267 return; |
| 254 } | 268 } |
| 255 m_controller = ServiceWorker::from(executionContext(), serviceWorker); | 269 m_controller = ServiceWorker::from(executionContext(), serviceWorker); |
| 256 } | 270 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 m_ready = createReadyProperty(); | 309 m_ready = createReadyProperty(); |
| 296 | 310 |
| 297 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) { | 311 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) { |
| 298 m_provider = client->provider(); | 312 m_provider = client->provider(); |
| 299 if (m_provider) | 313 if (m_provider) |
| 300 m_provider->setClient(this); | 314 m_provider->setClient(this); |
| 301 } | 315 } |
| 302 } | 316 } |
| 303 | 317 |
| 304 } // namespace blink | 318 } // namespace blink |
| OLD | NEW |