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 8112f3dd4977e6d0eafe3a6a726db7488c0bc901..340b8cfa4cf330ad9c0400463c8d0766391ae9c6 100644 |
--- a/content/browser/service_worker/service_worker_provider_host.cc |
+++ b/content/browser/service_worker/service_worker_provider_host.cc |
@@ -49,18 +49,15 @@ void ServiceWorkerProviderHost::OnVersionAttributesChanged( |
ServiceWorkerRegistration* registration, |
ChangedVersionAttributesMask changed_mask, |
const ServiceWorkerRegistrationInfo& info) { |
- if (changed_mask.installing_changed()) |
- SetInstallingVersion(registration->installing_version()); |
- if (changed_mask.waiting_changed()) |
- SetWaitingVersion(registration->waiting_version()); |
- if (changed_mask.active_changed()) |
- SetActiveVersion(registration->active_version()); |
+ DCHECK_EQ(associated_registration_, registration); |
+ SetVersionAttributes(registration->installing_version(), |
+ registration->waiting_version(), |
+ registration->active_version()); |
} |
void ServiceWorkerProviderHost::OnRegistrationFailed( |
ServiceWorkerRegistration* registration) { |
- DCHECK(associated_registration_); |
- DCHECK_EQ(registration->id(), associated_registration_->id()); |
+ DCHECK_EQ(associated_registration_, registration); |
UnassociateRegistration(); |
} |
@@ -69,93 +66,75 @@ void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { |
document_url_ = url; |
} |
-void ServiceWorkerProviderHost::SetControllerVersion( |
- ServiceWorkerVersion* version) { |
- DCHECK(CanAssociateVersion(version)); |
- if (version == controlling_version_) |
- return; |
- scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_; |
- controlling_version_ = version; |
- if (version) |
- version->AddControllee(this); |
- if (previous_version) |
- previous_version->RemoveControllee(this); |
+void ServiceWorkerProviderHost::SetVersionAttributes( |
+ ServiceWorkerVersion* installing_version, |
+ ServiceWorkerVersion* waiting_version, |
+ ServiceWorkerVersion* active_version) { |
+ ChangedVersionAttributesMask mask; |
+ |
+ if (installing_version != installing_version_) { |
+ SetVersionAttributesInternal(installing_version, &installing_version_); |
+ mask.add(ChangedVersionAttributesMask::INSTALLING_VERSION); |
+ } |
+ if (waiting_version != waiting_version_) { |
+ SetVersionAttributesInternal(waiting_version, &waiting_version_); |
+ mask.add(ChangedVersionAttributesMask::WAITING_VERSION); |
+ } |
+ if (active_version != active_version_) { |
+ SetVersionAttributesInternal(active_version, &active_version_); |
+ mask.add(ChangedVersionAttributesMask::ACTIVE_VERSION); |
+ } |
if (!dispatcher_host_) |
return; // Could be NULL in some tests. |
- |
- dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
- kDocumentMainThreadId, provider_id(), CreateHandleAndPass(version))); |
-} |
- |
-void ServiceWorkerProviderHost::SetActiveVersion( |
- ServiceWorkerVersion* version) { |
- DCHECK(CanAssociateVersion(version)); |
- if (version == active_version_) |
+ if (!mask.changed()) |
return; |
- scoped_refptr<ServiceWorkerVersion> previous_version = active_version_; |
- active_version_ = version; |
- if (version) |
- version->AddPotentialControllee(this); |
- if (previous_version) |
- previous_version->RemovePotentialControllee(this); |
- if (!dispatcher_host_) |
- return; // Could be NULL in some tests. |
+ ServiceWorkerVersionAttributes attributes; |
+ if (mask.installing_changed()) |
+ attributes.installing = CreateHandleAndPass(installing_version); |
+ if (mask.waiting_changed()) |
+ attributes.waiting = CreateHandleAndPass(waiting_version); |
+ if (mask.active_changed()) |
+ attributes.active = CreateHandleAndPass(active_version); |
- dispatcher_host_->Send(new ServiceWorkerMsg_SetActiveServiceWorker( |
- kDocumentMainThreadId, provider_id(), CreateHandleAndPass(version))); |
+ dispatcher_host_->Send(new ServiceWorkerMsg_SetVersionAttributes( |
+ kDocumentMainThreadId, provider_id(), mask.changed(), attributes)); |
} |
-void ServiceWorkerProviderHost::SetWaitingVersion( |
- ServiceWorkerVersion* version) { |
- DCHECK(CanAssociateVersion(version)); |
- if (version == waiting_version_) |
- return; |
- scoped_refptr<ServiceWorkerVersion> previous_version = waiting_version_; |
- waiting_version_ = version; |
+void ServiceWorkerProviderHost::SetVersionAttributesInternal( |
+ ServiceWorkerVersion* version, |
+ scoped_refptr<ServiceWorkerVersion>* data_member) { |
+ scoped_refptr<ServiceWorkerVersion> previous_version = *data_member; |
+ *data_member = version; |
if (version) |
version->AddPotentialControllee(this); |
if (previous_version) |
previous_version->RemovePotentialControllee(this); |
- |
- if (!dispatcher_host_) |
- return; // Could be NULL in some tests. |
- |
- dispatcher_host_->Send(new ServiceWorkerMsg_SetWaitingServiceWorker( |
- kDocumentMainThreadId, provider_id(), CreateHandleAndPass(version))); |
} |
-void ServiceWorkerProviderHost::SetInstallingVersion( |
+void ServiceWorkerProviderHost::SetControllerVersionAttribute( |
ServiceWorkerVersion* version) { |
- DCHECK(CanAssociateVersion(version)); |
- if (version == installing_version_) |
+ if (version == controlling_version_) |
return; |
- scoped_refptr<ServiceWorkerVersion> previous_version = installing_version_; |
- installing_version_ = version; |
+ |
+ scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_; |
+ controlling_version_ = version; |
if (version) |
- version->AddPotentialControllee(this); |
+ version->AddControllee(this); |
if (previous_version) |
- previous_version->RemovePotentialControllee(this); |
+ previous_version->RemoveControllee(this); |
if (!dispatcher_host_) |
return; // Could be NULL in some tests. |
- dispatcher_host_->Send(new ServiceWorkerMsg_SetInstallingServiceWorker( |
+ dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
kDocumentMainThreadId, provider_id(), CreateHandleAndPass(version))); |
} |
-void ServiceWorkerProviderHost::UnsetVersion(ServiceWorkerVersion* version) { |
- if (!version) |
- return; |
- if (installing_version_ == version) |
- SetInstallingVersion(NULL); |
- else if (waiting_version_ == version) |
- SetWaitingVersion(NULL); |
- else if (active_version_ == version) |
- SetActiveVersion(NULL); |
- else if (controlling_version_ == version) |
- SetControllerVersion(NULL); |
+void ServiceWorkerProviderHost::ClearVersionAttributes() { |
+ SetVersionAttributes(NULL, NULL, NULL); |
+ SetControllerVersionAttribute(NULL); |
} |
bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { |
@@ -185,10 +164,10 @@ void ServiceWorkerProviderHost::AssociateRegistration( |
DCHECK(CanAssociateRegistration(registration)); |
associated_registration_ = registration; |
registration->AddListener(this); |
- |
- SetActiveVersion(registration->active_version()); |
- SetInstallingVersion(registration->installing_version()); |
- SetWaitingVersion(registration->waiting_version()); |
+ SetVersionAttributes(registration->installing_version(), |
+ registration->waiting_version(), |
+ registration->active_version()); |
+ SetControllerVersionAttribute(registration->active_version()); |
} |
void ServiceWorkerProviderHost::UnassociateRegistration() { |
@@ -196,11 +175,7 @@ void ServiceWorkerProviderHost::UnassociateRegistration() { |
return; |
associated_registration_->RemoveListener(this); |
associated_registration_ = NULL; |
- |
- SetActiveVersion(NULL); |
- SetInstallingVersion(NULL); |
- SetWaitingVersion(NULL); |
- SetControllerVersion(NULL); |
+ ClearVersionAttributes(); |
} |
scoped_ptr<ServiceWorkerRequestHandler> |
@@ -221,30 +196,6 @@ ServiceWorkerProviderHost::CreateRequestHandler( |
return scoped_ptr<ServiceWorkerRequestHandler>(); |
} |
-bool ServiceWorkerProviderHost::CanAssociateVersion( |
- ServiceWorkerVersion* version) { |
- if (!context_) |
- return false; |
- if (running_hosted_version_) |
- return false; |
- if (!version) |
- return true; |
- |
- ServiceWorkerVersion* already_associated_version = NULL; |
- if (controlling_version_) |
- already_associated_version = controlling_version_; |
- if (active_version_) |
- already_associated_version = active_version_; |
- else if (waiting_version_) |
- already_associated_version = waiting_version_; |
- else if (installing_version_) |
- already_associated_version = installing_version_; |
- |
- return !already_associated_version || |
- already_associated_version->registration_id() == |
- version->registration_id(); |
-} |
- |
bool ServiceWorkerProviderHost::CanAssociateRegistration( |
ServiceWorkerRegistration* registration) { |
if (!context_) |