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..fd498900243a77be3bbf629534ab22dc2193cefc 100644 |
--- a/content/browser/service_worker/service_worker_registration.cc |
+++ b/content/browser/service_worker/service_worker_registration.cc |
@@ -161,6 +161,17 @@ void ServiceWorkerRegistration::ActivateWaitingVersionWhenReady() { |
ActivateWaitingVersion(); |
} |
+void ServiceWorkerRegistration::ClaimClients(const StatusCallback& callback) { |
+ DCHECK(context_); |
+ DCHECK(active_version()); |
+ // Check all stored and initially installing registrations of this origin is |
+ // enough for claiming documents. |
falken
2015/01/30 10:24:02
I'd change this comment to a TODO to not have to h
xiang
2015/02/02 04:24:58
Done.
|
+ context_->storage()->GetRegistrationsForOrigin( |
+ pattern_.GetOrigin(), |
+ base::Bind(&ServiceWorkerRegistration::DidGetRegistrationsForClaimClients, |
+ this, callback, active_version_)); |
+} |
+ |
void ServiceWorkerRegistration::ClearWhenReady() { |
DCHECK(context_); |
if (is_uninstalling_) |
@@ -360,4 +371,47 @@ 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_uninstalled()) |
xiang
2015/01/30 07:18:57
Only live registrations maybe uninstalled during G
|
+ continue; |
+ if (matcher.MatchLongest(info.pattern)) |
michaeln
2015/01/30 23:43:07
given a docurl and a matchingscope, this function
xiang
2015/02/02 04:24:58
Done.
|
+ return false; |
+ } |
+ return true; |
+} |
+ |
} // namespace content |