| 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 | |
| 9 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "content/browser/service_worker/service_worker_info.h" |
| 11 #include "content/browser/service_worker/service_worker_registration.h" | 11 #include "content/browser/service_worker/service_worker_registration.h" |
| 12 #include "content/public/browser/browser_thread.h" |
| 12 #include "webkit/browser/quota/quota_manager_proxy.h" | 13 #include "webkit/browser/quota/quota_manager_proxy.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 void RunSoon(const base::Closure& closure) { | 19 void RunSoon(const base::Closure& closure) { |
| 19 base::MessageLoop::current()->PostTask(FROM_HERE, closure); | 20 base::MessageLoop::current()->PostTask(FROM_HERE, closure); |
| 20 } | 21 } |
| 21 | 22 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 if (PatternMatches(it->first, document_url)) { | 75 if (PatternMatches(it->first, document_url)) { |
| 75 status = SERVICE_WORKER_OK; | 76 status = SERVICE_WORKER_OK; |
| 76 found = it->second; | 77 found = it->second; |
| 77 break; | 78 break; |
| 78 } | 79 } |
| 79 } | 80 } |
| 80 // Always simulate asynchronous call for now. | 81 // Always simulate asynchronous call for now. |
| 81 RunSoon(base::Bind(callback, status, found)); | 82 RunSoon(base::Bind(callback, status, found)); |
| 82 } | 83 } |
| 83 | 84 |
| 85 void ServiceWorkerStorage::GetAllRegistrations( |
| 86 const GetAllRegistrationInfosCallback& callback) { |
| 87 std::vector<ServiceWorkerRegistrationInfo> registrations; |
| 88 for (PatternToRegistrationMap::const_iterator it = |
| 89 registration_by_pattern_.begin(); |
| 90 it != registration_by_pattern_.end(); |
| 91 ++it) { |
| 92 ServiceWorkerRegistration* registration(it->second.get()); |
| 93 registrations.push_back(registration->GetInfo()); |
| 94 } |
| 95 |
| 96 BrowserThread::PostTask( |
| 97 BrowserThread::IO, FROM_HERE, base::Bind(callback, registrations)); |
| 98 } |
| 99 |
| 84 void ServiceWorkerStorage::StoreRegistration( | 100 void ServiceWorkerStorage::StoreRegistration( |
| 85 ServiceWorkerRegistration* registration, | 101 ServiceWorkerRegistration* registration, |
| 86 const StatusCallback& callback) { | 102 const StatusCallback& callback) { |
| 87 DCHECK(registration); | 103 DCHECK(registration); |
| 88 | 104 |
| 89 PatternToRegistrationMap::const_iterator current( | 105 PatternToRegistrationMap::const_iterator current( |
| 90 registration_by_pattern_.find(registration->pattern())); | 106 registration_by_pattern_.find(registration->pattern())); |
| 91 if (current != registration_by_pattern_.end() && | 107 if (current != registration_by_pattern_.end() && |
| 92 current->second->script_url() != registration->script_url()) { | 108 current->second->script_url() != registration->script_url()) { |
| 93 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_EXISTS)); | 109 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_EXISTS)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // Temporarily borrowed directly from appcache::Namespace::IsMatch(). | 144 // Temporarily borrowed directly from appcache::Namespace::IsMatch(). |
| 129 // We have to escape '?' characters since MatchPattern also treats those | 145 // We have to escape '?' characters since MatchPattern also treats those |
| 130 // as wildcards which we don't want here, we only do '*'s. | 146 // as wildcards which we don't want here, we only do '*'s. |
| 131 std::string pattern_spec(pattern.spec()); | 147 std::string pattern_spec(pattern.spec()); |
| 132 if (pattern.has_query()) | 148 if (pattern.has_query()) |
| 133 ReplaceSubstringsAfterOffset(&pattern_spec, 0, "?", "\\?"); | 149 ReplaceSubstringsAfterOffset(&pattern_spec, 0, "?", "\\?"); |
| 134 return MatchPattern(url.spec(), pattern_spec); | 150 return MatchPattern(url.spec(), pattern_spec); |
| 135 } | 151 } |
| 136 | 152 |
| 137 } // namespace content | 153 } // namespace content |
| OLD | NEW |