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

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

Issue 294593002: ServiceWorker: Support longest-prefix-match for registration scope (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 6 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
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_storage_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/service_worker/service_worker_storage.cc
diff --git a/content/browser/service_worker/service_worker_storage.cc b/content/browser/service_worker/service_worker_storage.cc
index 10c1462045f6a15dd03b95ce3b7388e329e193c2..1e096f4dcbfcd9612d2ec3d1ff14b78128d6ca1a 100644
--- a/content/browser/service_worker/service_worker_storage.cc
+++ b/content/browser/service_worker/service_worker_storage.cc
@@ -684,17 +684,19 @@ ServiceWorkerRegistration*
ServiceWorkerStorage::FindInstallingRegistrationForDocument(
const GURL& document_url) {
DCHECK(!document_url.has_ref());
- // TODO(michaeln): if there are multiple matches the one with
- // the longest scope should win.
+
+ LongestScopeMatcher matcher(document_url);
+ ServiceWorkerRegistration* match = NULL;
+
+ // TODO(nhiroki): This searches over installing registrations linearly and it
+ // couldn't be scalable. Maybe the regs should be partitioned by origin.
for (RegistrationRefsById::const_iterator it =
installing_registrations_.begin();
it != installing_registrations_.end(); ++it) {
- if (ServiceWorkerUtils::ScopeMatches(
- it->second->pattern(), document_url)) {
- return it->second;
- }
+ if (matcher.MatchLongest(it->second->pattern()))
+ match = it->second;
}
- return NULL;
+ return match;
}
ServiceWorkerRegistration*
@@ -898,21 +900,21 @@ void ServiceWorkerStorage::FindForDocumentInDB(
return;
}
- // Find one with a pattern match.
- // TODO(michaeln): if there are multiple matches the one with
- // the longest scope should win.
ServiceWorkerDatabase::RegistrationData data;
ResourceList resources;
status = ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND;
- for (RegistrationList::const_iterator it = registrations.begin();
- it != registrations.end(); ++it) {
- if (!ServiceWorkerUtils::ScopeMatches(it->scope, document_url))
- continue;
- status = database->ReadRegistration(it->registration_id, origin,
- &data, &resources);
- break; // We're done looping.
+
+ // Find one with a pattern match.
+ LongestScopeMatcher matcher(document_url);
+ int64 match = kInvalidServiceWorkerRegistrationId;
+ for (size_t i = 0; i < registrations.size(); ++i) {
+ if (matcher.MatchLongest(registrations[i].scope))
+ match = registrations[i].registration_id;
}
+ if (match != kInvalidServiceWorkerRegistrationId)
+ status = database->ReadRegistration(match, origin, &data, &resources);
+
original_task_runner->PostTask(
FROM_HERE,
base::Bind(callback, data, resources, status));
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_storage_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698