Chromium Code Reviews| 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 85ea2cae79391c90355ff0bb6b2fe5dfe5b4680a..ce83eff33324815c0941a16c74fea895560fd3fd 100644 |
| --- a/content/browser/service_worker/service_worker_provider_host.cc |
| +++ b/content/browser/service_worker/service_worker_provider_host.cc |
| @@ -41,6 +41,28 @@ ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { |
| waiting_version_->RemovePotentialControllee(this); |
| if (installing_version_) |
| installing_version_->RemovePotentialControllee(this); |
| + if (associated_registration_) |
| + associated_registration_->RemoveListener(this); |
| +} |
| + |
| +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()); |
| +} |
| + |
| +void ServiceWorkerProviderHost::OnRegistrationDeleted( |
| + ServiceWorkerRegistration* registration) { |
| + DCHECK(associated_registration_); |
| + DCHECK_EQ(registration->id(), associated_registration_->id()); |
| + associated_registration_->RemoveListener(this); |
| + associated_registration_ = NULL; |
| } |
| void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { |
| @@ -159,6 +181,26 @@ bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { |
| return true; |
| } |
| +void ServiceWorkerProviderHost::SetRegistration( |
| + ServiceWorkerRegistration* registration) { |
| + DCHECK(CanAssociateRegistration(registration)); |
| + if (associated_registration_) |
| + associated_registration_->RemoveListener(this); |
| + associated_registration_ = registration; |
| + |
| + if (!registration) { |
| + SetActiveVersion(NULL); |
| + SetInstallingVersion(NULL); |
| + SetWaitingVersion(NULL); |
| + return; |
| + } |
| + |
| + registration->AddListener(this); |
| + SetActiveVersion(registration->active_version()); |
| + SetInstallingVersion(registration->installing_version()); |
| + SetWaitingVersion(registration->waiting_version()); |
| +} |
| + |
| scoped_ptr<ServiceWorkerRequestHandler> |
| ServiceWorkerProviderHost::CreateRequestHandler( |
| ResourceType resource_type, |
| @@ -201,6 +243,17 @@ bool ServiceWorkerProviderHost::CanAssociateVersion( |
| version->registration_id(); |
| } |
| +bool ServiceWorkerProviderHost::CanAssociateRegistration( |
| + ServiceWorkerRegistration* registration) { |
| + if (!context_) |
| + return false; |
|
michaeln
2014/08/07 01:34:35
also if (running_hosted_version_) return false;
nhiroki
2014/08/07 02:57:27
Done.
|
| + if (!registration) |
|
michaeln
2014/08/07 01:34:35
seems like NULL should not be valid inputs to this
nhiroki
2014/08/07 02:57:27
Done.
|
| + return true; |
| + if (associated_registration_) |
| + return false; |
| + return true; |
| +} |
| + |
| void ServiceWorkerProviderHost::PostMessage( |
| const base::string16& message, |
| const std::vector<int>& sent_message_port_ids) { |