| 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 7ec25a4398400505e7dc6c94625ca568217d844b..d7ebc8f7f391e93480ba734deb1b31788465200f 100644
|
| --- a/content/browser/service_worker/service_worker_storage.cc
|
| +++ b/content/browser/service_worker/service_worker_storage.cc
|
| @@ -682,17 +682,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*
|
| @@ -896,21 +898,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));
|
|
|