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

Side by Side Diff: content/browser/service_worker/service_worker_register_job.cc

Issue 443593002: ServiceWorker: Move worker candidate process knowledge to ServiceWorkerProcessManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 <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
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 && (phase_ < UPDATE || !new_version()))
66 pending_process_ids_.push_back(process_id); 67 pending_provider_hosts_.push_back(provider_host->AsWeakPtr());
michaeln 2014/09/04 01:26:32 Why defer till later? Maybe we don't need the pend
xiang 2014/09/04 09:18:37 Yes, you're right, we don't need to pend it anymor
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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // "Let serviceWorker be a newly-created ServiceWorker object..." and start 316 // "Let serviceWorker be a newly-created ServiceWorker object..." and start
316 // the worker. 317 // the worker.
317 set_new_version(new ServiceWorkerVersion(registration(), 318 set_new_version(new ServiceWorkerVersion(registration(),
318 script_url_, 319 script_url_,
319 context_->storage()->NewVersionId(), 320 context_->storage()->NewVersionId(),
320 context_)); 321 context_));
321 322
322 bool pause_after_download = job_type_ == UPDATE_JOB; 323 bool pause_after_download = job_type_ == UPDATE_JOB;
323 if (pause_after_download) 324 if (pause_after_download)
324 new_version()->embedded_worker()->AddListener(this); 325 new_version()->embedded_worker()->AddListener(this);
325 new_version()->StartWorkerWithCandidateProcesses( 326 AssociateProviderHostsToPendingRegistration(registration());
326 pending_process_ids_, 327 new_version()->StartWorker(
327 pause_after_download, 328 pause_after_download,
328 base::Bind(&ServiceWorkerRegisterJob::OnStartWorkerFinished, 329 base::Bind(&ServiceWorkerRegisterJob::OnStartWorkerFinished,
329 weak_factory_.GetWeakPtr())); 330 weak_factory_.GetWeakPtr()));
330 } 331 }
331 332
332 void ServiceWorkerRegisterJob::OnStartWorkerFinished( 333 void ServiceWorkerRegisterJob::OnStartWorkerFinished(
333 ServiceWorkerStatusCode status) { 334 ServiceWorkerStatusCode status) {
334 // "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
335 // error and abort. 336 // error and abort.
336 if (status != SERVICE_WORKER_OK) { 337 if (status != SERVICE_WORKER_OK) {
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 !it->IsAtEnd(); it->Advance()) { 534 !it->IsAtEnd(); it->Advance()) {
534 ServiceWorkerProviderHost* host = it->GetProviderHost(); 535 ServiceWorkerProviderHost* host = it->GetProviderHost();
535 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(), 536 if (ServiceWorkerUtils::ScopeMatches(registration->pattern(),
536 host->document_url())) { 537 host->document_url())) {
537 if (host->CanAssociateRegistration(registration)) 538 if (host->CanAssociateRegistration(registration))
538 host->AssociateRegistration(registration); 539 host->AssociateRegistration(registration);
539 } 540 }
540 } 541 }
541 } 542 }
542 543
544 void ServiceWorkerRegisterJob::AssociateProviderHostsToPendingRegistration(
545 ServiceWorkerRegistration* registration) {
546 DCHECK(registration);
547 for (std::vector<base::WeakPtr<ServiceWorkerProviderHost> >::iterator it =
548 pending_provider_hosts_.begin();
549 it != pending_provider_hosts_.end(); ++it) {
550 if (*it)
551 (*it)->AssociatePendingRegistration(registration);
552 }
553 }
554
543 } // namespace content 555 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698