| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 weak_factory_(this) {} | 51 weak_factory_(this) {} |
| 52 | 52 |
| 53 ServiceWorkerRegisterJob::ServiceWorkerRegisterJob( | 53 ServiceWorkerRegisterJob::ServiceWorkerRegisterJob( |
| 54 base::WeakPtr<ServiceWorkerContextCore> context, | 54 base::WeakPtr<ServiceWorkerContextCore> context, |
| 55 ServiceWorkerRegistration* registration, | 55 ServiceWorkerRegistration* registration, |
| 56 bool force_bypass_cache, | 56 bool force_bypass_cache, |
| 57 bool skip_script_comparison) | 57 bool skip_script_comparison) |
| 58 : context_(context), | 58 : context_(context), |
| 59 job_type_(UPDATE_JOB), | 59 job_type_(UPDATE_JOB), |
| 60 pattern_(registration->pattern()), | 60 pattern_(registration->pattern()), |
| 61 script_url_(registration->GetNewestVersion()->script_url()), | |
| 62 phase_(INITIAL), | 61 phase_(INITIAL), |
| 63 doom_installing_worker_(false), | 62 doom_installing_worker_(false), |
| 64 is_promise_resolved_(false), | 63 is_promise_resolved_(false), |
| 65 should_uninstall_on_failure_(false), | 64 should_uninstall_on_failure_(false), |
| 66 force_bypass_cache_(force_bypass_cache), | 65 force_bypass_cache_(force_bypass_cache), |
| 67 skip_script_comparison_(skip_script_comparison), | 66 skip_script_comparison_(skip_script_comparison), |
| 68 promise_resolved_status_(SERVICE_WORKER_OK), | 67 promise_resolved_status_(SERVICE_WORKER_OK), |
| 69 weak_factory_(this) { | 68 weak_factory_(this) { |
| 70 internal_.registration = registration; | 69 internal_.registration = registration; |
| 71 } | 70 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 } | 118 } |
| 120 | 119 |
| 121 void ServiceWorkerRegisterJob::Abort() { | 120 void ServiceWorkerRegisterJob::Abort() { |
| 122 SetPhase(ABORT); | 121 SetPhase(ABORT); |
| 123 CompleteInternal(SERVICE_WORKER_ERROR_ABORT, std::string()); | 122 CompleteInternal(SERVICE_WORKER_ERROR_ABORT, std::string()); |
| 124 // Don't have to call FinishJob() because the caller takes care of removing | 123 // Don't have to call FinishJob() because the caller takes care of removing |
| 125 // the jobs from the queue. | 124 // the jobs from the queue. |
| 126 } | 125 } |
| 127 | 126 |
| 128 bool ServiceWorkerRegisterJob::Equals(ServiceWorkerRegisterJobBase* job) const { | 127 bool ServiceWorkerRegisterJob::Equals(ServiceWorkerRegisterJobBase* job) const { |
| 129 if (job->GetType() != GetType()) | 128 if (job->GetType() != job_type_) |
| 130 return false; | 129 return false; |
| 131 ServiceWorkerRegisterJob* register_job = | 130 ServiceWorkerRegisterJob* register_job = |
| 132 static_cast<ServiceWorkerRegisterJob*>(job); | 131 static_cast<ServiceWorkerRegisterJob*>(job); |
| 132 if (job_type_ == UPDATE_JOB) |
| 133 return register_job->pattern_ == pattern_; |
| 134 DCHECK_EQ(REGISTRATION_JOB, job_type_); |
| 133 return register_job->pattern_ == pattern_ && | 135 return register_job->pattern_ == pattern_ && |
| 134 register_job->script_url_ == script_url_; | 136 register_job->script_url_ == script_url_; |
| 135 } | 137 } |
| 136 | 138 |
| 137 RegistrationJobType ServiceWorkerRegisterJob::GetType() const { | 139 RegistrationJobType ServiceWorkerRegisterJob::GetType() const { |
| 138 return job_type_; | 140 return job_type_; |
| 139 } | 141 } |
| 140 | 142 |
| 141 void ServiceWorkerRegisterJob::DoomInstallingWorker() { | 143 void ServiceWorkerRegisterJob::DoomInstallingWorker() { |
| 142 doom_installing_worker_ = true; | 144 doom_installing_worker_ = true; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 if (status != SERVICE_WORKER_OK) { | 252 if (status != SERVICE_WORKER_OK) { |
| 251 Complete(status); | 253 Complete(status); |
| 252 return; | 254 return; |
| 253 } | 255 } |
| 254 | 256 |
| 255 if (existing_registration.get() != registration()) { | 257 if (existing_registration.get() != registration()) { |
| 256 Complete(SERVICE_WORKER_ERROR_NOT_FOUND); | 258 Complete(SERVICE_WORKER_ERROR_NOT_FOUND); |
| 257 return; | 259 return; |
| 258 } | 260 } |
| 259 | 261 |
| 260 // A previous job may have unregistered or installed a new version to this | 262 // A previous job may have unregistered this registration. |
| 261 // registration. | |
| 262 if (registration()->is_uninstalling() || | 263 if (registration()->is_uninstalling() || |
| 263 registration()->GetNewestVersion()->script_url() != script_url_) { | 264 !registration()->GetNewestVersion()) { |
| 264 Complete(SERVICE_WORKER_ERROR_NOT_FOUND); | 265 Complete(SERVICE_WORKER_ERROR_NOT_FOUND); |
| 265 return; | 266 return; |
| 266 } | 267 } |
| 267 | 268 |
| 269 DCHECK(script_url_.is_empty()); |
| 270 script_url_ = registration()->GetNewestVersion()->script_url(); |
| 271 |
| 268 // TODO(michaeln): If the last update check was less than 24 hours | 272 // TODO(michaeln): If the last update check was less than 24 hours |
| 269 // ago, depending on the freshness of the cached worker script we | 273 // ago, depending on the freshness of the cached worker script we |
| 270 // may be able to complete the update job right here. | 274 // may be able to complete the update job right here. |
| 271 | 275 |
| 272 UpdateAndContinue(); | 276 UpdateAndContinue(); |
| 273 } | 277 } |
| 274 | 278 |
| 275 // Creates a new ServiceWorkerRegistration. | 279 // Creates a new ServiceWorkerRegistration. |
| 276 void ServiceWorkerRegisterJob::RegisterAndContinue() { | 280 void ServiceWorkerRegisterJob::RegisterAndContinue() { |
| 277 SetPhase(REGISTER); | 281 SetPhase(REGISTER); |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 new_version()->force_bypass_cache_for_scripts() || | 602 new_version()->force_bypass_cache_for_scripts() || |
| 599 registration()->last_update_check().is_null()) { | 603 registration()->last_update_check().is_null()) { |
| 600 registration()->set_last_update_check(base::Time::Now()); | 604 registration()->set_last_update_check(base::Time::Now()); |
| 601 | 605 |
| 602 if (registration()->has_installed_version()) | 606 if (registration()->has_installed_version()) |
| 603 context_->storage()->UpdateLastUpdateCheckTime(registration()); | 607 context_->storage()->UpdateLastUpdateCheckTime(registration()); |
| 604 } | 608 } |
| 605 } | 609 } |
| 606 | 610 |
| 607 } // namespace content | 611 } // namespace content |
| OLD | NEW |