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

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

Issue 306133002: WebServiceWorkerProxy instances can be unwrapped to ServiceWorkers. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Crib from WebNode: make m_private protected to avoid unused field warnings. Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorker.h ('k') | Source/platform/blink_platform.gypi » ('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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 case blink::WebServiceWorkerStateActive: 130 case blink::WebServiceWorkerStateActive:
131 return active; 131 return active;
132 case blink::WebServiceWorkerStateDeactivated: 132 case blink::WebServiceWorkerStateDeactivated:
133 return deactivated; 133 return deactivated;
134 default: 134 default:
135 ASSERT_NOT_REACHED(); 135 ASSERT_NOT_REACHED();
136 return nullAtom; 136 return nullAtom;
137 } 137 }
138 } 138 }
139 139
140 PassRefPtr<ServiceWorker> ServiceWorker::from(ScriptState* scriptState, WebType* worker)
141 {
142 blink::WebServiceWorkerProxy* proxy = worker->proxy();
143 ServiceWorker* existingServiceWorker = proxy ? proxy->unwrap() : 0;
144 if (existingServiceWorker) {
145 ASSERT(existingServiceWorker->executionContext() == scriptState->executi onContext());
146 return existingServiceWorker;
147 }
148
149 return create(scriptState->executionContext(), adoptPtr(worker));
150 }
151
140 PassRefPtr<ServiceWorker> ServiceWorker::from(ScriptPromiseResolverWithContext* resolver, WebType* worker) 152 PassRefPtr<ServiceWorker> ServiceWorker::from(ScriptPromiseResolverWithContext* resolver, WebType* worker)
141 { 153 {
154 RefPtr<ServiceWorker> serviceWorker = ServiceWorker::from(resolver->scriptSt ate(), worker);
155
142 ScriptState::Scope scope(resolver->scriptState()); 156 ScriptState::Scope scope(resolver->scriptState());
143 RefPtr<ServiceWorker> serviceWorker = create(resolver->scriptState()->execut ionContext(), adoptPtr(worker));
144 serviceWorker->waitOnPromise(resolver->promise()); 157 serviceWorker->waitOnPromise(resolver->promise());
158
145 return serviceWorker; 159 return serviceWorker;
146 } 160 }
147 161
148 void ServiceWorker::onPromiseResolved() 162 void ServiceWorker::onPromiseResolved()
149 { 163 {
150 ASSERT(m_isPromisePending); 164 ASSERT(m_isPromisePending);
151 m_isPromisePending = false; 165 m_isPromisePending = false;
152 m_outerWorker->proxyReadyChanged(); 166 m_outerWorker->proxyReadyChanged();
153 } 167 }
154 168
155 void ServiceWorker::waitOnPromise(ScriptPromise promise) 169 void ServiceWorker::waitOnPromise(ScriptPromise promise)
156 { 170 {
157 ASSERT(!m_isPromisePending); 171 ASSERT(!m_isPromisePending);
158 m_isPromisePending = true; 172 m_isPromisePending = true;
159 m_outerWorker->proxyReadyChanged(); 173 m_outerWorker->proxyReadyChanged();
160 promise.then(ThenFunction::create(this)); 174 promise.then(ThenFunction::create(this));
161 } 175 }
162 176
163 PassRefPtr<ServiceWorker> ServiceWorker::create(ExecutionContext* executionConte xt, PassOwnPtr<blink::WebServiceWorker> outerWorker) 177 PassRefPtr<ServiceWorker> ServiceWorker::create(ExecutionContext* executionConte xt, PassOwnPtr<blink::WebServiceWorker> outerWorker)
164 { 178 {
165 RefPtr<ServiceWorker> worker = adoptRef(new ServiceWorker(executionContext, outerWorker)); 179 RefPtr<ServiceWorker> worker = adoptRef(new ServiceWorker(executionContext, outerWorker));
166 worker->suspendIfNeeded(); 180 worker->suspendIfNeeded();
167 return worker.release(); 181 return worker.release();
168 } 182 }
169 183
170 ServiceWorker::ServiceWorker(ExecutionContext* executionContext, PassOwnPtr<blin k::WebServiceWorker> worker) 184 ServiceWorker::ServiceWorker(ExecutionContext* executionContext, PassOwnPtr<blin k::WebServiceWorker> worker)
171 : AbstractWorker(executionContext) 185 : AbstractWorker(executionContext)
186 , WebServiceWorkerProxy(this)
172 , m_outerWorker(worker) 187 , m_outerWorker(worker)
173 , m_isPromisePending(false) 188 , m_isPromisePending(false)
174 { 189 {
175 ScriptWrappable::init(this); 190 ScriptWrappable::init(this);
176 ASSERT(m_outerWorker); 191 ASSERT(m_outerWorker);
177 m_outerWorker->setProxy(this); 192 m_outerWorker->setProxy(this);
178 } 193 }
179 194
180 } // namespace WebCore 195 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorker.h ('k') | Source/platform/blink_platform.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698