| OLD | NEW |
| 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 break; | 190 break; |
| 191 case COMPLETE: | 191 case COMPLETE: |
| 192 DCHECK(phase_ != INITIAL && phase_ != COMPLETE) << phase_; | 192 DCHECK(phase_ != INITIAL && phase_ != COMPLETE) << phase_; |
| 193 break; | 193 break; |
| 194 case ABORT: | 194 case ABORT: |
| 195 break; | 195 break; |
| 196 } | 196 } |
| 197 phase_ = phase; | 197 phase_ = phase; |
| 198 } | 198 } |
| 199 | 199 |
| 200 // This function corresponds to the steps in Register following | 200 // This function corresponds to the steps in [[Register]] following |
| 201 // "Let serviceWorkerRegistration be _GetRegistration(scope)" | 201 // "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. | 202 // Throughout this file, comments in quotes are excerpts from the spec. |
| 204 void ServiceWorkerRegisterJob::ContinueWithRegistration( | 203 void ServiceWorkerRegisterJob::ContinueWithRegistration( |
| 205 ServiceWorkerStatusCode status, | 204 ServiceWorkerStatusCode status, |
| 206 const scoped_refptr<ServiceWorkerRegistration>& existing_registration) { | 205 const scoped_refptr<ServiceWorkerRegistration>& existing_registration) { |
| 207 DCHECK_EQ(REGISTRATION_JOB, job_type_); | 206 DCHECK_EQ(REGISTRATION_JOB, job_type_); |
| 208 // On unexpected error, abort this registration job. | 207 // On unexpected error, abort this registration job. |
| 209 if (status != SERVICE_WORKER_ERROR_NOT_FOUND && status != SERVICE_WORKER_OK) { | 208 if (status != SERVICE_WORKER_ERROR_NOT_FOUND && status != SERVICE_WORKER_OK) { |
| 210 Complete(status); | 209 Complete(status); |
| 211 return; | 210 return; |
| 212 } | 211 } |
| 213 | 212 |
| 214 // "If serviceWorkerRegistration is not null and script is equal to | 213 if (!existing_registration) { |
| 215 // serviceWorkerRegistration.scriptUrl..." resolve with the existing | 214 RegisterAndContinue(SERVICE_WORKER_OK); |
| 216 // registration and abort. | 215 return; |
| 217 if (existing_registration.get() && | 216 } |
| 218 existing_registration->script_url() == script_url_) { | 217 |
| 218 // "1. Set registration.[[Uninstalling]] to false." |
| 219 existing_registration->set_uninstalling(false); |
| 220 |
| 221 // "2. If scriptURL is equal to registration.[[ScriptURL]], then:" |
| 222 if (existing_registration->script_url() == script_url_) { |
| 223 // Spec says to resolve with registration.[[GetNewestWorker]]. We come close |
| 224 // by resolving with the active version. |
| 219 set_registration(existing_registration); | 225 set_registration(existing_registration); |
| 220 // If there's no active version, go ahead to Update (this isn't in the spec | 226 |
| 221 // but seems reasonable, and without SoftUpdate implemented we can never | |
| 222 // Update otherwise). | |
| 223 if (!existing_registration->active_version()) { | 227 if (!existing_registration->active_version()) { |
| 224 UpdateAndContinue(); | 228 UpdateAndContinue(); |
| 225 return; | 229 return; |
| 226 } | 230 } |
| 231 |
| 227 ResolvePromise( | 232 ResolvePromise( |
| 228 status, existing_registration, existing_registration->active_version()); | 233 status, existing_registration, existing_registration->active_version()); |
| 229 Complete(SERVICE_WORKER_OK); | 234 Complete(SERVICE_WORKER_OK); |
| 230 return; | 235 return; |
| 231 } | 236 } |
| 232 | 237 |
| 233 // "If serviceWorkerRegistration is null..." create a new registration. | 238 // "Set registration.[[ScriptURL]] to scriptURL." We accomplish this by |
| 234 if (!existing_registration.get()) { | 239 // 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 | 240 // TODO(michaeln): Deactivate the live existing_registration object and |
| 245 // eventually call storage->DeleteVersionResources() | 241 // eventually call storage->DeleteVersionResources() when it no longer has any |
| 246 // when it no longer has any controllees. | 242 // controllees. |
| 247 context_->storage()->DeleteRegistration( | 243 context_->storage()->DeleteRegistration( |
| 248 existing_registration->id(), | 244 existing_registration->id(), |
| 249 existing_registration->script_url().GetOrigin(), | 245 existing_registration->script_url().GetOrigin(), |
| 250 base::Bind(&ServiceWorkerRegisterJob::RegisterAndContinue, | 246 base::Bind(&ServiceWorkerRegisterJob::RegisterAndContinue, |
| 251 weak_factory_.GetWeakPtr())); | 247 weak_factory_.GetWeakPtr())); |
| 252 } | 248 } |
| 253 | 249 |
| 254 void ServiceWorkerRegisterJob::ContinueWithUpdate( | 250 void ServiceWorkerRegisterJob::ContinueWithUpdate( |
| 255 ServiceWorkerStatusCode status, | 251 ServiceWorkerStatusCode status, |
| 256 const scoped_refptr<ServiceWorkerRegistration>& existing_registration) { | 252 const scoped_refptr<ServiceWorkerRegistration>& existing_registration) { |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 DCHECK(context); | 561 DCHECK(context); |
| 566 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = | 562 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = |
| 567 context->GetProviderHostIterator(); | 563 context->GetProviderHostIterator(); |
| 568 !it->IsAtEnd(); it->Advance()) { | 564 !it->IsAtEnd(); it->Advance()) { |
| 569 ServiceWorkerProviderHost* host = it->GetProviderHost(); | 565 ServiceWorkerProviderHost* host = it->GetProviderHost(); |
| 570 host->UnsetVersion(version); | 566 host->UnsetVersion(version); |
| 571 } | 567 } |
| 572 } | 568 } |
| 573 | 569 |
| 574 } // namespace content | 570 } // namespace content |
| OLD | NEW |