| 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 "content/browser/service_worker/service_worker_context_core.h" | 9 #include "content/browser/service_worker/service_worker_context_core.h" |
| 10 #include "content/browser/service_worker/service_worker_job_coordinator.h" | 10 #include "content/browser/service_worker/service_worker_job_coordinator.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 if (!registration.get()) { | 94 if (!registration.get()) { |
| 95 RegisterAndContinue(SERVICE_WORKER_OK); | 95 RegisterAndContinue(SERVICE_WORKER_OK); |
| 96 return; | 96 return; |
| 97 } | 97 } |
| 98 | 98 |
| 99 // On script URL mismatch, "set serviceWorkerRegistration.scriptUrl to | 99 // On script URL mismatch, "set serviceWorkerRegistration.scriptUrl to |
| 100 // script." We accomplish this by deleting the existing registration and | 100 // script." We accomplish this by deleting the existing registration and |
| 101 // registering a new one. | 101 // registering a new one. |
| 102 // TODO(falken): Match the spec. We now throw away the active_version_ and | 102 // TODO(falken): Match the spec. We now throw away the active_version_ and |
| 103 // pending_version_ of the existing registration, which isn't in the spec. | 103 // pending_version_ of the existing registration, which isn't in the spec. |
| 104 registration->Shutdown(); | |
| 105 context_->storage()->DeleteRegistration( | 104 context_->storage()->DeleteRegistration( |
| 106 pattern_, | 105 pattern_, |
| 107 base::Bind(&ServiceWorkerRegisterJob::RegisterAndContinue, | 106 base::Bind(&ServiceWorkerRegisterJob::RegisterAndContinue, |
| 108 weak_factory_.GetWeakPtr())); | 107 weak_factory_.GetWeakPtr())); |
| 109 } | 108 } |
| 110 | 109 |
| 111 // Registers a new ServiceWorkerRegistration. | 110 // Registers a new ServiceWorkerRegistration. |
| 112 void ServiceWorkerRegisterJob::RegisterAndContinue( | 111 void ServiceWorkerRegisterJob::RegisterAndContinue( |
| 113 ServiceWorkerStatusCode status) { | 112 ServiceWorkerStatusCode status) { |
| 114 DCHECK(!registration_); | 113 DCHECK(!registration_); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 Complete(SERVICE_WORKER_OK); | 219 Complete(SERVICE_WORKER_OK); |
| 221 } | 220 } |
| 222 | 221 |
| 223 void ServiceWorkerRegisterJob::Complete(ServiceWorkerStatusCode status) { | 222 void ServiceWorkerRegisterJob::Complete(ServiceWorkerStatusCode status) { |
| 224 // In success case the callbacks must have been dispatched already | 223 // In success case the callbacks must have been dispatched already |
| 225 // (so this is no-op), otherwise we must have come here for abort case, | 224 // (so this is no-op), otherwise we must have come here for abort case, |
| 226 // so dispatch callbacks with NULL. | 225 // so dispatch callbacks with NULL. |
| 227 DCHECK(callbacks_.empty() || status != SERVICE_WORKER_OK); | 226 DCHECK(callbacks_.empty() || status != SERVICE_WORKER_OK); |
| 228 RunCallbacks(status, NULL); | 227 RunCallbacks(status, NULL); |
| 229 | 228 |
| 230 // If |pending_version_| exists, it was not activated, so we are the sole | |
| 231 // owner of it, so it will be destroyed when this job ends, so Shutdown here. | |
| 232 // We should be able to remove this code later, when something else holds a | |
| 233 // reference to |pending_version_|. | |
| 234 // TODO(kinuko): Fix these ownership and shutdown semantics. | |
| 235 if (pending_version_) { | |
| 236 DCHECK(!registration_->pending_version()); | |
| 237 DCHECK(!registration_->active_version()); | |
| 238 pending_version_->Shutdown(); | |
| 239 } | |
| 240 | |
| 241 context_->job_coordinator()->FinishJob(pattern_, this); | 229 context_->job_coordinator()->FinishJob(pattern_, this); |
| 242 } | 230 } |
| 243 | 231 |
| 244 void ServiceWorkerRegisterJob::RunCallbacks(ServiceWorkerStatusCode status, | 232 void ServiceWorkerRegisterJob::RunCallbacks(ServiceWorkerStatusCode status, |
| 245 ServiceWorkerVersion* version) { | 233 ServiceWorkerVersion* version) { |
| 246 for (std::vector<RegistrationCallback>::iterator it = callbacks_.begin(); | 234 for (std::vector<RegistrationCallback>::iterator it = callbacks_.begin(); |
| 247 it != callbacks_.end(); | 235 it != callbacks_.end(); |
| 248 ++it) { | 236 ++it) { |
| 249 it->Run(status, version); | 237 it->Run(status, version); |
| 250 } | 238 } |
| 251 callbacks_.clear(); | 239 callbacks_.clear(); |
| 252 } | 240 } |
| 253 | 241 |
| 254 } // namespace content | 242 } // namespace content |
| OLD | NEW |