Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: content/browser/service_worker/service_worker_register_job.cc

Issue 1928443003: service worker: Update job gets the script url when the job starts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 script_url_(script_url), 43 script_url_(script_url),
44 phase_(INITIAL), 44 phase_(INITIAL),
45 doom_installing_worker_(false), 45 doom_installing_worker_(false),
46 is_promise_resolved_(false), 46 is_promise_resolved_(false),
47 should_uninstall_on_failure_(false), 47 should_uninstall_on_failure_(false),
48 force_bypass_cache_(false), 48 force_bypass_cache_(false),
49 skip_script_comparison_(false), 49 skip_script_comparison_(false),
50 promise_resolved_status_(SERVICE_WORKER_OK), 50 promise_resolved_status_(SERVICE_WORKER_OK),
51 weak_factory_(this) {} 51 weak_factory_(this) {}
52 52
53 ServiceWorkerRegisterJob::ServiceWorkerRegisterJob( 53 ServiceWorkerRegisterJob::ServiceWorkerRegisterJob(
nhiroki 2016/04/28 05:51:46 Can you remove DCHECK(registration->GetNewestVersi
falken 2016/04/28 06:25:17 Great catch. Done.
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
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(job_type_ == REGISTRATION_JOB);
nhiroki 2016/04/28 05:51:46 DCHECK_EQ(REGISTRATION_JOB, job_type_);
falken 2016/04/28 06:25:17 Done.
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
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 script_url_ = registration()->GetNewestVersion()->script_url();
nhiroki 2016/04/28 05:51:46 Can we have DCHECK(script_url_.is_empty()) immedia
falken 2016/04/28 06:25:17 Good idea. Done.
270
268 // TODO(michaeln): If the last update check was less than 24 hours 271 // TODO(michaeln): If the last update check was less than 24 hours
269 // ago, depending on the freshness of the cached worker script we 272 // ago, depending on the freshness of the cached worker script we
270 // may be able to complete the update job right here. 273 // may be able to complete the update job right here.
271
272 UpdateAndContinue(); 274 UpdateAndContinue();
273 } 275 }
274 276
275 // Creates a new ServiceWorkerRegistration. 277 // Creates a new ServiceWorkerRegistration.
276 void ServiceWorkerRegisterJob::RegisterAndContinue() { 278 void ServiceWorkerRegisterJob::RegisterAndContinue() {
277 SetPhase(REGISTER); 279 SetPhase(REGISTER);
278 280
279 int64_t registration_id = context_->storage()->NewRegistrationId(); 281 int64_t registration_id = context_->storage()->NewRegistrationId();
280 if (registration_id == kInvalidServiceWorkerRegistrationId) { 282 if (registration_id == kInvalidServiceWorkerRegistrationId) {
281 Complete(SERVICE_WORKER_ERROR_ABORT); 283 Complete(SERVICE_WORKER_ERROR_ABORT);
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 new_version()->force_bypass_cache_for_scripts() || 600 new_version()->force_bypass_cache_for_scripts() ||
599 registration()->last_update_check().is_null()) { 601 registration()->last_update_check().is_null()) {
600 registration()->set_last_update_check(base::Time::Now()); 602 registration()->set_last_update_check(base::Time::Now());
601 603
602 if (registration()->has_installed_version()) 604 if (registration()->has_installed_version())
603 context_->storage()->UpdateLastUpdateCheckTime(registration()); 605 context_->storage()->UpdateLastUpdateCheckTime(registration());
604 } 606 }
605 } 607 }
606 608
607 } // namespace content 609 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698