| Index: content/browser/service_worker/service_worker_registration.cc
|
| diff --git a/content/browser/service_worker/service_worker_registration.cc b/content/browser/service_worker/service_worker_registration.cc
|
| index a4fac5c65873a9c9afe96c3b0e8b6fa92fe493b0..0d84b6b0c6ebccd4b6b69689f726729a4a9360a2 100644
|
| --- a/content/browser/service_worker/service_worker_registration.cc
|
| +++ b/content/browser/service_worker/service_worker_registration.cc
|
| @@ -161,6 +161,20 @@ void ServiceWorkerRegistration::ActivateWaitingVersionWhenReady() {
|
| ActivateWaitingVersion();
|
| }
|
|
|
| +void ServiceWorkerRegistration::ClaimClients() {
|
| + DCHECK(context_);
|
| + DCHECK(active_version());
|
| + std::vector<ServiceWorkerRegistrationInfo> infos =
|
| + context_->GetAllLiveRegistrationInfo();
|
| + for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it =
|
| + context_->GetProviderHostIterator();
|
| + !it->IsAtEnd(); it->Advance()) {
|
| + ServiceWorkerProviderHost* host = it->GetProviderHost();
|
| + if (ShouldClaim(host, infos))
|
| + host->UseRegistration(this);
|
| + }
|
| +}
|
| +
|
| void ServiceWorkerRegistration::ClearWhenReady() {
|
| DCHECK(context_);
|
| if (is_uninstalling_)
|
| @@ -360,4 +374,31 @@ void ServiceWorkerRegistration::OnRestoreFinished(
|
| callback.Run(status);
|
| }
|
|
|
| +bool ServiceWorkerRegistration::ShouldClaim(
|
| + ServiceWorkerProviderHost* provider_host,
|
| + std::vector<ServiceWorkerRegistrationInfo>& registration_infos) {
|
| + if (!ServiceWorkerUtils::ScopeMatches(pattern_,
|
| + provider_host->document_url()))
|
| + return false;
|
| +
|
| + LongestScopeMatcher matcher(provider_host->document_url());
|
| + int64 match = kInvalidServiceWorkerRegistrationId;
|
| + for (std::vector<ServiceWorkerRegistrationInfo>::iterator it =
|
| + registration_infos.begin();
|
| + it != registration_infos.end(); ++it) {
|
| + ServiceWorkerRegistration* registration =
|
| + context_->GetLiveRegistration(it->registration_id);
|
| + if (!registration || registration->is_uninstalled())
|
| + continue;
|
| + if (matcher.MatchLongest(it->pattern))
|
| + match = it->registration_id;
|
| + }
|
| +
|
| + if (match != registration_id_)
|
| + return false;
|
| + if (provider_host->controlling_version() == active_version())
|
| + return false;
|
| + return true;
|
| +}
|
| +
|
| } // namespace content
|
|
|