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..2640e5eeeaf4b0694a37fab95d69a33e35b4ed33 100644 |
--- a/content/browser/service_worker/service_worker_registration.cc |
+++ b/content/browser/service_worker/service_worker_registration.cc |
@@ -161,6 +161,16 @@ void ServiceWorkerRegistration::ActivateWaitingVersionWhenReady() { |
ActivateWaitingVersion(); |
} |
+void ServiceWorkerRegistration::ClaimClients(const StatusCallback& callback) { |
+ DCHECK(context_); |
+ DCHECK(active_version()); |
+ // TODO(xiang): Should better not hit the database http://crbug.com/454250. |
+ context_->storage()->GetRegistrationsForOrigin( |
+ pattern_.GetOrigin(), |
+ base::Bind(&ServiceWorkerRegistration::DidGetRegistrationsForClaimClients, |
+ this, callback, active_version_)); |
+} |
+ |
void ServiceWorkerRegistration::ClearWhenReady() { |
DCHECK(context_); |
if (is_uninstalling_) |
@@ -360,4 +370,48 @@ void ServiceWorkerRegistration::OnRestoreFinished( |
callback.Run(status); |
} |
+void ServiceWorkerRegistration::DidGetRegistrationsForClaimClients( |
+ const StatusCallback& callback, |
+ scoped_refptr<ServiceWorkerVersion> version, |
+ const std::vector<ServiceWorkerRegistrationInfo>& registrations) { |
+ if (!context_) { |
+ callback.Run(SERVICE_WORKER_ERROR_ABORT); |
+ return; |
+ } |
+ if (!active_version() || version != active_version()) { |
+ callback.Run(SERVICE_WORKER_ERROR_STATE); |
+ return; |
+ } |
+ |
+ for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = |
+ context_->GetProviderHostIterator(); |
+ !it->IsAtEnd(); it->Advance()) { |
+ ServiceWorkerProviderHost* host = it->GetProviderHost(); |
+ if (ShouldClaim(host, registrations)) |
+ host->ClaimedByRegistration(this); |
+ } |
+ callback.Run(SERVICE_WORKER_OK); |
+} |
+ |
+bool ServiceWorkerRegistration::ShouldClaim( |
+ ServiceWorkerProviderHost* provider_host, |
+ const std::vector<ServiceWorkerRegistrationInfo>& registrations) { |
+ if (provider_host->controlling_version() == active_version()) |
+ return false; |
+ |
+ LongestScopeMatcher matcher(provider_host->document_url()); |
+ if (!matcher.MatchLongest(pattern_)) |
+ return false; |
+ for (const ServiceWorkerRegistrationInfo& info : registrations) { |
+ ServiceWorkerRegistration* registration = |
+ context_->GetLiveRegistration(info.registration_id); |
+ if (registration && |
+ (registration->is_uninstalling() || registration->is_uninstalled())) |
+ continue; |
+ if (matcher.MatchLongest(info.pattern)) |
+ return false; |
+ } |
+ return true; |
+} |
+ |
} // namespace content |