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

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

Issue 1013423002: ServiceWorker: Make claim() uses living matching registrations instead of fetching from DB. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for #3 Created 5 years, 9 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 f436f95c38f488003d691e93a13abbf5043b2915..e041093200b6f16a1750e1dfaf2aa876db0ac5b6 100644
--- a/content/browser/service_worker/service_worker_registration.cc
+++ b/content/browser/service_worker/service_worker_registration.cc
@@ -162,14 +162,21 @@ void ServiceWorkerRegistration::ActivateWaitingVersionWhenReady() {
ActivateWaitingVersion();
}
-void ServiceWorkerRegistration::ClaimClients(const StatusCallback& callback) {
+void ServiceWorkerRegistration::ClaimClients() {
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_));
+
+ for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it =
+ context_->GetProviderHostIterator();
+ !it->IsAtEnd(); it->Advance()) {
+ ServiceWorkerProviderHost* host = it->GetProviderHost();
+ if (host->IsHostToRunningServiceWorker())
+ continue;
+ if (host->controlling_version() == active_version())
+ continue;
+ if (host->MatchRegistration() == this)
+ host->ClaimedByRegistration(this);
+ }
}
void ServiceWorkerRegistration::ClearWhenReady() {
@@ -375,50 +382,4 @@ 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->IsHostToRunningServiceWorker())
- return false;
- 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
« no previous file with comments | « content/browser/service_worker/service_worker_registration.h ('k') | content/browser/service_worker/service_worker_version.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698