| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 weak_factory_(this) { | 51 weak_factory_(this) { |
| 52 internal_.registration = registration; | 52 internal_.registration = registration; |
| 53 } | 53 } |
| 54 | 54 |
| 55 ServiceWorkerRegisterJob::~ServiceWorkerRegisterJob() { | 55 ServiceWorkerRegisterJob::~ServiceWorkerRegisterJob() { |
| 56 DCHECK(!context_ || | 56 DCHECK(!context_ || |
| 57 phase_ == INITIAL || phase_ == COMPLETE || phase_ == ABORT) | 57 phase_ == INITIAL || phase_ == COMPLETE || phase_ == ABORT) |
| 58 << "Jobs should only be interrupted during shutdown."; | 58 << "Jobs should only be interrupted during shutdown."; |
| 59 } | 59 } |
| 60 | 60 |
| 61 void ServiceWorkerRegisterJob::AddCallback(const RegistrationCallback& callback, | 61 void ServiceWorkerRegisterJob::AddCallback( |
| 62 int process_id) { | 62 const RegistrationCallback& callback, |
| 63 ServiceWorkerProviderHost* provider_host) { |
| 63 if (!is_promise_resolved_) { | 64 if (!is_promise_resolved_) { |
| 64 callbacks_.push_back(callback); | 65 callbacks_.push_back(callback); |
| 65 if (process_id != -1 && (phase_ < UPDATE || !new_version())) | 66 if (provider_host) |
| 66 pending_process_ids_.push_back(process_id); | 67 provider_host->AddScopedProcessReferenceToPattern(pattern_); |
| 67 return; | 68 return; |
| 68 } | 69 } |
| 69 RunSoon(base::Bind( | 70 RunSoon(base::Bind( |
| 70 callback, promise_resolved_status_, | 71 callback, promise_resolved_status_, |
| 71 promise_resolved_registration_, promise_resolved_version_)); | 72 promise_resolved_registration_, promise_resolved_version_)); |
| 72 } | 73 } |
| 73 | 74 |
| 74 void ServiceWorkerRegisterJob::Start() { | 75 void ServiceWorkerRegisterJob::Start() { |
| 75 SetPhase(START); | 76 SetPhase(START); |
| 76 ServiceWorkerStorage::FindRegistrationCallback next_step; | 77 ServiceWorkerStorage::FindRegistrationCallback next_step; |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 // "Let serviceWorker be a newly-created ServiceWorker object..." and start | 317 // "Let serviceWorker be a newly-created ServiceWorker object..." and start |
| 317 // the worker. | 318 // the worker. |
| 318 set_new_version(new ServiceWorkerVersion(registration(), | 319 set_new_version(new ServiceWorkerVersion(registration(), |
| 319 script_url_, | 320 script_url_, |
| 320 context_->storage()->NewVersionId(), | 321 context_->storage()->NewVersionId(), |
| 321 context_)); | 322 context_)); |
| 322 | 323 |
| 323 bool pause_after_download = job_type_ == UPDATE_JOB; | 324 bool pause_after_download = job_type_ == UPDATE_JOB; |
| 324 if (pause_after_download) | 325 if (pause_after_download) |
| 325 new_version()->embedded_worker()->AddListener(this); | 326 new_version()->embedded_worker()->AddListener(this); |
| 326 new_version()->StartWorkerWithCandidateProcesses( | 327 new_version()->StartWorker( |
| 327 pending_process_ids_, | |
| 328 pause_after_download, | 328 pause_after_download, |
| 329 base::Bind(&ServiceWorkerRegisterJob::OnStartWorkerFinished, | 329 base::Bind(&ServiceWorkerRegisterJob::OnStartWorkerFinished, |
| 330 weak_factory_.GetWeakPtr())); | 330 weak_factory_.GetWeakPtr())); |
| 331 } | 331 } |
| 332 | 332 |
| 333 void ServiceWorkerRegisterJob::OnStartWorkerFinished( | 333 void ServiceWorkerRegisterJob::OnStartWorkerFinished( |
| 334 ServiceWorkerStatusCode status) { | 334 ServiceWorkerStatusCode status) { |
| 335 // "If serviceWorker fails to start up..." then reject the promise with an | 335 // "If serviceWorker fails to start up..." then reject the promise with an |
| 336 // error and abort. | 336 // error and abort. |
| 337 if (status != SERVICE_WORKER_OK) { | 337 if (status != SERVICE_WORKER_OK) { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 ServiceWorkerProviderHost* host = it->GetProviderHost(); | 536 ServiceWorkerProviderHost* host = it->GetProviderHost(); |
| 537 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(), | 537 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(), |
| 538 host->document_url())) { | 538 host->document_url())) { |
| 539 if (host->CanAssociateRegistration(registration)) | 539 if (host->CanAssociateRegistration(registration)) |
| 540 host->AssociateRegistration(registration); | 540 host->AssociateRegistration(registration); |
| 541 } | 541 } |
| 542 } | 542 } |
| 543 } | 543 } |
| 544 | 544 |
| 545 } // namespace content | 545 } // namespace content |
| OLD | NEW |