Chromium Code Reviews| Index: Source/modules/serviceworkers/ServiceWorker.cpp |
| diff --git a/Source/modules/serviceworkers/ServiceWorker.cpp b/Source/modules/serviceworkers/ServiceWorker.cpp |
| index 012f548ad6ea65cd94eccba47b332889e2864b63..2a2bce2df5710576e34a7615f6299bb0f9f35fa4 100644 |
| --- a/Source/modules/serviceworkers/ServiceWorker.cpp |
| +++ b/Source/modules/serviceworkers/ServiceWorker.cpp |
| @@ -139,19 +139,18 @@ PassRefPtrWillBeRawPtr<ServiceWorker> ServiceWorker::from(ExecutionContext* exec |
| if (!worker) |
| return nullptr; |
| - blink::WebServiceWorkerProxy* proxy = worker->proxy(); |
| - ServiceWorker* existingServiceWorker = proxy ? proxy->unwrap() : 0; |
| - if (existingServiceWorker) { |
| - ASSERT(existingServiceWorker->executionContext() == executionContext); |
| - return existingServiceWorker; |
| - } |
| - |
| - return create(executionContext, adoptPtr(worker)); |
| + RefPtr<ServiceWorker> serviceWorker = getOrCreate(executionContext, worker); |
|
tkent
2014/08/11 01:31:31
RefPtr -> RefPtrWillBeRawPtr
nhiroki
2014/08/11 02:26:06
Done.
|
| + if (serviceWorker->m_proxyState == Initial) |
| + serviceWorker->setProxyState(Ready); |
| + return serviceWorker.release(); |
| } |
| PassRefPtrWillBeRawPtr<ServiceWorker> ServiceWorker::take(ScriptPromiseResolver* resolver, WebType* worker) |
| { |
| - RefPtrWillBeRawPtr<ServiceWorker> serviceWorker = ServiceWorker::from(resolver->scriptState()->executionContext(), worker); |
| + if (!worker) |
| + return nullptr; |
| + |
| + RefPtrWillBeRawPtr<ServiceWorker> serviceWorker = getOrCreate(resolver->scriptState()->executionContext(), worker); |
| ScriptState::Scope scope(resolver->scriptState()); |
| if (serviceWorker->m_proxyState == Initial) |
| serviceWorker->waitOnPromise(resolver->promise()); |
| @@ -170,7 +169,7 @@ void ServiceWorker::setProxyState(ProxyState state) |
| return; |
| switch (m_proxyState) { |
| case Initial: |
| - ASSERT(state == RegisterPromisePending || state == ContextStopped); |
| + ASSERT(state == RegisterPromisePending || state == Ready || state == ContextStopped); |
| break; |
| case RegisterPromisePending: |
| ASSERT(state == Ready || state == ContextStopped); |
| @@ -222,9 +221,19 @@ void ServiceWorker::stop() |
| setProxyState(ContextStopped); |
| } |
| -PassRefPtrWillBeRawPtr<ServiceWorker> ServiceWorker::create(ExecutionContext* executionContext, PassOwnPtr<blink::WebServiceWorker> outerWorker) |
| +PassRefPtrWillBeRawPtr<ServiceWorker> ServiceWorker::getOrCreate(ExecutionContext* executionContext, WebType* outerWorker) |
| { |
| - RefPtrWillBeRawPtr<ServiceWorker> worker = adoptRefWillBeRefCountedGarbageCollected(new ServiceWorker(executionContext, outerWorker)); |
| + if (!outerWorker) |
| + return nullptr; |
| + |
| + blink::WebServiceWorkerProxy* proxy = outerWorker->proxy(); |
|
tkent
2014/08/11 01:31:31
Remove blink::
nhiroki
2014/08/11 02:26:06
Done.
|
| + ServiceWorker* existingServiceWorker = proxy ? proxy->unwrap() : 0; |
| + if (existingServiceWorker) { |
| + ASSERT(existingServiceWorker->executionContext() == executionContext); |
| + return existingServiceWorker; |
| + } |
| + |
| + RefPtrWillBeRawPtr<ServiceWorker> worker = adoptRefWillBeRefCountedGarbageCollected(new ServiceWorker(executionContext, adoptPtr(outerWorker))); |
| worker->suspendIfNeeded(); |
| return worker.release(); |
| } |