| 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 25 matching lines...) Expand all Loading... |
| 36 is_promise_resolved_(false), | 36 is_promise_resolved_(false), |
| 37 promise_resolved_status_(SERVICE_WORKER_OK), | 37 promise_resolved_status_(SERVICE_WORKER_OK), |
| 38 weak_factory_(this) {} | 38 weak_factory_(this) {} |
| 39 | 39 |
| 40 ServiceWorkerRegisterJob::~ServiceWorkerRegisterJob() { | 40 ServiceWorkerRegisterJob::~ServiceWorkerRegisterJob() { |
| 41 DCHECK(phase_ == INITIAL || phase_ == COMPLETE); | 41 DCHECK(phase_ == INITIAL || phase_ == COMPLETE); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void ServiceWorkerRegisterJob::AddCallback(const RegistrationCallback& callback, | 44 void ServiceWorkerRegisterJob::AddCallback(const RegistrationCallback& callback, |
| 45 int process_id) { | 45 int process_id) { |
| 46 DCHECK_NE(-1, process_id); | |
| 47 if (phase_ >= UPDATE && pending_version()) | |
| 48 pending_version()->AddProcessToWorker(process_id); | |
| 49 else | |
| 50 pending_process_ids_.push_back(process_id); | |
| 51 | |
| 52 if (!is_promise_resolved_) { | 46 if (!is_promise_resolved_) { |
| 53 callbacks_.push_back(callback); | 47 callbacks_.push_back(callback); |
| 48 if (process_id != -1 && (phase_ < UPDATE || !pending_version())) |
| 49 pending_process_ids_.push_back(process_id); |
| 54 return; | 50 return; |
| 55 } | 51 } |
| 56 RunSoon(base::Bind( | 52 RunSoon(base::Bind( |
| 57 callback, promise_resolved_status_, | 53 callback, promise_resolved_status_, |
| 58 promise_resolved_registration_, promise_resolved_version_)); | 54 promise_resolved_registration_, promise_resolved_version_)); |
| 59 } | 55 } |
| 60 | 56 |
| 61 void ServiceWorkerRegisterJob::Start() { | 57 void ServiceWorkerRegisterJob::Start() { |
| 62 SetPhase(START); | 58 SetPhase(START); |
| 63 context_->storage()->FindRegistrationForPattern( | 59 context_->storage()->FindRegistrationForPattern( |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 // TODO(falken): "If serviceWorkerRegistration.pendingWorker is not null..." | 217 // TODO(falken): "If serviceWorkerRegistration.pendingWorker is not null..." |
| 222 // then terminate the pending worker. It doesn't make sense to implement yet | 218 // then terminate the pending worker. It doesn't make sense to implement yet |
| 223 // since we always activate the worker if install completed, so there can be | 219 // since we always activate the worker if install completed, so there can be |
| 224 // no pending worker at this point. | 220 // no pending worker at this point. |
| 225 DCHECK(!registration()->pending_version()); | 221 DCHECK(!registration()->pending_version()); |
| 226 | 222 |
| 227 // "Let serviceWorker be a newly-created ServiceWorker object..." and start | 223 // "Let serviceWorker be a newly-created ServiceWorker object..." and start |
| 228 // the worker. | 224 // the worker. |
| 229 set_pending_version(new ServiceWorkerVersion( | 225 set_pending_version(new ServiceWorkerVersion( |
| 230 registration(), context_->storage()->NewVersionId(), context_)); | 226 registration(), context_->storage()->NewVersionId(), context_)); |
| 231 for (std::vector<int>::const_iterator it = pending_process_ids_.begin(); | |
| 232 it != pending_process_ids_.end(); | |
| 233 ++it) { | |
| 234 pending_version()->AddProcessToWorker(*it); | |
| 235 } | |
| 236 | 227 |
| 237 // TODO(michaeln): Start the worker into a paused state where the | 228 // TODO(michaeln): Start the worker into a paused state where the |
| 238 // script resource is downloaded but not yet evaluated. | 229 // script resource is downloaded but not yet evaluated. |
| 239 pending_version()->StartWorker( | 230 pending_version()->StartWorker( |
| 240 base::Bind(&ServiceWorkerRegisterJob::OnStartWorkerFinished, | 231 base::Bind(&ServiceWorkerRegisterJob::OnStartWorkerFinished, |
| 241 weak_factory_.GetWeakPtr())); | 232 weak_factory_.GetWeakPtr()), |
| 233 pending_process_ids_); |
| 242 } | 234 } |
| 243 | 235 |
| 244 void ServiceWorkerRegisterJob::OnStartWorkerFinished( | 236 void ServiceWorkerRegisterJob::OnStartWorkerFinished( |
| 245 ServiceWorkerStatusCode status) { | 237 ServiceWorkerStatusCode status) { |
| 246 // "If serviceWorker fails to start up..." then reject the promise with an | 238 // "If serviceWorker fails to start up..." then reject the promise with an |
| 247 // error and abort. | 239 // error and abort. |
| 248 if (status != SERVICE_WORKER_OK) { | 240 if (status != SERVICE_WORKER_OK) { |
| 249 Complete(status); | 241 Complete(status); |
| 250 return; | 242 return; |
| 251 } | 243 } |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 !it->IsAtEnd(); | 404 !it->IsAtEnd(); |
| 413 it->Advance()) { | 405 it->Advance()) { |
| 414 ServiceWorkerProviderHost* provider_host = it->GetProviderHost(); | 406 ServiceWorkerProviderHost* provider_host = it->GetProviderHost(); |
| 415 if (ServiceWorkerUtils::ScopeMatches(pattern_, | 407 if (ServiceWorkerUtils::ScopeMatches(pattern_, |
| 416 provider_host->document_url())) | 408 provider_host->document_url())) |
| 417 provider_host->SetPendingVersion(version); | 409 provider_host->SetPendingVersion(version); |
| 418 } | 410 } |
| 419 } | 411 } |
| 420 | 412 |
| 421 } // namespace content | 413 } // namespace content |
| OLD | NEW |