| OLD | NEW | 
|---|
| 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 654 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 665   else | 665   else | 
| 666     NOTREACHED(); | 666     NOTREACHED(); | 
| 667   // TODO(michaeln): Hmmm, what if DeleteReg was invoked after | 667   // TODO(michaeln): Hmmm, what if DeleteReg was invoked after | 
| 668   // the Find result we're returning here? NOTREACHED condition? | 668   // the Find result we're returning here? NOTREACHED condition? | 
| 669   return registration; | 669   return registration; | 
| 670 } | 670 } | 
| 671 | 671 | 
| 672 ServiceWorkerRegistration* | 672 ServiceWorkerRegistration* | 
| 673 ServiceWorkerStorage::FindInstallingRegistrationForDocument( | 673 ServiceWorkerStorage::FindInstallingRegistrationForDocument( | 
| 674     const GURL& document_url) { | 674     const GURL& document_url) { | 
| 675   // TODO(michaeln): if there are multiple matches the one with | 675   std::vector<GURL> scopes; | 
| 676   // the longest scope should win. | 676   scopes.reserve(installing_registrations_.size()); | 
| 677   for (RegistrationRefsById::const_iterator it = | 677   for (RegistrationRefsById::const_iterator it = | 
| 678            installing_registrations_.begin(); | 678            installing_registrations_.begin(); | 
| 679        it != installing_registrations_.end(); ++it) { | 679        it != installing_registrations_.end(); ++it) { | 
| 680     if (ServiceWorkerUtils::ScopeMatches( | 680     scopes.push_back(it->second->pattern()); | 
| 681             it->second->pattern(), document_url)) { |  | 
| 682       return it->second; |  | 
| 683     } |  | 
| 684   } | 681   } | 
| 685   return NULL; | 682 | 
|  | 683   size_t pos = 0; | 
|  | 684   if (!ServiceWorkerUtils::FindLongestScopeMatch(scopes, document_url, &pos)) | 
|  | 685     return NULL; | 
|  | 686   RegistrationRefsById::const_iterator it = installing_registrations_.begin(); | 
|  | 687   std::advance(it, pos); | 
|  | 688   return it->second; | 
| 686 } | 689 } | 
| 687 | 690 | 
| 688 ServiceWorkerRegistration* | 691 ServiceWorkerRegistration* | 
| 689 ServiceWorkerStorage::FindInstallingRegistrationForPattern( | 692 ServiceWorkerStorage::FindInstallingRegistrationForPattern( | 
| 690     const GURL& scope) { | 693     const GURL& scope) { | 
| 691   for (RegistrationRefsById::const_iterator it = | 694   for (RegistrationRefsById::const_iterator it = | 
| 692            installing_registrations_.begin(); | 695            installing_registrations_.begin(); | 
| 693        it != installing_registrations_.end(); ++it) { | 696        it != installing_registrations_.end(); ++it) { | 
| 694     if (it->second->pattern() == scope) | 697     if (it->second->pattern() == scope) | 
| 695       return it->second; | 698       return it->second; | 
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 880     original_task_runner->PostTask( | 883     original_task_runner->PostTask( | 
| 881         FROM_HERE, | 884         FROM_HERE, | 
| 882         base::Bind(callback, | 885         base::Bind(callback, | 
| 883                    ServiceWorkerDatabase::RegistrationData(), | 886                    ServiceWorkerDatabase::RegistrationData(), | 
| 884                    ResourceList(), | 887                    ResourceList(), | 
| 885                    status)); | 888                    status)); | 
| 886     return; | 889     return; | 
| 887   } | 890   } | 
| 888 | 891 | 
| 889   // Find one with a pattern match. | 892   // Find one with a pattern match. | 
| 890   // TODO(michaeln): if there are multiple matches the one with |  | 
| 891   // the longest scope should win. |  | 
| 892   ServiceWorkerDatabase::RegistrationData data; | 893   ServiceWorkerDatabase::RegistrationData data; | 
| 893   ResourceList resources; | 894   ResourceList resources; | 
| 894   status = ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND; | 895   status = ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND; | 
| 895   for (RegistrationList::const_iterator it = registrations.begin(); | 896 | 
| 896        it != registrations.end(); ++it) { | 897   std::vector<GURL> scopes; | 
| 897     if (!ServiceWorkerUtils::ScopeMatches(it->scope, document_url)) | 898   scopes.reserve(registrations.size()); | 
| 898       continue; | 899   for (size_t i = 0; i < registrations.size(); ++i) | 
| 899     status = database->ReadRegistration(it->registration_id, origin, | 900     scopes.push_back(registrations[i].scope); | 
| 900                                         &data, &resources); | 901   size_t pos = 0; | 
| 901     break;  // We're done looping. | 902   if (ServiceWorkerUtils::FindLongestScopeMatch(scopes, document_url, &pos)) { | 
|  | 903     status = database->ReadRegistration(registrations[pos].registration_id, | 
|  | 904                                         origin, &data, &resources); | 
| 902   } | 905   } | 
| 903 | 906 | 
| 904   original_task_runner->PostTask( | 907   original_task_runner->PostTask( | 
| 905       FROM_HERE, | 908       FROM_HERE, | 
| 906       base::Bind(callback, data, resources, status)); | 909       base::Bind(callback, data, resources, status)); | 
| 907 } | 910 } | 
| 908 | 911 | 
| 909 void ServiceWorkerStorage::FindForPatternInDB( | 912 void ServiceWorkerStorage::FindForPatternInDB( | 
| 910     ServiceWorkerDatabase* database, | 913     ServiceWorkerDatabase* database, | 
| 911     scoped_refptr<base::SequencedTaskRunner> original_task_runner, | 914     scoped_refptr<base::SequencedTaskRunner> original_task_runner, | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 951     const FindInDBCallback& callback) { | 954     const FindInDBCallback& callback) { | 
| 952   ServiceWorkerDatabase::RegistrationData data; | 955   ServiceWorkerDatabase::RegistrationData data; | 
| 953   ResourceList resources; | 956   ResourceList resources; | 
| 954   ServiceWorkerDatabase::Status status = | 957   ServiceWorkerDatabase::Status status = | 
| 955       database->ReadRegistration(registration_id, origin, &data, &resources); | 958       database->ReadRegistration(registration_id, origin, &data, &resources); | 
| 956   original_task_runner->PostTask( | 959   original_task_runner->PostTask( | 
| 957       FROM_HERE, base::Bind(callback, data, resources, status)); | 960       FROM_HERE, base::Bind(callback, data, resources, status)); | 
| 958 } | 961 } | 
| 959 | 962 | 
| 960 }  // namespace content | 963 }  // namespace content | 
| OLD | NEW | 
|---|