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

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

Issue 2771823002: Implement updateViaCache flag and no-cache by default for main service worker scripts
Patch Set: fix IPC Created 3 years, 4 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 typedef ServiceWorkerRegisterJobBase::RegistrationJobType RegistrationJobType; 67 typedef ServiceWorkerRegisterJobBase::RegistrationJobType RegistrationJobType;
68 68
69 ServiceWorkerRegisterJob::ServiceWorkerRegisterJob( 69 ServiceWorkerRegisterJob::ServiceWorkerRegisterJob(
70 base::WeakPtr<ServiceWorkerContextCore> context, 70 base::WeakPtr<ServiceWorkerContextCore> context,
71 const GURL& script_url, 71 const GURL& script_url,
72 const ServiceWorkerRegistrationOptions& options) 72 const ServiceWorkerRegistrationOptions& options)
73 : context_(context), 73 : context_(context),
74 job_type_(REGISTRATION_JOB), 74 job_type_(REGISTRATION_JOB),
75 pattern_(options.scope), 75 pattern_(options.scope),
76 script_url_(script_url), 76 script_url_(script_url),
77 update_via_cache_(options.update_via_cache),
77 phase_(INITIAL), 78 phase_(INITIAL),
78 is_promise_resolved_(false), 79 is_promise_resolved_(false),
79 should_uninstall_on_failure_(false), 80 should_uninstall_on_failure_(false),
80 force_bypass_cache_(false), 81 force_bypass_cache_(false),
81 skip_script_comparison_(false), 82 skip_script_comparison_(false),
82 promise_resolved_status_(SERVICE_WORKER_OK), 83 promise_resolved_status_(SERVICE_WORKER_OK),
83 weak_factory_(this) {} 84 weak_factory_(this) {}
84 85
85 ServiceWorkerRegisterJob::ServiceWorkerRegisterJob( 86 ServiceWorkerRegisterJob::ServiceWorkerRegisterJob(
86 base::WeakPtr<ServiceWorkerContextCore> context, 87 base::WeakPtr<ServiceWorkerContextCore> context,
87 ServiceWorkerRegistration* registration, 88 ServiceWorkerRegistration* registration,
88 bool force_bypass_cache, 89 bool force_bypass_cache,
89 bool skip_script_comparison) 90 bool skip_script_comparison)
90 : context_(context), 91 : context_(context),
91 job_type_(UPDATE_JOB), 92 job_type_(UPDATE_JOB),
92 pattern_(registration->pattern()), 93 pattern_(registration->pattern()),
94 update_via_cache_(registration->update_via_cache()),
93 phase_(INITIAL), 95 phase_(INITIAL),
94 is_promise_resolved_(false), 96 is_promise_resolved_(false),
95 should_uninstall_on_failure_(false), 97 should_uninstall_on_failure_(false),
96 force_bypass_cache_(force_bypass_cache), 98 force_bypass_cache_(force_bypass_cache),
97 skip_script_comparison_(skip_script_comparison), 99 skip_script_comparison_(skip_script_comparison),
98 promise_resolved_status_(SERVICE_WORKER_OK), 100 promise_resolved_status_(SERVICE_WORKER_OK),
99 weak_factory_(this) { 101 weak_factory_(this) {
100 internal_.registration = registration; 102 internal_.registration = registration;
101 } 103 }
102 104
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 Complete(status); 246 Complete(status);
245 return; 247 return;
246 } 248 }
247 249
248 if (!existing_registration.get() || existing_registration->is_uninstalled()) { 250 if (!existing_registration.get() || existing_registration->is_uninstalled()) {
249 RegisterAndContinue(); 251 RegisterAndContinue();
250 return; 252 return;
251 } 253 }
252 254
253 DCHECK(existing_registration->GetNewestVersion()); 255 DCHECK(existing_registration->GetNewestVersion());
254 // "If scriptURL is equal to registration.[[ScriptURL]], then:" 256 // "If scriptURL is equal to registration.[[ScriptURL]] and
255 if (existing_registration->GetNewestVersion()->script_url() == script_url_) { 257 // "update_via_cache is equal to registration.[[update_via_cache]], then:"
258 if (existing_registration->GetNewestVersion()->script_url() == script_url_ &&
259 existing_registration->update_via_cache() == update_via_cache_) {
256 // "Set registration.[[Uninstalling]] to false." 260 // "Set registration.[[Uninstalling]] to false."
257 existing_registration->AbortPendingClear(base::Bind( 261 existing_registration->AbortPendingClear(base::Bind(
258 &ServiceWorkerRegisterJob::ContinueWithRegistrationForSameScriptUrl, 262 &ServiceWorkerRegisterJob::ContinueWithRegistrationForSameScriptUrl,
259 weak_factory_.GetWeakPtr(), 263 weak_factory_.GetWeakPtr(),
260 existing_registration)); 264 existing_registration));
261 return; 265 return;
262 } 266 }
263 267
264 if (existing_registration->is_uninstalling()) { 268 if (existing_registration->is_uninstalling()) {
265 existing_registration->AbortPendingClear(base::Bind( 269 existing_registration->AbortPendingClear(base::Bind(
266 &ServiceWorkerRegisterJob::ContinueWithUninstallingRegistration, 270 &ServiceWorkerRegisterJob::ContinueWithUninstallingRegistration,
267 weak_factory_.GetWeakPtr(), 271 weak_factory_.GetWeakPtr(),
268 existing_registration)); 272 existing_registration));
269 return; 273 return;
270 } 274 }
271 275
276 // "Invoke Set Registration algorithm with job’s scope url and
277 // job’s update via cache mode."
278 existing_registration->set_update_via_cache(update_via_cache_);
279 set_registration(existing_registration);
272 // "Return the result of running the [[Update]] algorithm, or its equivalent, 280 // "Return the result of running the [[Update]] algorithm, or its equivalent,
273 // passing registration as the argument." 281 // passing registration as the argument."
274 set_registration(existing_registration);
275 UpdateAndContinue(); 282 UpdateAndContinue();
276 } 283 }
277 284
278 void ServiceWorkerRegisterJob::ContinueWithUpdate( 285 void ServiceWorkerRegisterJob::ContinueWithUpdate(
279 ServiceWorkerStatusCode status, 286 ServiceWorkerStatusCode status,
280 scoped_refptr<ServiceWorkerRegistration> existing_registration) { 287 scoped_refptr<ServiceWorkerRegistration> existing_registration) {
281 DCHECK_EQ(UPDATE_JOB, job_type_); 288 DCHECK_EQ(UPDATE_JOB, job_type_);
282 if (status != SERVICE_WORKER_OK) { 289 if (status != SERVICE_WORKER_OK) {
283 Complete(status); 290 Complete(status);
284 return; 291 return;
(...skipping 25 matching lines...) Expand all
310 void ServiceWorkerRegisterJob::RegisterAndContinue() { 317 void ServiceWorkerRegisterJob::RegisterAndContinue() {
311 SetPhase(REGISTER); 318 SetPhase(REGISTER);
312 319
313 int64_t registration_id = context_->storage()->NewRegistrationId(); 320 int64_t registration_id = context_->storage()->NewRegistrationId();
314 if (registration_id == kInvalidServiceWorkerRegistrationId) { 321 if (registration_id == kInvalidServiceWorkerRegistrationId) {
315 Complete(SERVICE_WORKER_ERROR_ABORT); 322 Complete(SERVICE_WORKER_ERROR_ABORT);
316 return; 323 return;
317 } 324 }
318 325
319 set_registration(new ServiceWorkerRegistration( 326 set_registration(new ServiceWorkerRegistration(
320 ServiceWorkerRegistrationOptions(pattern_), registration_id, context_)); 327 ServiceWorkerRegistrationOptions(pattern_, update_via_cache_),
328 registration_id, context_));
321 AddRegistrationToMatchingProviderHosts(registration()); 329 AddRegistrationToMatchingProviderHosts(registration());
322 UpdateAndContinue(); 330 UpdateAndContinue();
323 } 331 }
324 332
325 void ServiceWorkerRegisterJob::ContinueWithUninstallingRegistration( 333 void ServiceWorkerRegisterJob::ContinueWithUninstallingRegistration(
326 scoped_refptr<ServiceWorkerRegistration> existing_registration, 334 scoped_refptr<ServiceWorkerRegistration> existing_registration,
327 ServiceWorkerStatusCode status) { 335 ServiceWorkerStatusCode status) {
328 if (status != SERVICE_WORKER_OK) { 336 if (status != SERVICE_WORKER_OK) {
329 Complete(status); 337 Complete(status);
330 return; 338 return;
331 } 339 }
332 should_uninstall_on_failure_ = true; 340 should_uninstall_on_failure_ = true;
333 set_registration(existing_registration); 341 set_registration(existing_registration);
334 UpdateAndContinue(); 342 UpdateAndContinue();
335 } 343 }
336 344
337 void ServiceWorkerRegisterJob::ContinueWithRegistrationForSameScriptUrl( 345 void ServiceWorkerRegisterJob::ContinueWithRegistrationForSameScriptUrl(
338 scoped_refptr<ServiceWorkerRegistration> existing_registration, 346 scoped_refptr<ServiceWorkerRegistration> existing_registration,
339 ServiceWorkerStatusCode status) { 347 ServiceWorkerStatusCode status) {
340 if (status != SERVICE_WORKER_OK) { 348 if (status != SERVICE_WORKER_OK) {
341 Complete(status); 349 Complete(status);
342 return; 350 return;
343 } 351 }
344 set_registration(existing_registration); 352 set_registration(existing_registration);
345 353
346 // "If newestWorker is not null, and scriptURL is equal to 354 // "If newestWorker is not null, scriptURL is equal to newestWorker.scriptURL,
347 // newestWorker.scriptURL, then: 355 // and job’s update via cache mode's value equals registration’s
356 // update via cache mode then:
348 // Return a promise resolved with registration." 357 // Return a promise resolved with registration."
349 // We resolve only if there's an active version. If there's not, 358 // We resolve only if there's an active version. If there's not,
350 // then there is either no version or only a waiting version from 359 // then there is either no version or only a waiting version from
351 // the last browser session; it makes sense to proceed with registration in 360 // the last browser session; it makes sense to proceed with registration in
352 // either case. 361 // either case.
353 DCHECK(!existing_registration->installing_version()); 362 DCHECK(!existing_registration->installing_version());
354 if (existing_registration->active_version()) { 363 if (existing_registration->active_version()) {
355 ResolvePromise(status, std::string(), existing_registration.get()); 364 ResolvePromise(status, std::string(), existing_registration.get());
356 Complete(SERVICE_WORKER_OK); 365 Complete(SERVICE_WORKER_OK);
357 return; 366 return;
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 new_version()->force_bypass_cache_for_scripts() || 672 new_version()->force_bypass_cache_for_scripts() ||
664 registration()->last_update_check().is_null()) { 673 registration()->last_update_check().is_null()) {
665 registration()->set_last_update_check(base::Time::Now()); 674 registration()->set_last_update_check(base::Time::Now());
666 675
667 if (registration()->has_installed_version()) 676 if (registration()->has_installed_version())
668 context_->storage()->UpdateLastUpdateCheckTime(registration()); 677 context_->storage()->UpdateLastUpdateCheckTime(registration());
669 } 678 }
670 } 679 }
671 680
672 } // namespace content 681 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698