| 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/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "content/browser/service_worker/service_worker_registration.h" | 11 #include "content/browser/service_worker/service_worker_registration.h" |
| 12 #include "webkit/browser/quota/quota_manager_proxy.h" | 12 #include "webkit/browser/quota/quota_manager_proxy.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 void RunSoon(const base::Closure& closure) { | 18 void RunSoon(const base::Closure& closure) { |
| 19 base::MessageLoop::current()->PostTask(FROM_HERE, closure); | 19 base::MessageLoop::current()->PostTask(FROM_HERE, closure); |
| 20 } | 20 } |
| 21 | 21 |
| 22 const base::FilePath::CharType kServiceWorkerDirectory[] = | 22 const base::FilePath::CharType kServiceWorkerDirectory[] = |
| 23 FILE_PATH_LITERAL("ServiceWorker"); | 23 FILE_PATH_LITERAL("ServiceWorker"); |
| 24 | 24 |
| 25 } | 25 } // namespace |
| 26 | 26 |
| 27 ServiceWorkerStorage::ServiceWorkerStorage( | 27 ServiceWorkerStorage::ServiceWorkerStorage( |
| 28 const base::FilePath& path, | 28 const base::FilePath& path, |
| 29 quota::QuotaManagerProxy* quota_manager_proxy) | 29 quota::QuotaManagerProxy* quota_manager_proxy) |
| 30 : last_registration_id_(0), // TODO(kinuko): this should be read from disk. | 30 : last_registration_id_(0), // TODO(kinuko): this should be read from disk. |
| 31 last_version_id_(0), // TODO(kinuko): this should be read from disk. |
| 31 quota_manager_proxy_(quota_manager_proxy) { | 32 quota_manager_proxy_(quota_manager_proxy) { |
| 32 if (!path.empty()) | 33 if (!path.empty()) |
| 33 path_ = path.Append(kServiceWorkerDirectory); | 34 path_ = path.Append(kServiceWorkerDirectory); |
| 34 } | 35 } |
| 35 | 36 |
| 36 ServiceWorkerStorage::~ServiceWorkerStorage() { | 37 ServiceWorkerStorage::~ServiceWorkerStorage() { |
| 37 for (PatternToRegistrationMap::const_iterator iter = | 38 for (PatternToRegistrationMap::const_iterator iter = |
| 38 registration_by_pattern_.begin(); | 39 registration_by_pattern_.begin(); |
| 39 iter != registration_by_pattern_.end(); | 40 iter != registration_by_pattern_.end(); |
| 40 ++iter) { | 41 ++iter) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 return; | 110 return; |
| 110 } | 111 } |
| 111 registration_by_pattern_.erase(match); | 112 registration_by_pattern_.erase(match); |
| 112 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); | 113 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); |
| 113 } | 114 } |
| 114 | 115 |
| 115 int64 ServiceWorkerStorage::NewRegistrationId() { | 116 int64 ServiceWorkerStorage::NewRegistrationId() { |
| 116 return ++last_registration_id_; | 117 return ++last_registration_id_; |
| 117 } | 118 } |
| 118 | 119 |
| 120 int64 ServiceWorkerStorage::NewVersionId() { |
| 121 return ++last_version_id_; |
| 122 } |
| 123 |
| 119 bool ServiceWorkerStorage::PatternMatches(const GURL& pattern, | 124 bool ServiceWorkerStorage::PatternMatches(const GURL& pattern, |
| 120 const GURL& url) { | 125 const GURL& url) { |
| 121 // This is a really basic, naive | 126 // This is a really basic, naive |
| 122 // TODO(alecflett): Formalize what pattern matches mean. | 127 // TODO(alecflett): Formalize what pattern matches mean. |
| 123 // Temporarily borrowed directly from appcache::Namespace::IsMatch(). | 128 // Temporarily borrowed directly from appcache::Namespace::IsMatch(). |
| 124 // We have to escape '?' characters since MatchPattern also treats those | 129 // We have to escape '?' characters since MatchPattern also treats those |
| 125 // as wildcards which we don't want here, we only do '*'s. | 130 // as wildcards which we don't want here, we only do '*'s. |
| 126 std::string pattern_spec(pattern.spec()); | 131 std::string pattern_spec(pattern.spec()); |
| 127 if (pattern.has_query()) | 132 if (pattern.has_query()) |
| 128 ReplaceSubstringsAfterOffset(&pattern_spec, 0, "?", "\\?"); | 133 ReplaceSubstringsAfterOffset(&pattern_spec, 0, "?", "\\?"); |
| 129 return MatchPattern(url.spec(), pattern_spec); | 134 return MatchPattern(url.spec(), pattern_spec); |
| 130 } | 135 } |
| 131 | 136 |
| 132 } // namespace content | 137 } // namespace content |
| OLD | NEW |