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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_storage_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/service_worker/service_worker_storage.h" 5 #include "content/browser/service_worker/service_worker_storage.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 NOTREACHED(); 677 NOTREACHED();
678 // TODO(michaeln): Hmmm, what if DeleteReg was invoked after 678 // TODO(michaeln): Hmmm, what if DeleteReg was invoked after
679 // the Find result we're returning here? NOTREACHED condition? 679 // the Find result we're returning here? NOTREACHED condition?
680 return registration; 680 return registration;
681 } 681 }
682 682
683 ServiceWorkerRegistration* 683 ServiceWorkerRegistration*
684 ServiceWorkerStorage::FindInstallingRegistrationForDocument( 684 ServiceWorkerStorage::FindInstallingRegistrationForDocument(
685 const GURL& document_url) { 685 const GURL& document_url) {
686 DCHECK(!document_url.has_ref()); 686 DCHECK(!document_url.has_ref());
687 // TODO(michaeln): if there are multiple matches the one with 687
688 // the longest scope should win. 688 LongestScopeMatcher matcher(document_url);
689 ServiceWorkerRegistration* match = NULL;
690
691 // TODO(nhiroki): This searches over installing registrations linearly and it
692 // couldn't be scalable. Maybe the regs should be partitioned by origin.
689 for (RegistrationRefsById::const_iterator it = 693 for (RegistrationRefsById::const_iterator it =
690 installing_registrations_.begin(); 694 installing_registrations_.begin();
691 it != installing_registrations_.end(); ++it) { 695 it != installing_registrations_.end(); ++it) {
692 if (ServiceWorkerUtils::ScopeMatches( 696 if (matcher.MatchLongest(it->second->pattern()))
693 it->second->pattern(), document_url)) { 697 match = it->second;
694 return it->second;
695 }
696 } 698 }
697 return NULL; 699 return match;
698 } 700 }
699 701
700 ServiceWorkerRegistration* 702 ServiceWorkerRegistration*
701 ServiceWorkerStorage::FindInstallingRegistrationForPattern( 703 ServiceWorkerStorage::FindInstallingRegistrationForPattern(
702 const GURL& scope) { 704 const GURL& scope) {
703 for (RegistrationRefsById::const_iterator it = 705 for (RegistrationRefsById::const_iterator it =
704 installing_registrations_.begin(); 706 installing_registrations_.begin();
705 it != installing_registrations_.end(); ++it) { 707 it != installing_registrations_.end(); ++it) {
706 if (it->second->pattern() == scope) 708 if (it->second->pattern() == scope)
707 return it->second; 709 return it->second;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 if (status != ServiceWorkerDatabase::STATUS_OK) { 893 if (status != ServiceWorkerDatabase::STATUS_OK) {
892 original_task_runner->PostTask( 894 original_task_runner->PostTask(
893 FROM_HERE, 895 FROM_HERE,
894 base::Bind(callback, 896 base::Bind(callback,
895 ServiceWorkerDatabase::RegistrationData(), 897 ServiceWorkerDatabase::RegistrationData(),
896 ResourceList(), 898 ResourceList(),
897 status)); 899 status));
898 return; 900 return;
899 } 901 }
900 902
901 // Find one with a pattern match.
902 // TODO(michaeln): if there are multiple matches the one with
903 // the longest scope should win.
904 ServiceWorkerDatabase::RegistrationData data; 903 ServiceWorkerDatabase::RegistrationData data;
905 ResourceList resources; 904 ResourceList resources;
906 status = ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND; 905 status = ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND;
907 for (RegistrationList::const_iterator it = registrations.begin(); 906
908 it != registrations.end(); ++it) { 907 // Find one with a pattern match.
909 if (!ServiceWorkerUtils::ScopeMatches(it->scope, document_url)) 908 LongestScopeMatcher matcher(document_url);
910 continue; 909 int64 match = kInvalidServiceWorkerRegistrationId;
911 status = database->ReadRegistration(it->registration_id, origin, 910 for (size_t i = 0; i < registrations.size(); ++i) {
912 &data, &resources); 911 if (matcher.MatchLongest(registrations[i].scope))
913 break; // We're done looping. 912 match = registrations[i].registration_id;
914 } 913 }
915 914
915 if (match != kInvalidServiceWorkerRegistrationId)
916 status = database->ReadRegistration(match, origin, &data, &resources);
917
916 original_task_runner->PostTask( 918 original_task_runner->PostTask(
917 FROM_HERE, 919 FROM_HERE,
918 base::Bind(callback, data, resources, status)); 920 base::Bind(callback, data, resources, status));
919 } 921 }
920 922
921 void ServiceWorkerStorage::FindForPatternInDB( 923 void ServiceWorkerStorage::FindForPatternInDB(
922 ServiceWorkerDatabase* database, 924 ServiceWorkerDatabase* database,
923 scoped_refptr<base::SequencedTaskRunner> original_task_runner, 925 scoped_refptr<base::SequencedTaskRunner> original_task_runner,
924 const GURL& scope, 926 const GURL& scope,
925 const FindInDBCallback& callback) { 927 const FindInDBCallback& callback) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 const FindInDBCallback& callback) { 965 const FindInDBCallback& callback) {
964 ServiceWorkerDatabase::RegistrationData data; 966 ServiceWorkerDatabase::RegistrationData data;
965 ResourceList resources; 967 ResourceList resources;
966 ServiceWorkerDatabase::Status status = 968 ServiceWorkerDatabase::Status status =
967 database->ReadRegistration(registration_id, origin, &data, &resources); 969 database->ReadRegistration(registration_id, origin, &data, &resources);
968 original_task_runner->PostTask( 970 original_task_runner->PostTask(
969 FROM_HERE, base::Bind(callback, data, resources, status)); 971 FROM_HERE, base::Bind(callback, data, resources, status));
970 } 972 }
971 973
972 } // namespace content 974 } // namespace content
OLDNEW
« 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