Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(851)

Unified Diff: content/browser/service_worker/service_worker_registration.cc

Issue 871853002: ServiceWorker: add ServiceWorkerClients.claim() support (2/3). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove should_notify_controllerchange flag Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698