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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 if (exceptionState.hadException()) | 79 if (exceptionState.hadException()) |
| 80 return; | 80 return; |
| 81 | 81 |
| 82 blink::WebString messageString = message->toWireString(); | 82 blink::WebString messageString = message->toWireString(); |
| 83 OwnPtr<blink::WebMessagePortChannelArray> webChannels = MessagePort::toWebMe ssagePortChannelArray(channels.release()); | 83 OwnPtr<blink::WebMessagePortChannelArray> webChannels = MessagePort::toWebMe ssagePortChannelArray(channels.release()); |
| 84 m_outerWorker->postMessage(messageString, webChannels.leakPtr()); | 84 m_outerWorker->postMessage(messageString, webChannels.leakPtr()); |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool ServiceWorker::isReady() | 87 bool ServiceWorker::isReady() |
| 88 { | 88 { |
| 89 return !m_isPromisePending; | 89 return m_proxyState == Ready; |
| 90 } | 90 } |
| 91 | 91 |
| 92 void ServiceWorker::dispatchStateChangeEvent() | 92 void ServiceWorker::dispatchStateChangeEvent() |
| 93 { | 93 { |
| 94 ASSERT(isReady()); | 94 ASSERT(isReady()); |
| 95 this->dispatchEvent(Event::create(EventTypeNames::statechange)); | 95 this->dispatchEvent(Event::create(EventTypeNames::statechange)); |
| 96 } | 96 } |
| 97 | 97 |
| 98 String ServiceWorker::scope() const | 98 String ServiceWorker::scope() const |
| 99 { | 99 { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 } | 154 } |
| 155 | 155 |
| 156 PassRefPtr<ServiceWorker> ServiceWorker::from(ScriptPromiseResolverWithContext* resolver, WebType* worker) | 156 PassRefPtr<ServiceWorker> ServiceWorker::from(ScriptPromiseResolverWithContext* resolver, WebType* worker) |
| 157 { | 157 { |
| 158 RefPtr<ServiceWorker> serviceWorker = ServiceWorker::from(resolver->scriptSt ate()->executionContext(), worker); | 158 RefPtr<ServiceWorker> serviceWorker = ServiceWorker::from(resolver->scriptSt ate()->executionContext(), worker); |
| 159 ScriptState::Scope scope(resolver->scriptState()); | 159 ScriptState::Scope scope(resolver->scriptState()); |
| 160 serviceWorker->waitOnPromise(resolver->promise()); | 160 serviceWorker->waitOnPromise(resolver->promise()); |
| 161 return serviceWorker; | 161 return serviceWorker; |
| 162 } | 162 } |
| 163 | 163 |
| 164 void ServiceWorker::setProxyState(ProxyState state) | |
|
dominicc (has gone to gerrit)
2014/06/13 19:55:13
This is very nice and neat.
falken
2014/06/13 22:34:18
Thanks!
| |
| 165 { | |
| 166 if (m_proxyState == state) | |
| 167 return; | |
| 168 switch (m_proxyState) { | |
| 169 case Initial: | |
| 170 ASSERT(state == RegisterPromisePending || state == ContextStopped); | |
| 171 break; | |
| 172 case RegisterPromisePending: | |
| 173 ASSERT(state == Ready || state == ContextStopped); | |
| 174 break; | |
| 175 case Ready: | |
| 176 ASSERT(state == ContextStopped); | |
| 177 break; | |
| 178 case ContextStopped: | |
| 179 ASSERT_NOT_REACHED(); | |
| 180 break; | |
| 181 } | |
| 182 | |
| 183 ProxyState oldState = m_proxyState; | |
| 184 m_proxyState = state; | |
| 185 if (oldState == Ready || state == Ready) | |
| 186 m_outerWorker->proxyReadyChanged(); | |
| 187 } | |
| 188 | |
| 164 void ServiceWorker::onPromiseResolved() | 189 void ServiceWorker::onPromiseResolved() |
| 165 { | 190 { |
| 166 ASSERT(m_isPromisePending); | 191 if (m_proxyState == ContextStopped) |
| 167 m_isPromisePending = false; | 192 return; |
| 168 m_outerWorker->proxyReadyChanged(); | 193 setProxyState(Ready); |
| 169 } | 194 } |
| 170 | 195 |
| 171 void ServiceWorker::waitOnPromise(ScriptPromise promise) | 196 void ServiceWorker::waitOnPromise(ScriptPromise promise) |
| 172 { | 197 { |
| 173 ASSERT(!m_isPromisePending); | 198 setProxyState(RegisterPromisePending); |
| 174 m_isPromisePending = true; | |
| 175 m_outerWorker->proxyReadyChanged(); | |
| 176 promise.then(ThenFunction::create(this)); | 199 promise.then(ThenFunction::create(this)); |
| 177 } | 200 } |
| 178 | 201 |
| 202 bool ServiceWorker::hasPendingActivity() const | |
| 203 { | |
| 204 if (m_proxyState == ContextStopped) | |
| 205 return false; | |
| 206 return m_outerWorker->state() != blink::WebServiceWorkerStateDeactivated; | |
| 207 } | |
| 208 | |
| 209 void ServiceWorker::stop() | |
| 210 { | |
| 211 setProxyState(ContextStopped); | |
| 212 } | |
| 213 | |
| 179 PassRefPtr<ServiceWorker> ServiceWorker::create(ExecutionContext* executionConte xt, PassOwnPtr<blink::WebServiceWorker> outerWorker) | 214 PassRefPtr<ServiceWorker> ServiceWorker::create(ExecutionContext* executionConte xt, PassOwnPtr<blink::WebServiceWorker> outerWorker) |
| 180 { | 215 { |
| 181 RefPtr<ServiceWorker> worker = adoptRef(new ServiceWorker(executionContext, outerWorker)); | 216 RefPtr<ServiceWorker> worker = adoptRef(new ServiceWorker(executionContext, outerWorker)); |
| 182 worker->suspendIfNeeded(); | 217 worker->suspendIfNeeded(); |
| 183 return worker.release(); | 218 return worker.release(); |
| 184 } | 219 } |
| 185 | 220 |
| 186 ServiceWorker::ServiceWorker(ExecutionContext* executionContext, PassOwnPtr<blin k::WebServiceWorker> worker) | 221 ServiceWorker::ServiceWorker(ExecutionContext* executionContext, PassOwnPtr<blin k::WebServiceWorker> worker) |
| 187 : AbstractWorker(executionContext) | 222 : AbstractWorker(executionContext) |
| 188 , WebServiceWorkerProxy(this) | 223 , WebServiceWorkerProxy(this) |
| 189 , m_outerWorker(worker) | 224 , m_outerWorker(worker) |
| 190 , m_isPromisePending(false) | 225 , m_proxyState(Initial) |
| 191 { | 226 { |
| 192 ScriptWrappable::init(this); | 227 ScriptWrappable::init(this); |
| 193 ASSERT(m_outerWorker); | 228 ASSERT(m_outerWorker); |
| 194 m_outerWorker->setProxy(this); | 229 m_outerWorker->setProxy(this); |
| 195 } | 230 } |
| 196 | 231 |
| 197 } // namespace WebCore | 232 } // namespace WebCore |
| OLD | NEW |