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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 if (existing_registration.get() && | 183 if (existing_registration.get() && |
184 existing_registration->script_url() == script_url_) { | 184 existing_registration->script_url() == script_url_) { |
185 set_registration(existing_registration); | 185 set_registration(existing_registration); |
186 // If there's no active version, go ahead to Update (this isn't in the spec | 186 // If there's no active version, go ahead to Update (this isn't in the spec |
187 // but seems reasonable, and without SoftUpdate implemented we can never | 187 // but seems reasonable, and without SoftUpdate implemented we can never |
188 // Update otherwise). | 188 // Update otherwise). |
189 if (!existing_registration->active_version()) { | 189 if (!existing_registration->active_version()) { |
190 UpdateAndContinue(); | 190 UpdateAndContinue(); |
191 return; | 191 return; |
192 } | 192 } |
| 193 |
| 194 existing_registration->active_version()->AddPendingProcesses( |
| 195 pending_process_ids_); |
193 ResolvePromise( | 196 ResolvePromise( |
194 status, existing_registration, existing_registration->active_version()); | 197 status, existing_registration, existing_registration->active_version()); |
195 Complete(SERVICE_WORKER_OK); | 198 Complete(SERVICE_WORKER_OK); |
196 return; | 199 return; |
197 } | 200 } |
198 | 201 |
199 // "If serviceWorkerRegistration is null..." create a new registration. | 202 // "If serviceWorkerRegistration is null..." create a new registration. |
200 if (!existing_registration.get()) { | 203 if (!existing_registration.get()) { |
201 RegisterAndContinue(SERVICE_WORKER_OK); | 204 RegisterAndContinue(SERVICE_WORKER_OK); |
202 return; | 205 return; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 // TODO(falken): "If serviceWorkerRegistration.installingWorker is not null.." | 262 // TODO(falken): "If serviceWorkerRegistration.installingWorker is not null.." |
260 // then terminate the installing worker. It doesn't make sense to implement | 263 // then terminate the installing worker. It doesn't make sense to implement |
261 // yet since we always activate the worker if install completed, so there can | 264 // yet since we always activate the worker if install completed, so there can |
262 // be no installing worker at this point. | 265 // be no installing worker at this point. |
263 | 266 |
264 // "Let serviceWorker be a newly-created ServiceWorker object..." and start | 267 // "Let serviceWorker be a newly-created ServiceWorker object..." and start |
265 // the worker. | 268 // the worker. |
266 set_new_version(new ServiceWorkerVersion( | 269 set_new_version(new ServiceWorkerVersion( |
267 registration(), context_->storage()->NewVersionId(), context_)); | 270 registration(), context_->storage()->NewVersionId(), context_)); |
268 | 271 |
| 272 new_version()->AddPendingProcesses(pending_process_ids_); |
269 bool pause_after_download = job_type_ == UPDATE_JOB; | 273 bool pause_after_download = job_type_ == UPDATE_JOB; |
270 if (pause_after_download) | 274 if (pause_after_download) |
271 new_version()->embedded_worker()->AddListener(this); | 275 new_version()->embedded_worker()->AddListener(this); |
272 new_version()->StartWorkerWithCandidateProcesses( | 276 new_version()->StartWorker( |
273 pending_process_ids_, | |
274 pause_after_download, | 277 pause_after_download, |
275 base::Bind(&ServiceWorkerRegisterJob::OnStartWorkerFinished, | 278 base::Bind(&ServiceWorkerRegisterJob::OnStartWorkerFinished, |
276 weak_factory_.GetWeakPtr())); | 279 weak_factory_.GetWeakPtr())); |
277 } | 280 } |
278 | 281 |
279 void ServiceWorkerRegisterJob::OnStartWorkerFinished( | 282 void ServiceWorkerRegisterJob::OnStartWorkerFinished( |
280 ServiceWorkerStatusCode status) { | 283 ServiceWorkerStatusCode status) { |
281 // "If serviceWorker fails to start up..." then reject the promise with an | 284 // "If serviceWorker fails to start up..." then reject the promise with an |
282 // error and abort. | 285 // error and abort. |
283 if (status != SERVICE_WORKER_OK) { | 286 if (status != SERVICE_WORKER_OK) { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 ServiceWorkerProviderHost* host = it->GetProviderHost(); | 464 ServiceWorkerProviderHost* host = it->GetProviderHost(); |
462 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(), | 465 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(), |
463 host->document_url())) { | 466 host->document_url())) { |
464 if (host->CanAssociateRegistration(registration)) | 467 if (host->CanAssociateRegistration(registration)) |
465 host->AssociateRegistration(registration); | 468 host->AssociateRegistration(registration); |
466 } | 469 } |
467 } | 470 } |
468 } | 471 } |
469 | 472 |
470 } // namespace content | 473 } // namespace content |
OLD | NEW |