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

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 tests Created 3 years, 8 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 19 matching lines...) Expand all
30 void RunSoon(const base::Closure& closure) { 30 void RunSoon(const base::Closure& closure) {
31 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure); 31 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure);
32 } 32 }
33 33
34 } // namespace 34 } // namespace
35 35
36 typedef ServiceWorkerRegisterJobBase::RegistrationJobType RegistrationJobType; 36 typedef ServiceWorkerRegisterJobBase::RegistrationJobType RegistrationJobType;
37 37
38 ServiceWorkerRegisterJob::ServiceWorkerRegisterJob( 38 ServiceWorkerRegisterJob::ServiceWorkerRegisterJob(
39 base::WeakPtr<ServiceWorkerContextCore> context, 39 base::WeakPtr<ServiceWorkerContextCore> context,
40 const GURL& pattern, 40 const GURL& script_url,
41 const GURL& script_url) 41 const ServiceWorkerRegistrationOptions& options)
42 : context_(context), 42 : context_(context),
43 job_type_(REGISTRATION_JOB), 43 job_type_(REGISTRATION_JOB),
44 pattern_(pattern), 44 pattern_(options.scope),
45 script_url_(script_url), 45 script_url_(script_url),
46 use_cache_(options.use_cache ==
47 ServiceWorkerRegistrationOptions::UseCache::Use),
46 phase_(INITIAL), 48 phase_(INITIAL),
47 doom_installing_worker_(false), 49 doom_installing_worker_(false),
48 is_promise_resolved_(false), 50 is_promise_resolved_(false),
49 should_uninstall_on_failure_(false), 51 should_uninstall_on_failure_(false),
50 force_bypass_cache_(false), 52 force_bypass_cache_(false),
51 skip_script_comparison_(false), 53 skip_script_comparison_(false),
52 promise_resolved_status_(SERVICE_WORKER_OK), 54 promise_resolved_status_(SERVICE_WORKER_OK),
53 weak_factory_(this) {} 55 weak_factory_(this) {}
54 56
55 ServiceWorkerRegisterJob::ServiceWorkerRegisterJob( 57 ServiceWorkerRegisterJob::ServiceWorkerRegisterJob(
56 base::WeakPtr<ServiceWorkerContextCore> context, 58 base::WeakPtr<ServiceWorkerContextCore> context,
57 ServiceWorkerRegistration* registration, 59 ServiceWorkerRegistration* registration,
58 bool force_bypass_cache, 60 bool force_bypass_cache,
59 bool skip_script_comparison) 61 bool skip_script_comparison)
60 : context_(context), 62 : context_(context),
61 job_type_(UPDATE_JOB), 63 job_type_(UPDATE_JOB),
62 pattern_(registration->pattern()), 64 pattern_(registration->pattern()),
65 use_cache_(registration->use_cache()),
63 phase_(INITIAL), 66 phase_(INITIAL),
64 doom_installing_worker_(false), 67 doom_installing_worker_(false),
65 is_promise_resolved_(false), 68 is_promise_resolved_(false),
66 should_uninstall_on_failure_(false), 69 should_uninstall_on_failure_(false),
67 force_bypass_cache_(force_bypass_cache), 70 force_bypass_cache_(force_bypass_cache),
68 skip_script_comparison_(skip_script_comparison), 71 skip_script_comparison_(skip_script_comparison),
69 promise_resolved_status_(SERVICE_WORKER_OK), 72 promise_resolved_status_(SERVICE_WORKER_OK),
70 weak_factory_(this) { 73 weak_factory_(this) {
71 internal_.registration = registration; 74 internal_.registration = registration;
72 } 75 }
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 // Creates a new ServiceWorkerRegistration. 284 // Creates a new ServiceWorkerRegistration.
282 void ServiceWorkerRegisterJob::RegisterAndContinue() { 285 void ServiceWorkerRegisterJob::RegisterAndContinue() {
283 SetPhase(REGISTER); 286 SetPhase(REGISTER);
284 287
285 int64_t registration_id = context_->storage()->NewRegistrationId(); 288 int64_t registration_id = context_->storage()->NewRegistrationId();
286 if (registration_id == kInvalidServiceWorkerRegistrationId) { 289 if (registration_id == kInvalidServiceWorkerRegistrationId) {
287 Complete(SERVICE_WORKER_ERROR_ABORT); 290 Complete(SERVICE_WORKER_ERROR_ABORT);
288 return; 291 return;
289 } 292 }
290 293
291 set_registration( 294 set_registration(new ServiceWorkerRegistration(pattern_, use_cache_,
292 new ServiceWorkerRegistration(pattern_, registration_id, context_)); 295 registration_id, context_));
293 AddRegistrationToMatchingProviderHosts(registration()); 296 AddRegistrationToMatchingProviderHosts(registration());
294 UpdateAndContinue(); 297 UpdateAndContinue();
295 } 298 }
296 299
297 void ServiceWorkerRegisterJob::ContinueWithUninstallingRegistration( 300 void ServiceWorkerRegisterJob::ContinueWithUninstallingRegistration(
298 scoped_refptr<ServiceWorkerRegistration> existing_registration, 301 scoped_refptr<ServiceWorkerRegistration> existing_registration,
299 ServiceWorkerStatusCode status) { 302 ServiceWorkerStatusCode status) {
300 if (status != SERVICE_WORKER_OK) { 303 if (status != SERVICE_WORKER_OK) {
301 Complete(status); 304 Complete(status);
302 return; 305 return;
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 new_version()->force_bypass_cache_for_scripts() || 651 new_version()->force_bypass_cache_for_scripts() ||
649 registration()->last_update_check().is_null()) { 652 registration()->last_update_check().is_null()) {
650 registration()->set_last_update_check(base::Time::Now()); 653 registration()->set_last_update_check(base::Time::Now());
651 654
652 if (registration()->has_installed_version()) 655 if (registration()->has_installed_version())
653 context_->storage()->UpdateLastUpdateCheckTime(registration()); 656 context_->storage()->UpdateLastUpdateCheckTime(registration());
654 } 657 }
655 } 658 }
656 659
657 } // namespace content 660 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698