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

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: change error type 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..4301c85151ad223b8d17e43bfdad8ea3329b54ab 100644
--- a/content/browser/service_worker/service_worker_registration.cc
+++ b/content/browser/service_worker/service_worker_registration.cc
@@ -161,6 +161,40 @@ void ServiceWorkerRegistration::ActivateWaitingVersionWhenReady() {
ActivateWaitingVersion();
}
+void ServiceWorkerRegistration::ClaimClients() {
+ DCHECK(context_);
+ DCHECK(active_version());
+ std::vector<ServiceWorkerRegistrationInfo> registration_infos =
+ context_->GetAllLiveRegistrationInfo();
+ for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it =
+ context_->GetProviderHostIterator();
+ !it->IsAtEnd(); it->Advance()) {
+ ServiceWorkerProviderHost* host = it->GetProviderHost();
+ if (host->document_url().GetOrigin() != pattern_.GetOrigin())
+ continue;
+
+ LongestScopeMatcher matcher(host->document_url());
+ int64 match = kInvalidServiceWorkerRegistrationId;
+ for (std::vector<ServiceWorkerRegistrationInfo>::iterator it =
michaeln 2015/01/28 00:55:13 This inner loop is not so nice. I think we can avo
xiang 2015/01/28 05:38:35 Yes, move out the inner loop is more cleaner. How
falken 2015/01/28 08:59:49 I think you're right, "/foob" shouldn't claim the
michaeln 2015/01/28 21:11:14 Thats too bad because it adds code complexity and
xiang 2015/01/29 02:58:37 I thought about FindRegistrationForDocument() when
falken 2015/01/29 03:28:50 I suspected this might be the case too. Michael, w
+ registration_infos.begin();
+ it != registration_infos.end(); ++it) {
+ ServiceWorkerRegistration* registration =
+ context_->GetLiveRegistration(it->registration_id);
+ DCHECK(registration);
+ if (registration->is_uninstalled())
+ continue;
+ if (matcher.MatchLongest(it->pattern))
+ match = it->registration_id;
+ }
+ if (match != registration_id_)
+ continue;
+ if (host->controlling_version() == active_version())
+ continue;
+
+ host->SetController(this);
+ }
+}
+
void ServiceWorkerRegistration::ClearWhenReady() {
DCHECK(context_);
if (is_uninstalling_)

Powered by Google App Engine
This is Rietveld 408576698