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 8e1d43ccc8a8518986d60fa0caec93eb819b32c3..3c65aa7c8cf8c1408fdc878c78129fd998f1be4f 100644 |
--- a/content/browser/service_worker/service_worker_provider_host.cc |
+++ b/content/browser/service_worker/service_worker_provider_host.cc |
@@ -37,14 +37,15 @@ ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { |
document_url_ = GURL(); |
if (controlling_version_.get()) |
controlling_version_->RemoveControllee(this); |
- if (active_version_.get()) |
- active_version_->RemovePotentialControllee(this); |
- if (waiting_version_.get()) |
- waiting_version_->RemovePotentialControllee(this); |
- if (installing_version_.get()) |
- installing_version_->RemovePotentialControllee(this); |
- if (associated_registration_.get()) |
+ if (associated_registration_.get()) { |
+ DecreaseProcessReference(associated_registration_); |
associated_registration_->RemoveListener(this); |
+ } |
+ for (std::vector<scoped_refptr<ServiceWorkerRegistration> >::iterator it = |
+ pending_registrations_.begin(); |
+ it != pending_registrations_.end(); ++it) { |
+ DecreaseProcessReference(it->get()); |
+ } |
} |
void ServiceWorkerProviderHost::OnVersionAttributesChanged( |
@@ -52,9 +53,9 @@ void ServiceWorkerProviderHost::OnVersionAttributesChanged( |
ChangedVersionAttributesMask changed_mask, |
const ServiceWorkerRegistrationInfo& info) { |
DCHECK_EQ(associated_registration_.get(), registration); |
- UpdatePotentialControllees(registration->installing_version(), |
- registration->waiting_version(), |
- registration->active_version()); |
+ installing_version_ = registration->installing_version(); |
+ waiting_version_ = registration->waiting_version(); |
+ active_version_ = registration->active_version(); |
} |
void ServiceWorkerProviderHost::OnRegistrationFailed( |
@@ -68,38 +69,6 @@ void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { |
document_url_ = url; |
} |
-void ServiceWorkerProviderHost::UpdatePotentialControllees( |
- ServiceWorkerVersion* installing_version, |
- ServiceWorkerVersion* waiting_version, |
- ServiceWorkerVersion* active_version) { |
- if (installing_version != installing_version_.get()) { |
- scoped_refptr<ServiceWorkerVersion> previous_version = installing_version_; |
- if (previous_version) |
- previous_version->RemovePotentialControllee(this); |
- if (installing_version) |
- installing_version->AddPotentialControllee(this); |
- installing_version_ = installing_version; |
- } |
- |
- if (waiting_version != waiting_version_.get()) { |
- scoped_refptr<ServiceWorkerVersion> previous_version = waiting_version_; |
- if (previous_version) |
- previous_version->RemovePotentialControllee(this); |
- if (waiting_version) |
- waiting_version->AddPotentialControllee(this); |
- waiting_version_ = waiting_version; |
- } |
- |
- if (active_version != active_version_.get()) { |
- scoped_refptr<ServiceWorkerVersion> previous_version = active_version_; |
- if (previous_version) |
- previous_version->RemovePotentialControllee(this); |
- if (active_version) |
- active_version->AddPotentialControllee(this); |
- active_version_ = active_version; |
- } |
-} |
- |
void ServiceWorkerProviderHost::SetControllerVersionAttribute( |
ServiceWorkerVersion* version) { |
if (version == controlling_version_.get()) |
@@ -144,23 +113,36 @@ bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { |
void ServiceWorkerProviderHost::AssociateRegistration( |
ServiceWorkerRegistration* registration) { |
DCHECK(CanAssociateRegistration(registration)); |
+ if (associated_registration_.get()) |
+ DecreaseProcessReference(associated_registration_); |
+ IncreaseProcessReference(registration); |
+ |
associated_registration_ = registration; |
registration->AddListener(this); |
- UpdatePotentialControllees(registration->installing_version(), |
- registration->waiting_version(), |
- registration->active_version()); |
+ installing_version_ = registration->installing_version(); |
+ waiting_version_ = registration->waiting_version(); |
+ active_version_ = registration->active_version(); |
SetControllerVersionAttribute(registration->active_version()); |
} |
void ServiceWorkerProviderHost::UnassociateRegistration() { |
if (!associated_registration_.get()) |
return; |
+ DecreaseProcessReference(associated_registration_); |
associated_registration_->RemoveListener(this); |
associated_registration_ = NULL; |
- UpdatePotentialControllees(NULL, NULL, NULL); |
+ installing_version_ = NULL; |
+ waiting_version_ = NULL; |
+ active_version_ = NULL; |
SetControllerVersionAttribute(NULL); |
} |
+void ServiceWorkerProviderHost::AssociatePendingRegistration( |
+ ServiceWorkerRegistration* registration) { |
+ pending_registrations_.push_back(registration); |
+ IncreaseProcessReference(registration); |
+} |
+ |
scoped_ptr<ServiceWorkerRequestHandler> |
ServiceWorkerProviderHost::CreateRequestHandler( |
ResourceType resource_type, |
@@ -226,6 +208,22 @@ ServiceWorkerObjectInfo ServiceWorkerProviderHost::CreateHandleAndPass( |
return info; |
} |
+void ServiceWorkerProviderHost::IncreaseProcessReference( |
+ ServiceWorkerRegistration* registration) { |
+ if (context_ && context_->process_manager()) { |
+ context_->process_manager()->AddProcessReferenceToPattern( |
+ registration->pattern(), process_id_); |
+ } |
+} |
+ |
+void ServiceWorkerProviderHost::DecreaseProcessReference( |
+ ServiceWorkerRegistration* registration) { |
+ if (context_ && context_->process_manager()) { |
+ context_->process_manager()->RemoveProcessReferenceFromPattern( |
+ registration->pattern(), process_id_); |
+ } |
+} |
+ |
bool ServiceWorkerProviderHost::IsContextAlive() { |
return context_ != NULL; |
} |