| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 doom_installing_worker_ = true; | 145 doom_installing_worker_ = true; |
| 146 if (phase_ == INSTALL) | 146 if (phase_ == INSTALL) |
| 147 Complete(SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED, std::string()); | 147 Complete(SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED, std::string()); |
| 148 } | 148 } |
| 149 | 149 |
| 150 ServiceWorkerRegisterJob::Internal::Internal() {} | 150 ServiceWorkerRegisterJob::Internal::Internal() {} |
| 151 | 151 |
| 152 ServiceWorkerRegisterJob::Internal::~Internal() {} | 152 ServiceWorkerRegisterJob::Internal::~Internal() {} |
| 153 | 153 |
| 154 void ServiceWorkerRegisterJob::set_registration( | 154 void ServiceWorkerRegisterJob::set_registration( |
| 155 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 155 scoped_refptr<ServiceWorkerRegistration> registration) { |
| 156 DCHECK(phase_ == START || phase_ == REGISTER) << phase_; | 156 DCHECK(phase_ == START || phase_ == REGISTER) << phase_; |
| 157 DCHECK(!internal_.registration.get()); | 157 DCHECK(!internal_.registration.get()); |
| 158 internal_.registration = registration; | 158 internal_.registration = std::move(registration); |
| 159 } | 159 } |
| 160 | 160 |
| 161 ServiceWorkerRegistration* ServiceWorkerRegisterJob::registration() { | 161 ServiceWorkerRegistration* ServiceWorkerRegisterJob::registration() { |
| 162 DCHECK(phase_ >= REGISTER || job_type_ == UPDATE_JOB) << phase_; | 162 DCHECK(phase_ >= REGISTER || job_type_ == UPDATE_JOB) << phase_; |
| 163 return internal_.registration.get(); | 163 return internal_.registration.get(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void ServiceWorkerRegisterJob::set_new_version( | 166 void ServiceWorkerRegisterJob::set_new_version( |
| 167 ServiceWorkerVersion* version) { | 167 ServiceWorkerVersion* version) { |
| 168 DCHECK(phase_ == UPDATE) << phase_; | 168 DCHECK(phase_ == UPDATE) << phase_; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 break; | 202 break; |
| 203 } | 203 } |
| 204 phase_ = phase; | 204 phase_ = phase; |
| 205 } | 205 } |
| 206 | 206 |
| 207 // This function corresponds to the steps in [[Register]] following | 207 // This function corresponds to the steps in [[Register]] following |
| 208 // "Let registration be the result of running the [[GetRegistration]] algorithm. | 208 // "Let registration be the result of running the [[GetRegistration]] algorithm. |
| 209 // Throughout this file, comments in quotes are excerpts from the spec. | 209 // Throughout this file, comments in quotes are excerpts from the spec. |
| 210 void ServiceWorkerRegisterJob::ContinueWithRegistration( | 210 void ServiceWorkerRegisterJob::ContinueWithRegistration( |
| 211 ServiceWorkerStatusCode status, | 211 ServiceWorkerStatusCode status, |
| 212 const scoped_refptr<ServiceWorkerRegistration>& existing_registration) { | 212 scoped_refptr<ServiceWorkerRegistration> existing_registration) { |
| 213 DCHECK_EQ(REGISTRATION_JOB, job_type_); | 213 DCHECK_EQ(REGISTRATION_JOB, job_type_); |
| 214 if (status != SERVICE_WORKER_ERROR_NOT_FOUND && status != SERVICE_WORKER_OK) { | 214 if (status != SERVICE_WORKER_ERROR_NOT_FOUND && status != SERVICE_WORKER_OK) { |
| 215 Complete(status); | 215 Complete(status); |
| 216 return; | 216 return; |
| 217 } | 217 } |
| 218 | 218 |
| 219 if (!existing_registration.get() || existing_registration->is_uninstalled()) { | 219 if (!existing_registration.get() || existing_registration->is_uninstalled()) { |
| 220 RegisterAndContinue(); | 220 RegisterAndContinue(); |
| 221 return; | 221 return; |
| 222 } | 222 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 241 } | 241 } |
| 242 | 242 |
| 243 // "Return the result of running the [[Update]] algorithm, or its equivalent, | 243 // "Return the result of running the [[Update]] algorithm, or its equivalent, |
| 244 // passing registration as the argument." | 244 // passing registration as the argument." |
| 245 set_registration(existing_registration); | 245 set_registration(existing_registration); |
| 246 UpdateAndContinue(); | 246 UpdateAndContinue(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 void ServiceWorkerRegisterJob::ContinueWithUpdate( | 249 void ServiceWorkerRegisterJob::ContinueWithUpdate( |
| 250 ServiceWorkerStatusCode status, | 250 ServiceWorkerStatusCode status, |
| 251 const scoped_refptr<ServiceWorkerRegistration>& existing_registration) { | 251 scoped_refptr<ServiceWorkerRegistration> existing_registration) { |
| 252 DCHECK_EQ(UPDATE_JOB, job_type_); | 252 DCHECK_EQ(UPDATE_JOB, job_type_); |
| 253 if (status != SERVICE_WORKER_OK) { | 253 if (status != SERVICE_WORKER_OK) { |
| 254 Complete(status); | 254 Complete(status); |
| 255 return; | 255 return; |
| 256 } | 256 } |
| 257 | 257 |
| 258 if (existing_registration.get() != registration()) { | 258 if (existing_registration.get() != registration()) { |
| 259 Complete(SERVICE_WORKER_ERROR_NOT_FOUND); | 259 Complete(SERVICE_WORKER_ERROR_NOT_FOUND); |
| 260 return; | 260 return; |
| 261 } | 261 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 287 return; | 287 return; |
| 288 } | 288 } |
| 289 | 289 |
| 290 set_registration( | 290 set_registration( |
| 291 new ServiceWorkerRegistration(pattern_, registration_id, context_)); | 291 new ServiceWorkerRegistration(pattern_, registration_id, context_)); |
| 292 AddRegistrationToMatchingProviderHosts(registration()); | 292 AddRegistrationToMatchingProviderHosts(registration()); |
| 293 UpdateAndContinue(); | 293 UpdateAndContinue(); |
| 294 } | 294 } |
| 295 | 295 |
| 296 void ServiceWorkerRegisterJob::ContinueWithUninstallingRegistration( | 296 void ServiceWorkerRegisterJob::ContinueWithUninstallingRegistration( |
| 297 const scoped_refptr<ServiceWorkerRegistration>& existing_registration, | 297 scoped_refptr<ServiceWorkerRegistration> existing_registration, |
| 298 ServiceWorkerStatusCode status) { | 298 ServiceWorkerStatusCode status) { |
| 299 if (status != SERVICE_WORKER_OK) { | 299 if (status != SERVICE_WORKER_OK) { |
| 300 Complete(status); | 300 Complete(status); |
| 301 return; | 301 return; |
| 302 } | 302 } |
| 303 should_uninstall_on_failure_ = true; | 303 should_uninstall_on_failure_ = true; |
| 304 set_registration(existing_registration); | 304 set_registration(existing_registration); |
| 305 UpdateAndContinue(); | 305 UpdateAndContinue(); |
| 306 } | 306 } |
| 307 | 307 |
| 308 void ServiceWorkerRegisterJob::ContinueWithRegistrationForSameScriptUrl( | 308 void ServiceWorkerRegisterJob::ContinueWithRegistrationForSameScriptUrl( |
| 309 const scoped_refptr<ServiceWorkerRegistration>& existing_registration, | 309 scoped_refptr<ServiceWorkerRegistration> existing_registration, |
| 310 ServiceWorkerStatusCode status) { | 310 ServiceWorkerStatusCode status) { |
| 311 if (status != SERVICE_WORKER_OK) { | 311 if (status != SERVICE_WORKER_OK) { |
| 312 Complete(status); | 312 Complete(status); |
| 313 return; | 313 return; |
| 314 } | 314 } |
| 315 set_registration(existing_registration); | 315 set_registration(existing_registration); |
| 316 | 316 |
| 317 // "If newestWorker is not null, and scriptURL is equal to | 317 // "If newestWorker is not null, and scriptURL is equal to |
| 318 // newestWorker.scriptURL, then: | 318 // newestWorker.scriptURL, then: |
| 319 // Return a promise resolved with registration." | 319 // Return a promise resolved with registration." |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 new_version()->force_bypass_cache_for_scripts() || | 639 new_version()->force_bypass_cache_for_scripts() || |
| 640 registration()->last_update_check().is_null()) { | 640 registration()->last_update_check().is_null()) { |
| 641 registration()->set_last_update_check(base::Time::Now()); | 641 registration()->set_last_update_check(base::Time::Now()); |
| 642 | 642 |
| 643 if (registration()->has_installed_version()) | 643 if (registration()->has_installed_version()) |
| 644 context_->storage()->UpdateLastUpdateCheckTime(registration()); | 644 context_->storage()->UpdateLastUpdateCheckTime(registration()); |
| 645 } | 645 } |
| 646 } | 646 } |
| 647 | 647 |
| 648 } // namespace content | 648 } // namespace content |
| OLD | NEW |