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

Side by Side Diff: content/browser/service_worker/service_worker_register_job.cc

Issue 413063004: Service Worker: in Unregister, wait until after the active worker no longer controls a document (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: delete/restore from storage Created 6 years, 4 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/service_worker/service_worker_register_job.h" 5 #include "content/browser/service_worker/service_worker_register_job.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "content/browser/service_worker/service_worker_context_core.h" 10 #include "content/browser/service_worker/service_worker_context_core.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 ServiceWorkerStorage::FindRegistrationCallback next_step; 107 ServiceWorkerStorage::FindRegistrationCallback next_step;
108 if (job_type_ == REGISTRATION_JOB) { 108 if (job_type_ == REGISTRATION_JOB) {
109 next_step = base::Bind( 109 next_step = base::Bind(
110 &ServiceWorkerRegisterJob::ContinueWithRegistration, 110 &ServiceWorkerRegisterJob::ContinueWithRegistration,
111 weak_factory_.GetWeakPtr()); 111 weak_factory_.GetWeakPtr());
112 } else { 112 } else {
113 next_step = base::Bind( 113 next_step = base::Bind(
114 &ServiceWorkerRegisterJob::ContinueWithUpdate, 114 &ServiceWorkerRegisterJob::ContinueWithUpdate,
115 weak_factory_.GetWeakPtr()); 115 weak_factory_.GetWeakPtr());
116 } 116 }
117 context_->storage()->FindRegistrationForPattern(pattern_, next_step); 117
118 scoped_refptr<ServiceWorkerRegistration> registration =
119 context_->storage()->GetUninstallingRegistration(pattern_);
120 if (registration)
121 RunSoon(base::Bind(next_step, SERVICE_WORKER_OK, registration));
122 else
123 context_->storage()->FindRegistrationForPattern(pattern_, next_step);
118 } 124 }
119 125
120 void ServiceWorkerRegisterJob::Abort() { 126 void ServiceWorkerRegisterJob::Abort() {
121 SetPhase(ABORT); 127 SetPhase(ABORT);
122 CompleteInternal(SERVICE_WORKER_ERROR_ABORT); 128 CompleteInternal(SERVICE_WORKER_ERROR_ABORT);
123 // Don't have to call FinishJob() because the caller takes care of removing 129 // Don't have to call FinishJob() because the caller takes care of removing
124 // the jobs from the queue. 130 // the jobs from the queue.
125 } 131 }
126 132
127 bool ServiceWorkerRegisterJob::Equals(ServiceWorkerRegisterJobBase* job) { 133 bool ServiceWorkerRegisterJob::Equals(ServiceWorkerRegisterJobBase* job) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 break; 196 break;
191 case COMPLETE: 197 case COMPLETE:
192 DCHECK(phase_ != INITIAL && phase_ != COMPLETE) << phase_; 198 DCHECK(phase_ != INITIAL && phase_ != COMPLETE) << phase_;
193 break; 199 break;
194 case ABORT: 200 case ABORT:
195 break; 201 break;
196 } 202 }
197 phase_ = phase; 203 phase_ = phase;
198 } 204 }
199 205
200 // This function corresponds to the steps in Register following 206 // This function corresponds to the steps in [[Register]] following
201 // "Let serviceWorkerRegistration be _GetRegistration(scope)" 207 // "Let registration be the result of running the [[GetRegistration]] algorithm.
202 // |existing_registration| corresponds to serviceWorkerRegistration.
203 // Throughout this file, comments in quotes are excerpts from the spec. 208 // Throughout this file, comments in quotes are excerpts from the spec.
204 void ServiceWorkerRegisterJob::ContinueWithRegistration( 209 void ServiceWorkerRegisterJob::ContinueWithRegistration(
205 ServiceWorkerStatusCode status, 210 ServiceWorkerStatusCode status,
206 const scoped_refptr<ServiceWorkerRegistration>& existing_registration) { 211 const scoped_refptr<ServiceWorkerRegistration>& existing_registration) {
207 DCHECK_EQ(REGISTRATION_JOB, job_type_); 212 DCHECK_EQ(REGISTRATION_JOB, job_type_);
208 // On unexpected error, abort this registration job.
209 if (status != SERVICE_WORKER_ERROR_NOT_FOUND && status != SERVICE_WORKER_OK) { 213 if (status != SERVICE_WORKER_ERROR_NOT_FOUND && status != SERVICE_WORKER_OK) {
210 Complete(status); 214 Complete(status);
211 return; 215 return;
212 } 216 }
213 217
214 // "If serviceWorkerRegistration is not null and script is equal to 218 if (!existing_registration) {
215 // serviceWorkerRegistration.scriptUrl..." resolve with the existing 219 RegisterAndContinue(SERVICE_WORKER_OK);
216 // registration and abort. 220 return;
217 if (existing_registration.get() && 221 }
218 existing_registration->script_url() == script_url_) { 222
223 // "1. Set registration.[[Uninstalling]] to false."
224 existing_registration->AbortPendingClear();
michaeln 2014/07/29 03:33:39 what if extisting.script != new.script?
falken 2014/07/29 05:36:22 Great catch, this is a big point. There are two ca
225
226 // "2. If scriptURL is equal to registration.[[ScriptURL]], then:"
227 if (existing_registration->script_url() == script_url_) {
228 // Spec says to resolve with registration.[[GetNewestWorker]]. We come close
229 // by resolving with the active version.
219 set_registration(existing_registration); 230 set_registration(existing_registration);
220 // If there's no active version, go ahead to Update (this isn't in the spec 231
221 // but seems reasonable, and without SoftUpdate implemented we can never
222 // Update otherwise).
223 if (!existing_registration->active_version()) { 232 if (!existing_registration->active_version()) {
224 UpdateAndContinue(); 233 UpdateAndContinue();
225 return; 234 return;
226 } 235 }
236
227 ResolvePromise( 237 ResolvePromise(
228 status, existing_registration, existing_registration->active_version()); 238 status, existing_registration, existing_registration->active_version());
229 Complete(SERVICE_WORKER_OK); 239 Complete(SERVICE_WORKER_OK);
230 return; 240 return;
231 } 241 }
232 242
233 // "If serviceWorkerRegistration is null..." create a new registration. 243 // "Set registration.[[ScriptURL]] to scriptURL." We accomplish this by
234 if (!existing_registration.get()) { 244 // deleting the existing registration and registering a new one.
235 RegisterAndContinue(SERVICE_WORKER_OK);
236 return;
237 }
238
239 // On script URL mismatch, "set serviceWorkerRegistration.scriptUrl to
240 // script." We accomplish this by deleting the existing registration and
241 // registering a new one.
242 // TODO(falken): Match the spec. We now throw away the active_version_ and
243 // waiting_version_ of the existing registration, which isn't in the spec.
244 // TODO(michaeln): Deactivate the live existing_registration object and 245 // TODO(michaeln): Deactivate the live existing_registration object and
245 // eventually call storage->DeleteVersionResources() 246 // eventually call storage->DeleteVersionResources() when it no longer has any
246 // when it no longer has any controllees. 247 // controllees.
247 context_->storage()->DeleteRegistration( 248 context_->storage()->DeleteRegistration(
248 existing_registration->id(), 249 existing_registration->id(),
249 existing_registration->script_url().GetOrigin(), 250 existing_registration->script_url().GetOrigin(),
250 base::Bind(&ServiceWorkerRegisterJob::RegisterAndContinue, 251 base::Bind(&ServiceWorkerRegisterJob::RegisterAndContinue,
251 weak_factory_.GetWeakPtr())); 252 weak_factory_.GetWeakPtr()));
252 } 253 }
253 254
254 void ServiceWorkerRegisterJob::ContinueWithUpdate( 255 void ServiceWorkerRegisterJob::ContinueWithUpdate(
255 ServiceWorkerStatusCode status, 256 ServiceWorkerStatusCode status,
256 const scoped_refptr<ServiceWorkerRegistration>& existing_registration) { 257 const scoped_refptr<ServiceWorkerRegistration>& existing_registration) {
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 DCHECK(context); 566 DCHECK(context);
566 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = 567 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it =
567 context->GetProviderHostIterator(); 568 context->GetProviderHostIterator();
568 !it->IsAtEnd(); it->Advance()) { 569 !it->IsAtEnd(); it->Advance()) {
569 ServiceWorkerProviderHost* host = it->GetProviderHost(); 570 ServiceWorkerProviderHost* host = it->GetProviderHost();
570 host->UnsetVersion(version); 571 host->UnsetVersion(version);
571 } 572 }
572 } 573 }
573 574
574 } // namespace content 575 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698