Chromium Code Reviews

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

Issue 256723002: Remove the queued states mechanism from ServiceWorker (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: finish removal of stuff Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorker.h ('k') | public/platform/WebServiceWorker.h » ('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 66 matching lines...)
77 // Disentangle the port in preparation for sending it to the remote context. 77 // Disentangle the port in preparation for sending it to the remote context.
78 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(por ts, exceptionState); 78 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(por ts, exceptionState);
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 void ServiceWorker::onStateChanged(blink::WebServiceWorkerState state) 87 bool ServiceWorker::isReady()
88 { 88 {
89 if (m_isPromisePending) 89 return !m_isPromisePending;
90 m_queuedStates.append(state);
91 else
92 changeState(state);
93 } 90 }
94 91
95 // FIXME: To be removed, this is just here as part of a three-sided patch.
96 void ServiceWorker::dispatchStateChangeEvent() 92 void ServiceWorker::dispatchStateChangeEvent()
97 { 93 {
98 changeState(m_outerWorker->state()); 94 // FIXME: Add ASSERT(isReady()) when Chromium side change rolls in.
95 this->dispatchEvent(Event::create(EventTypeNames::statechange));
99 } 96 }
100 97
101 const AtomicString& ServiceWorker::state() const 98 const AtomicString& ServiceWorker::state() const
102 { 99 {
103 DEFINE_STATIC_LOCAL(AtomicString, unknown, ("unknown", AtomicString::Constru ctFromLiteral)); 100 DEFINE_STATIC_LOCAL(AtomicString, unknown, ("unknown", AtomicString::Constru ctFromLiteral));
104 DEFINE_STATIC_LOCAL(AtomicString, parsed, ("parsed", AtomicString::Construct FromLiteral)); 101 DEFINE_STATIC_LOCAL(AtomicString, parsed, ("parsed", AtomicString::Construct FromLiteral));
105 DEFINE_STATIC_LOCAL(AtomicString, installing, ("installing", AtomicString::C onstructFromLiteral)); 102 DEFINE_STATIC_LOCAL(AtomicString, installing, ("installing", AtomicString::C onstructFromLiteral));
106 DEFINE_STATIC_LOCAL(AtomicString, installed, ("installed", AtomicString::Con structFromLiteral)); 103 DEFINE_STATIC_LOCAL(AtomicString, installed, ("installed", AtomicString::Con structFromLiteral));
107 DEFINE_STATIC_LOCAL(AtomicString, activating, ("activating", AtomicString::C onstructFromLiteral)); 104 DEFINE_STATIC_LOCAL(AtomicString, activating, ("activating", AtomicString::C onstructFromLiteral));
108 DEFINE_STATIC_LOCAL(AtomicString, active, ("active", AtomicString::Construct FromLiteral)); 105 DEFINE_STATIC_LOCAL(AtomicString, active, ("active", AtomicString::Construct FromLiteral));
(...skipping 27 matching lines...)
136 NewScriptState::Scope scope(resolver->scriptState()); 133 NewScriptState::Scope scope(resolver->scriptState());
137 RefPtr<ServiceWorker> serviceWorker = create(resolver->scriptState()->execut ionContext(), adoptPtr(worker)); 134 RefPtr<ServiceWorker> serviceWorker = create(resolver->scriptState()->execut ionContext(), adoptPtr(worker));
138 serviceWorker->waitOnPromise(resolver->promise()); 135 serviceWorker->waitOnPromise(resolver->promise());
139 return serviceWorker; 136 return serviceWorker;
140 } 137 }
141 138
142 void ServiceWorker::onPromiseResolved() 139 void ServiceWorker::onPromiseResolved()
143 { 140 {
144 ASSERT(m_isPromisePending); 141 ASSERT(m_isPromisePending);
145 m_isPromisePending = false; 142 m_isPromisePending = false;
146 for (Vector<blink::WebServiceWorkerState>::iterator iterator = m_queuedState s.begin(); iterator != m_queuedStates.end(); ++iterator) 143 m_outerWorker->proxyReadyChanged();
147 changeState(*iterator);
148 m_queuedStates.clear();
149 } 144 }
150 145
151 void ServiceWorker::waitOnPromise(ScriptPromise promise) 146 void ServiceWorker::waitOnPromise(ScriptPromise promise)
152 { 147 {
153 ASSERT(!m_isPromisePending); 148 ASSERT(!m_isPromisePending);
154 m_isPromisePending = true; 149 m_isPromisePending = true;
150 m_outerWorker->proxyReadyChanged();
155 promise.then(ThenFunction::create(this)); 151 promise.then(ThenFunction::create(this));
156 } 152 }
157 153
158 void ServiceWorker::changeState(blink::WebServiceWorkerState state)
159 {
160 m_outerWorker->setState(state);
161 this->dispatchEvent(Event::create(EventTypeNames::statechange));
162 }
163
164 PassRefPtr<ServiceWorker> ServiceWorker::create(ExecutionContext* executionConte xt, PassOwnPtr<blink::WebServiceWorker> outerWorker) 154 PassRefPtr<ServiceWorker> ServiceWorker::create(ExecutionContext* executionConte xt, PassOwnPtr<blink::WebServiceWorker> outerWorker)
165 { 155 {
166 RefPtr<ServiceWorker> worker = adoptRef(new ServiceWorker(executionContext, outerWorker)); 156 RefPtr<ServiceWorker> worker = adoptRef(new ServiceWorker(executionContext, outerWorker));
167 worker->suspendIfNeeded(); 157 worker->suspendIfNeeded();
168 return worker.release(); 158 return worker.release();
169 } 159 }
170 160
171 ServiceWorker::ServiceWorker(ExecutionContext* executionContext, PassOwnPtr<blin k::WebServiceWorker> worker) 161 ServiceWorker::ServiceWorker(ExecutionContext* executionContext, PassOwnPtr<blin k::WebServiceWorker> worker)
172 : AbstractWorker(executionContext) 162 : AbstractWorker(executionContext)
173 , m_outerWorker(worker) 163 , m_outerWorker(worker)
174 , m_isPromisePending(false) 164 , m_isPromisePending(false)
175 { 165 {
176 ScriptWrappable::init(this); 166 ScriptWrappable::init(this);
177 ASSERT(m_outerWorker); 167 ASSERT(m_outerWorker);
178 m_outerWorker->setProxy(this); 168 m_outerWorker->setProxy(this);
179 } 169 }
180 170
181 } // namespace WebCore 171 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorker.h ('k') | public/platform/WebServiceWorker.h » ('j') | no next file with comments »

Powered by Google App Engine