| 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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "content/browser/service_worker/service_worker_registration.h" | 10 #include "content/browser/service_worker/service_worker_registration.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 const GURL& pattern, | 47 const GURL& pattern, |
| 48 const FindRegistrationCallback& callback) { | 48 const FindRegistrationCallback& callback) { |
| 49 PatternToRegistrationMap::const_iterator match = | 49 PatternToRegistrationMap::const_iterator match = |
| 50 registration_by_pattern_.find(pattern); | 50 registration_by_pattern_.find(pattern); |
| 51 if (match == registration_by_pattern_.end()) { | 51 if (match == registration_by_pattern_.end()) { |
| 52 BrowserThread::PostTask( | 52 BrowserThread::PostTask( |
| 53 BrowserThread::IO, | 53 BrowserThread::IO, |
| 54 FROM_HERE, | 54 FROM_HERE, |
| 55 base::Bind(callback, | 55 base::Bind(callback, |
| 56 false /* found */, | 56 false /* found */, |
| 57 REGISTRATION_OK, | 57 SERVICE_WORKER_OK, |
| 58 scoped_refptr<ServiceWorkerRegistration>())); | 58 scoped_refptr<ServiceWorkerRegistration>())); |
| 59 return; | 59 return; |
| 60 } | 60 } |
| 61 BrowserThread::PostTask( | 61 BrowserThread::PostTask( |
| 62 BrowserThread::IO, | 62 BrowserThread::IO, |
| 63 FROM_HERE, | 63 FROM_HERE, |
| 64 base::Bind(callback, true /* found */, REGISTRATION_OK, match->second)); | 64 base::Bind(callback, true /* found */, SERVICE_WORKER_OK, match->second)); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void ServiceWorkerStorage::FindRegistrationForDocument( | 67 void ServiceWorkerStorage::FindRegistrationForDocument( |
| 68 const GURL& document_url, | 68 const GURL& document_url, |
| 69 const FindRegistrationCallback& callback) { | 69 const FindRegistrationCallback& callback) { |
| 70 // TODO(alecflett): This needs to be synchronous in the fast path, | 70 // TODO(alecflett): This needs to be synchronous in the fast path, |
| 71 // but asynchronous in the slow path (when the patterns have to be | 71 // but asynchronous in the slow path (when the patterns have to be |
| 72 // loaded from disk). For now it is always pessimistically async. | 72 // loaded from disk). For now it is always pessimistically async. |
| 73 for (PatternToRegistrationMap::const_iterator it = | 73 for (PatternToRegistrationMap::const_iterator it = |
| 74 registration_by_pattern_.begin(); | 74 registration_by_pattern_.begin(); |
| 75 it != registration_by_pattern_.end(); | 75 it != registration_by_pattern_.end(); |
| 76 ++it) { | 76 ++it) { |
| 77 if (PatternMatches(it->first, document_url)) { | 77 if (PatternMatches(it->first, document_url)) { |
| 78 BrowserThread::PostTask( | 78 BrowserThread::PostTask( |
| 79 BrowserThread::IO, | 79 BrowserThread::IO, |
| 80 FROM_HERE, | 80 FROM_HERE, |
| 81 base::Bind(callback, | 81 base::Bind(callback, |
| 82 true /* found */, | 82 true /* found */, |
| 83 REGISTRATION_OK, | 83 SERVICE_WORKER_OK, |
| 84 scoped_refptr<ServiceWorkerRegistration>(it->second))); | 84 scoped_refptr<ServiceWorkerRegistration>(it->second))); |
| 85 return; | 85 return; |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 BrowserThread::PostTask( | 88 BrowserThread::PostTask( |
| 89 BrowserThread::IO, | 89 BrowserThread::IO, |
| 90 FROM_HERE, | 90 FROM_HERE, |
| 91 base::Bind(callback, | 91 base::Bind(callback, |
| 92 false /* found */, | 92 false /* found */, |
| 93 REGISTRATION_OK, | 93 SERVICE_WORKER_OK, |
| 94 scoped_refptr<ServiceWorkerRegistration>())); | 94 scoped_refptr<ServiceWorkerRegistration>())); |
| 95 } | 95 } |
| 96 | 96 |
| 97 scoped_refptr<ServiceWorkerRegistration> ServiceWorkerStorage::RegisterInternal( | 97 scoped_refptr<ServiceWorkerRegistration> ServiceWorkerStorage::RegisterInternal( |
| 98 const GURL& pattern, | 98 const GURL& pattern, |
| 99 const GURL& script_url) { | 99 const GURL& script_url) { |
| 100 | 100 |
| 101 PatternToRegistrationMap::const_iterator current( | 101 PatternToRegistrationMap::const_iterator current( |
| 102 registration_by_pattern_.find(pattern)); | 102 registration_by_pattern_.find(pattern)); |
| 103 DCHECK(current == registration_by_pattern_.end() || | 103 DCHECK(current == registration_by_pattern_.end() || |
| (...skipping 27 matching lines...) Expand all Loading... |
| 131 // Temporarily borrowed directly from appcache::Namespace::IsMatch(). | 131 // Temporarily borrowed directly from appcache::Namespace::IsMatch(). |
| 132 // We have to escape '?' characters since MatchPattern also treats those | 132 // We have to escape '?' characters since MatchPattern also treats those |
| 133 // as wildcards which we don't want here, we only do '*'s. | 133 // as wildcards which we don't want here, we only do '*'s. |
| 134 std::string pattern_spec(pattern.spec()); | 134 std::string pattern_spec(pattern.spec()); |
| 135 if (pattern.has_query()) | 135 if (pattern.has_query()) |
| 136 ReplaceSubstringsAfterOffset(&pattern_spec, 0, "?", "\\?"); | 136 ReplaceSubstringsAfterOffset(&pattern_spec, 0, "?", "\\?"); |
| 137 return MatchPattern(url.spec(), pattern_spec); | 137 return MatchPattern(url.spec(), pattern_spec); |
| 138 } | 138 } |
| 139 | 139 |
| 140 } // namespace content | 140 } // namespace content |
| OLD | NEW |