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

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

Issue 304423004: ServiceWorker: Scope should match url in longest-prefix-match way (won't commit) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compile error Created 6 years, 7 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 62d198bd5aa6e6678b0a66b786222d9d77415c29..6b9d62fab5c3c6fd1e2c61e18f5594a4d15c7ad2 100644
--- a/content/browser/service_worker/service_worker_storage.cc
+++ b/content/browser/service_worker/service_worker_storage.cc
@@ -672,17 +672,20 @@ ServiceWorkerStorage::GetOrCreateRegistration(
ServiceWorkerRegistration*
ServiceWorkerStorage::FindInstallingRegistrationForDocument(
const GURL& document_url) {
- // TODO(michaeln): if there are multiple matches the one with
- // the longest scope should win.
+ std::vector<GURL> scopes;
+ scopes.reserve(installing_registrations_.size());
for (RegistrationRefsById::const_iterator it =
installing_registrations_.begin();
it != installing_registrations_.end(); ++it) {
- if (ServiceWorkerUtils::ScopeMatches(
- it->second->pattern(), document_url)) {
- return it->second;
- }
+ scopes.push_back(it->second->pattern());
}
- return NULL;
+
+ size_t pos = 0;
+ if (!ServiceWorkerUtils::FindLongestScopeMatch(scopes, document_url, &pos))
+ return NULL;
+ RegistrationRefsById::const_iterator it = installing_registrations_.begin();
+ std::advance(it, pos);
+ return it->second;
}
ServiceWorkerRegistration*
@@ -887,18 +890,18 @@ void ServiceWorkerStorage::FindForDocumentInDB(
}
// 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.
+
+ std::vector<GURL> scopes;
+ scopes.reserve(registrations.size());
+ for (size_t i = 0; i < registrations.size(); ++i)
+ scopes.push_back(registrations[i].scope);
+ size_t pos = 0;
+ if (ServiceWorkerUtils::FindLongestScopeMatch(scopes, document_url, &pos)) {
+ status = database->ReadRegistration(registrations[pos].registration_id,
+ origin, &data, &resources);
}
original_task_runner->PostTask(
« 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