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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "content/browser/service_worker/service_worker_context_core.h" | 10 #include "content/browser/service_worker/service_worker_context_core.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 provider_host->AddScopedProcessReferenceToPattern(pattern_); | 74 provider_host->AddScopedProcessReferenceToPattern(pattern_); |
75 return; | 75 return; |
76 } | 76 } |
77 RunSoon(base::Bind(callback, promise_resolved_status_, | 77 RunSoon(base::Bind(callback, promise_resolved_status_, |
78 promise_resolved_status_message_, | 78 promise_resolved_status_message_, |
79 promise_resolved_registration_)); | 79 promise_resolved_registration_)); |
80 } | 80 } |
81 | 81 |
82 void ServiceWorkerRegisterJob::Start() { | 82 void ServiceWorkerRegisterJob::Start() { |
83 SetPhase(START); | 83 SetPhase(START); |
| 84 |
| 85 if (IsBrowserStartingUp()) { |
| 86 // Delay running update jobs until after startup. |
| 87 const base::TimeDelta kRetryInterval = base::TimeDelta::FromSeconds(15); |
| 88 delayed_start_timer_.Start( |
| 89 FROM_HERE, kRetryInterval, |
| 90 base::Bind(&ServiceWorkerRegisterJob::Restart, |
| 91 weak_factory_.GetWeakPtr())); |
| 92 return; |
| 93 } |
| 94 |
84 ServiceWorkerStorage::FindRegistrationCallback next_step; | 95 ServiceWorkerStorage::FindRegistrationCallback next_step; |
85 if (job_type_ == REGISTRATION_JOB) { | 96 if (job_type_ == REGISTRATION_JOB) { |
86 next_step = base::Bind( | 97 next_step = base::Bind( |
87 &ServiceWorkerRegisterJob::ContinueWithRegistration, | 98 &ServiceWorkerRegisterJob::ContinueWithRegistration, |
88 weak_factory_.GetWeakPtr()); | 99 weak_factory_.GetWeakPtr()); |
89 } else { | 100 } else { |
90 next_step = base::Bind( | 101 next_step = base::Bind( |
91 &ServiceWorkerRegisterJob::ContinueWithUpdate, | 102 &ServiceWorkerRegisterJob::ContinueWithUpdate, |
92 weak_factory_.GetWeakPtr()); | 103 weak_factory_.GetWeakPtr()); |
93 } | 104 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 break; | 187 break; |
177 case COMPLETE: | 188 case COMPLETE: |
178 DCHECK(phase_ != INITIAL && phase_ != COMPLETE) << phase_; | 189 DCHECK(phase_ != INITIAL && phase_ != COMPLETE) << phase_; |
179 break; | 190 break; |
180 case ABORT: | 191 case ABORT: |
181 break; | 192 break; |
182 } | 193 } |
183 phase_ = phase; | 194 phase_ = phase; |
184 } | 195 } |
185 | 196 |
| 197 void ServiceWorkerRegisterJob::Restart() { |
| 198 DCHECK(phase_ == START) << phase_; |
| 199 phase_ = INITIAL; |
| 200 Start(); |
| 201 } |
| 202 |
186 // This function corresponds to the steps in [[Register]] following | 203 // This function corresponds to the steps in [[Register]] following |
187 // "Let registration be the result of running the [[GetRegistration]] algorithm. | 204 // "Let registration be the result of running the [[GetRegistration]] algorithm. |
188 // Throughout this file, comments in quotes are excerpts from the spec. | 205 // Throughout this file, comments in quotes are excerpts from the spec. |
189 void ServiceWorkerRegisterJob::ContinueWithRegistration( | 206 void ServiceWorkerRegisterJob::ContinueWithRegistration( |
190 ServiceWorkerStatusCode status, | 207 ServiceWorkerStatusCode status, |
191 const scoped_refptr<ServiceWorkerRegistration>& existing_registration) { | 208 const scoped_refptr<ServiceWorkerRegistration>& existing_registration) { |
192 DCHECK_EQ(REGISTRATION_JOB, job_type_); | 209 DCHECK_EQ(REGISTRATION_JOB, job_type_); |
193 if (status != SERVICE_WORKER_ERROR_NOT_FOUND && status != SERVICE_WORKER_OK) { | 210 if (status != SERVICE_WORKER_ERROR_NOT_FOUND && status != SERVICE_WORKER_OK) { |
194 Complete(status); | 211 Complete(status); |
195 return; | 212 return; |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 ServiceWorkerProviderHost* host = it->GetProviderHost(); | 573 ServiceWorkerProviderHost* host = it->GetProviderHost(); |
557 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(), | 574 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(), |
558 host->document_url())) { | 575 host->document_url())) { |
559 if (host->CanAssociateRegistration(registration)) | 576 if (host->CanAssociateRegistration(registration)) |
560 host->AssociateRegistration(registration); | 577 host->AssociateRegistration(registration); |
561 } | 578 } |
562 } | 579 } |
563 } | 580 } |
564 | 581 |
565 } // namespace content | 582 } // namespace content |
OLD | NEW |