@@ -225,9 +225,10 @@ void ServiceWorkerRegisterJob::SetPhase(Phase phase) {
225
225
phase_ = phase;
226
226
}
227
227
228
- // This function corresponds to the steps in [[Register]] following
229
- // "Let registration be the result of running the [[GetRegistration]] algorithm.
230
- // Throughout this file, comments in quotes are excerpts from the spec.
228
+ // This function corresponds to the steps in the [[Register]] algorithm.
229
+ // https://w3c.github.io/ServiceWorker/#register-algorithm
230
+ // "4. Let registration be the result of running the Get Registration algorithm
231
+ // passing job’s scope url as the argument."
231
232
void ServiceWorkerRegisterJob::ContinueWithRegistration (
232
233
blink::ServiceWorkerStatusCode status,
233
234
scoped_refptr<ServiceWorkerRegistration> existing_registration) {
@@ -244,20 +245,19 @@ void ServiceWorkerRegisterJob::ContinueWithRegistration(
244
245
}
245
246
246
247
DCHECK (existing_registration->GetNewestVersion ());
247
- // We also compare |script_type| here to proceed with registration when the
248
- // script type is changed.
249
- // TODO(asamidoi): Update the spec comment once
250
- // https://github.com/w3c/ServiceWorker/issues/1359 is resolved.
251
- // "If scriptURL is equal to registration.[[ScriptURL]] and "update_via_cache
252
- // is equal to registration.[[update_via_cache]], then:"
248
+ // "5.2. If newestWorker is not null, job’s script url equals newestWorker’s
249
+ // script url, job’s worker type equals newestWorker’s type, and job’s update
250
+ // via cache mode's value equals registration’s update via cache mode, then:"
253
251
if (existing_registration->GetNewestVersion ()->script_url () == script_url_ &&
254
- existing_registration->update_via_cache () == update_via_cache_ &&
255
252
existing_registration->GetNewestVersion ()->script_type () ==
256
- worker_script_type_) {
257
- // "Set registration.[[Uninstalling]] to false."
258
- existing_registration->AbortPendingClear (base::BindOnce (
259
- &ServiceWorkerRegisterJob::ContinueWithRegistrationForSameScriptUrl,
260
- weak_factory_.GetWeakPtr (), existing_registration));
253
+ worker_script_type_ &&
254
+ existing_registration->update_via_cache () == update_via_cache_) {
255
+ // Subsequent spec steps (5.2.1-5.2.2) are implemented in
256
+ // ContinueWithRegistrationWithSameRegistrationOptions().
257
+ existing_registration->AbortPendingClear (
258
+ base::BindOnce (&ServiceWorkerRegisterJob::
259
+ ContinueWithRegistrationWithSameRegistrationOptions,
260
+ weak_factory_.GetWeakPtr (), existing_registration));
261
261
return ;
262
262
}
263
263
@@ -268,12 +268,11 @@ void ServiceWorkerRegisterJob::ContinueWithRegistration(
268
268
return ;
269
269
}
270
270
271
- // "Invoke Set Registration algorithm with job’s scope url and
272
- // job’s update via cache mode."
271
+ // "6.1. Invoke Set Registration algorithm with job’s scope url and job’s
272
+ // update via cache mode."
273
273
existing_registration->SetUpdateViaCache (update_via_cache_);
274
274
set_registration (existing_registration);
275
- // "Return the result of running the [[Update]] algorithm, or its equivalent,
276
- // passing registration as the argument."
275
+ // "7. Invoke Update algorithm passing job as the argument."
277
276
UpdateAndContinue ();
278
277
}
279
278
@@ -401,32 +400,30 @@ void ServiceWorkerRegisterJob::ContinueWithUninstallingRegistration(
401
400
UpdateAndContinue ();
402
401
}
403
402
404
- void ServiceWorkerRegisterJob::ContinueWithRegistrationForSameScriptUrl (
405
- scoped_refptr<ServiceWorkerRegistration> existing_registration,
406
- blink::ServiceWorkerStatusCode status) {
403
+ void ServiceWorkerRegisterJob::
404
+ ContinueWithRegistrationWithSameRegistrationOptions (
405
+ scoped_refptr<ServiceWorkerRegistration> existing_registration,
406
+ blink::ServiceWorkerStatusCode status) {
407
407
if (status != blink::ServiceWorkerStatusCode::kOk ) {
408
408
Complete (status);
409
409
return ;
410
410
}
411
411
set_registration (existing_registration);
412
412
413
- // "If newestWorker is not null, scriptURL is equal to newestWorker.scriptURL,
414
- // and job’s update via cache mode's value equals registration’s
415
- // update via cache mode then:
416
- // Return a promise resolved with registration."
417
413
// We resolve only if there's an active version. If there's not,
418
414
// then there is either no version or only a waiting version from
419
415
// the last browser session; it makes sense to proceed with registration in
420
416
// either case.
421
417
DCHECK (!existing_registration->installing_version ());
422
418
if (existing_registration->active_version ()) {
419
+ // "5.2.1. Invoke Resolve Job Promise with job and registration."
423
420
ResolvePromise (status, std::string (), existing_registration.get ());
421
+ // "5.2.2. Invoke Finish Job with job and abort these steps."
424
422
Complete (blink::ServiceWorkerStatusCode::kOk );
425
423
return ;
426
424
}
427
425
428
- // "Return the result of running the [[Update]] algorithm, or its equivalent,
429
- // passing registration as the argument."
426
+ // "7. Invoke Update algorithm passing job as the argument."
430
427
UpdateAndContinue ();
431
428
}
432
429
0 commit comments