| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 110 |
| 111 RegistrationJobType ServiceWorkerRegisterJob::GetType() { | 111 RegistrationJobType ServiceWorkerRegisterJob::GetType() { |
| 112 return job_type_; | 112 return job_type_; |
| 113 } | 113 } |
| 114 | 114 |
| 115 ServiceWorkerRegisterJob::Internal::Internal() {} | 115 ServiceWorkerRegisterJob::Internal::Internal() {} |
| 116 | 116 |
| 117 ServiceWorkerRegisterJob::Internal::~Internal() {} | 117 ServiceWorkerRegisterJob::Internal::~Internal() {} |
| 118 | 118 |
| 119 void ServiceWorkerRegisterJob::set_registration( | 119 void ServiceWorkerRegisterJob::set_registration( |
| 120 ServiceWorkerRegistration* registration) { | 120 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| 121 DCHECK(phase_ == START || phase_ == REGISTER) << phase_; | 121 DCHECK(phase_ == START || phase_ == REGISTER) << phase_; |
| 122 DCHECK(!internal_.registration.get()); | 122 DCHECK(!internal_.registration.get()); |
| 123 internal_.registration = registration; | 123 internal_.registration = registration; |
| 124 } | 124 } |
| 125 | 125 |
| 126 ServiceWorkerRegistration* ServiceWorkerRegisterJob::registration() { | 126 ServiceWorkerRegistration* ServiceWorkerRegisterJob::registration() { |
| 127 DCHECK(phase_ >= REGISTER || job_type_ == UPDATE_JOB) << phase_; | 127 DCHECK(phase_ >= REGISTER || job_type_ == UPDATE_JOB) << phase_; |
| 128 return internal_.registration.get(); | 128 return internal_.registration.get(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void ServiceWorkerRegisterJob::set_new_version( | 131 void ServiceWorkerRegisterJob::set_new_version( |
| 132 ServiceWorkerVersion* version) { | 132 ServiceWorkerVersion* version) { |
| 133 DCHECK(phase_ == UPDATE) << phase_; | 133 DCHECK(phase_ == UPDATE) << phase_; |
| 134 DCHECK(!internal_.new_version.get()); | 134 DCHECK(!internal_.new_version.get()); |
| 135 internal_.new_version = version; | 135 internal_.new_version = version; |
| 136 } | 136 } |
| 137 | 137 |
| 138 ServiceWorkerVersion* ServiceWorkerRegisterJob::new_version() { | 138 ServiceWorkerVersion* ServiceWorkerRegisterJob::new_version() { |
| 139 DCHECK(phase_ >= UPDATE) << phase_; | 139 DCHECK(phase_ >= UPDATE) << phase_; |
| 140 return internal_.new_version.get(); | 140 return internal_.new_version.get(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void ServiceWorkerRegisterJob::set_uninstalling_registration( | 143 void ServiceWorkerRegisterJob::set_uninstalling_registration( |
| 144 ServiceWorkerRegistration* registration) { | 144 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| 145 DCHECK_EQ(phase_, WAIT_FOR_UNINSTALL); | 145 DCHECK_EQ(phase_, WAIT_FOR_UNINSTALL); |
| 146 internal_.uninstalling_registration = registration; | 146 internal_.uninstalling_registration = registration; |
| 147 } | 147 } |
| 148 | 148 |
| 149 ServiceWorkerRegistration* | 149 ServiceWorkerRegistration* |
| 150 ServiceWorkerRegisterJob::uninstalling_registration() { | 150 ServiceWorkerRegisterJob::uninstalling_registration() { |
| 151 DCHECK_EQ(phase_, WAIT_FOR_UNINSTALL); | 151 DCHECK_EQ(phase_, WAIT_FOR_UNINSTALL); |
| 152 return internal_.uninstalling_registration; | 152 return internal_.uninstalling_registration.get(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void ServiceWorkerRegisterJob::SetPhase(Phase phase) { | 155 void ServiceWorkerRegisterJob::SetPhase(Phase phase) { |
| 156 switch (phase) { | 156 switch (phase) { |
| 157 case INITIAL: | 157 case INITIAL: |
| 158 NOTREACHED(); | 158 NOTREACHED(); |
| 159 break; | 159 break; |
| 160 case START: | 160 case START: |
| 161 DCHECK(phase_ == INITIAL) << phase_; | 161 DCHECK(phase_ == INITIAL) << phase_; |
| 162 break; | 162 break; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 set_registration(existing_registration); | 290 set_registration(existing_registration); |
| 291 | 291 |
| 292 // TODO(falken): Follow the spec: resolve the promise | 292 // TODO(falken): Follow the spec: resolve the promise |
| 293 // with the newest version. | 293 // with the newest version. |
| 294 | 294 |
| 295 if (!existing_registration->active_version()) { | 295 if (!existing_registration->active_version()) { |
| 296 UpdateAndContinue(); | 296 UpdateAndContinue(); |
| 297 return; | 297 return; |
| 298 } | 298 } |
| 299 | 299 |
| 300 ResolvePromise( | 300 ResolvePromise(status, |
| 301 status, existing_registration, existing_registration->active_version()); | 301 existing_registration.get(), |
| 302 existing_registration->active_version()); |
| 302 Complete(SERVICE_WORKER_OK); | 303 Complete(SERVICE_WORKER_OK); |
| 303 } | 304 } |
| 304 | 305 |
| 305 // This function corresponds to the spec's [[Update]] algorithm. | 306 // This function corresponds to the spec's [[Update]] algorithm. |
| 306 void ServiceWorkerRegisterJob::UpdateAndContinue() { | 307 void ServiceWorkerRegisterJob::UpdateAndContinue() { |
| 307 SetPhase(UPDATE); | 308 SetPhase(UPDATE); |
| 308 context_->storage()->NotifyInstallingRegistration(registration()); | 309 context_->storage()->NotifyInstallingRegistration(registration()); |
| 309 | 310 |
| 310 // TODO(falken): "If serviceWorkerRegistration.installingWorker is not null.." | 311 // TODO(falken): "If serviceWorkerRegistration.installingWorker is not null.." |
| 311 // then terminate the installing worker. It doesn't make sense to implement | 312 // then terminate the installing worker. It doesn't make sense to implement |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 ServiceWorkerProviderHost* host = it->GetProviderHost(); | 535 ServiceWorkerProviderHost* host = it->GetProviderHost(); |
| 535 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(), | 536 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(), |
| 536 host->document_url())) { | 537 host->document_url())) { |
| 537 if (host->CanAssociateRegistration(registration)) | 538 if (host->CanAssociateRegistration(registration)) |
| 538 host->AssociateRegistration(registration); | 539 host->AssociateRegistration(registration); |
| 539 } | 540 } |
| 540 } | 541 } |
| 541 } | 542 } |
| 542 | 543 |
| 543 } // namespace content | 544 } // namespace content |
| OLD | NEW |