| Index: content/browser/service_worker/service_worker_provider_host.cc
|
| diff --git a/content/browser/service_worker/service_worker_provider_host.cc b/content/browser/service_worker/service_worker_provider_host.cc
|
| index e16454558e0ec9cc46862b3110a811dcf3bfca6f..8157d2c012af858a5c1990a00e9a16a30aecb0cb 100644
|
| --- a/content/browser/service_worker/service_worker_provider_host.cc
|
| +++ b/content/browser/service_worker/service_worker_provider_host.cc
|
| @@ -17,6 +17,7 @@
|
| #include "content/common/resource_request_body.h"
|
| #include "content/common/service_worker/service_worker_messages.h"
|
| #include "content/common/service_worker/service_worker_types.h"
|
| +#include "content/public/common/child_process_host.h"
|
|
|
| namespace content {
|
|
|
| @@ -31,6 +32,7 @@ ServiceWorkerProviderHost::ServiceWorkerProviderHost(
|
| context_(context),
|
| dispatcher_host_(dispatcher_host),
|
| allow_association_(true) {
|
| + DCHECK_NE(ChildProcessHost::kInvalidUniqueID, process_id_);
|
| }
|
|
|
| ServiceWorkerProviderHost::~ServiceWorkerProviderHost() {
|
| @@ -43,10 +45,9 @@ ServiceWorkerProviderHost::~ServiceWorkerProviderHost() {
|
| DecreaseProcessReference(associated_registration_->pattern());
|
| associated_registration_->RemoveListener(this);
|
| }
|
| - for (std::vector<GURL>::iterator it = associated_patterns_.begin();
|
| - it != associated_patterns_.end(); ++it) {
|
| - DecreaseProcessReference(*it);
|
| - }
|
| +
|
| + for (const GURL& pattern : associated_patterns_)
|
| + DecreaseProcessReference(pattern);
|
| }
|
|
|
| void ServiceWorkerProviderHost::OnRegistrationFailed(
|
| @@ -112,25 +113,9 @@ void ServiceWorkerProviderHost::AssociateRegistration(
|
| DecreaseProcessReference(associated_registration_->pattern());
|
| IncreaseProcessReference(registration->pattern());
|
|
|
| - if (dispatcher_host_) {
|
| - ServiceWorkerRegistrationHandle* handle =
|
| - dispatcher_host_->GetOrCreateRegistrationHandle(
|
| - provider_id(), registration);
|
| -
|
| - ServiceWorkerVersionAttributes attrs;
|
| - attrs.installing = handle->CreateServiceWorkerHandleAndPass(
|
| - registration->installing_version());
|
| - attrs.waiting = handle->CreateServiceWorkerHandleAndPass(
|
| - registration->waiting_version());
|
| - attrs.active = handle->CreateServiceWorkerHandleAndPass(
|
| - registration->active_version());
|
| -
|
| - dispatcher_host_->Send(new ServiceWorkerMsg_AssociateRegistration(
|
| - kDocumentMainThreadId, provider_id(), handle->GetObjectInfo(), attrs));
|
| - }
|
| -
|
| associated_registration_ = registration;
|
| associated_registration_->AddListener(this);
|
| + SendAssociateRegistrationMessage();
|
| SetControllerVersionAttribute(registration->active_version());
|
| }
|
|
|
| @@ -214,6 +199,65 @@ void ServiceWorkerProviderHost::AddScopedProcessReferenceToPattern(
|
| IncreaseProcessReference(pattern);
|
| }
|
|
|
| +void ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() {
|
| + DCHECK_NE(ChildProcessHost::kInvalidUniqueID, process_id_);
|
| +
|
| + for (const GURL& pattern : associated_patterns_)
|
| + DecreaseProcessReference(pattern);
|
| +
|
| + if (associated_registration_.get())
|
| + DecreaseProcessReference(associated_registration_->pattern());
|
| +
|
| + process_id_ = ChildProcessHost::kInvalidUniqueID;
|
| + provider_id_ = kInvalidServiceWorkerProviderId;
|
| + dispatcher_host_ = nullptr;
|
| +}
|
| +
|
| +void ServiceWorkerProviderHost::CompleteCrossSiteTransfer(
|
| + int new_process_id,
|
| + int new_provider_id,
|
| + ServiceWorkerDispatcherHost* new_dispatcher_host) {
|
| + DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, process_id_);
|
| + DCHECK_NE(ChildProcessHost::kInvalidUniqueID, new_process_id);
|
| +
|
| + process_id_ = new_process_id;
|
| + provider_id_ = new_provider_id;
|
| + dispatcher_host_ = new_dispatcher_host;
|
| +
|
| + for (const GURL& pattern : associated_patterns_)
|
| + IncreaseProcessReference(pattern);
|
| +
|
| + if (associated_registration_.get()) {
|
| + IncreaseProcessReference(associated_registration_->pattern());
|
| + SendAssociateRegistrationMessage();
|
| + if (dispatcher_host_ && associated_registration_->active_version()) {
|
| + dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker(
|
| + kDocumentMainThreadId, provider_id(),
|
| + CreateHandleAndPass(associated_registration_->active_version())));
|
| + }
|
| + }
|
| +}
|
| +
|
| +void ServiceWorkerProviderHost::SendAssociateRegistrationMessage() {
|
| + if (!dispatcher_host_)
|
| + return;
|
| +
|
| + ServiceWorkerRegistrationHandle* handle =
|
| + dispatcher_host_->GetOrCreateRegistrationHandle(
|
| + provider_id(), associated_registration_.get());
|
| +
|
| + ServiceWorkerVersionAttributes attrs;
|
| + attrs.installing = handle->CreateServiceWorkerHandleAndPass(
|
| + associated_registration_->installing_version());
|
| + attrs.waiting = handle->CreateServiceWorkerHandleAndPass(
|
| + associated_registration_->waiting_version());
|
| + attrs.active = handle->CreateServiceWorkerHandleAndPass(
|
| + associated_registration_->active_version());
|
| +
|
| + dispatcher_host_->Send(new ServiceWorkerMsg_AssociateRegistration(
|
| + kDocumentMainThreadId, provider_id(), handle->GetObjectInfo(), attrs));
|
| +}
|
| +
|
| ServiceWorkerObjectInfo ServiceWorkerProviderHost::CreateHandleAndPass(
|
| ServiceWorkerVersion* version) {
|
| ServiceWorkerObjectInfo info;
|
|
|