OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/browser/appcache/appcache.h" | 5 #include "content/browser/appcache/appcache.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "webkit/browser/appcache/appcache_executable_handler.h" | 11 #include "content/browser/appcache/appcache_executable_handler.h" |
12 #include "webkit/browser/appcache/appcache_group.h" | 12 #include "content/browser/appcache/appcache_group.h" |
13 #include "webkit/browser/appcache/appcache_host.h" | 13 #include "content/browser/appcache/appcache_host.h" |
14 #include "webkit/browser/appcache/appcache_storage.h" | 14 #include "content/browser/appcache/appcache_storage.h" |
15 #include "webkit/common/appcache/appcache_interfaces.h" | 15 #include "content/common/appcache_interfaces.h" |
16 | 16 |
17 namespace appcache { | 17 namespace content { |
18 | 18 |
19 AppCache::AppCache(AppCacheStorage* storage, int64 cache_id) | 19 AppCache::AppCache(AppCacheStorage* storage, int64 cache_id) |
20 : cache_id_(cache_id), | 20 : cache_id_(cache_id), |
21 owning_group_(NULL), | 21 owning_group_(NULL), |
22 online_whitelist_all_(false), | 22 online_whitelist_all_(false), |
23 is_complete_(false), | 23 is_complete_(false), |
24 cache_size_(0), | 24 cache_size_(0), |
25 storage_(storage) { | 25 storage_(storage) { |
26 storage_->working_set()->AddCache(this); | 26 storage_->working_set()->AddCache(this); |
27 } | 27 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 scoped_ptr<AppCacheExecutableHandler> own_ptr = | 108 scoped_ptr<AppCacheExecutableHandler> own_ptr = |
109 storage_->service()->handler_factory()-> | 109 storage_->service()->handler_factory()-> |
110 CreateHandler(handler_url, handler_source); | 110 CreateHandler(handler_url, handler_source); |
111 handler = own_ptr.release(); | 111 handler = own_ptr.release(); |
112 if (!handler) | 112 if (!handler) |
113 return NULL; | 113 return NULL; |
114 executable_handlers_[response_id] = handler; | 114 executable_handlers_[response_id] = handler; |
115 return handler; | 115 return handler; |
116 } | 116 } |
117 | 117 |
118 GURL AppCache::GetNamespaceEntryUrl(const NamespaceVector& namespaces, | 118 GURL AppCache::GetNamespaceEntryUrl(const AppCacheNamespaceVector& namespaces, |
119 const GURL& namespace_url) const { | 119 const GURL& namespace_url) const { |
120 size_t count = namespaces.size(); | 120 size_t count = namespaces.size(); |
121 for (size_t i = 0; i < count; ++i) { | 121 for (size_t i = 0; i < count; ++i) { |
122 if (namespaces[i].namespace_url == namespace_url) | 122 if (namespaces[i].namespace_url == namespace_url) |
123 return namespaces[i].target_url; | 123 return namespaces[i].target_url; |
124 } | 124 } |
125 NOTREACHED(); | 125 NOTREACHED(); |
126 return GURL(); | 126 return GURL(); |
127 } | 127 } |
128 | 128 |
129 namespace { | 129 namespace { |
130 bool SortNamespacesByLength( | 130 bool SortNamespacesByLength( |
131 const Namespace& lhs, const Namespace& rhs) { | 131 const AppCacheNamespace& lhs, const AppCacheNamespace& rhs) { |
132 return lhs.namespace_url.spec().length() > rhs.namespace_url.spec().length(); | 132 return lhs.namespace_url.spec().length() > rhs.namespace_url.spec().length(); |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 void AppCache::InitializeWithManifest(Manifest* manifest) { | 136 void AppCache::InitializeWithManifest(Manifest* manifest) { |
137 DCHECK(manifest); | 137 DCHECK(manifest); |
138 intercept_namespaces_.swap(manifest->intercept_namespaces); | 138 intercept_namespaces_.swap(manifest->intercept_namespaces); |
139 fallback_namespaces_.swap(manifest->fallback_namespaces); | 139 fallback_namespaces_.swap(manifest->fallback_namespaces); |
140 online_whitelist_namespaces_.swap(manifest->online_whitelist_namespaces); | 140 online_whitelist_namespaces_.swap(manifest->online_whitelist_namespaces); |
141 online_whitelist_all_ = manifest->online_whitelist_all; | 141 online_whitelist_all_ = manifest->online_whitelist_all; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // Sort the fallback namespaces by url string length, longest to shortest, | 174 // Sort the fallback namespaces by url string length, longest to shortest, |
175 // since longer matches trump when matching a url to a namespace. | 175 // since longer matches trump when matching a url to a namespace. |
176 std::sort(intercept_namespaces_.begin(), intercept_namespaces_.end(), | 176 std::sort(intercept_namespaces_.begin(), intercept_namespaces_.end(), |
177 SortNamespacesByLength); | 177 SortNamespacesByLength); |
178 std::sort(fallback_namespaces_.begin(), fallback_namespaces_.end(), | 178 std::sort(fallback_namespaces_.begin(), fallback_namespaces_.end(), |
179 SortNamespacesByLength); | 179 SortNamespacesByLength); |
180 | 180 |
181 for (size_t i = 0; i < whitelists.size(); ++i) { | 181 for (size_t i = 0; i < whitelists.size(); ++i) { |
182 const AppCacheDatabase::OnlineWhiteListRecord& record = whitelists.at(i); | 182 const AppCacheDatabase::OnlineWhiteListRecord& record = whitelists.at(i); |
183 online_whitelist_namespaces_.push_back( | 183 online_whitelist_namespaces_.push_back( |
184 Namespace(APPCACHE_NETWORK_NAMESPACE, | 184 AppCacheNamespace(APPCACHE_NETWORK_NAMESPACE, |
185 record.namespace_url, | 185 record.namespace_url, |
186 GURL(), | 186 GURL(), |
187 record.is_pattern)); | 187 record.is_pattern)); |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 void AppCache::ToDatabaseRecords( | 191 void AppCache::ToDatabaseRecords( |
192 const AppCacheGroup* group, | 192 const AppCacheGroup* group, |
193 AppCacheDatabase::CacheRecord* cache_record, | 193 AppCacheDatabase::CacheRecord* cache_record, |
194 std::vector<AppCacheDatabase::EntryRecord>* entries, | 194 std::vector<AppCacheDatabase::EntryRecord>* entries, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 261 |
262 AppCacheEntry* entry = GetEntry(url_no_ref); | 262 AppCacheEntry* entry = GetEntry(url_no_ref); |
263 if (entry) { | 263 if (entry) { |
264 *found_entry = *entry; | 264 *found_entry = *entry; |
265 return true; | 265 return true; |
266 } | 266 } |
267 | 267 |
268 if ((*found_network_namespace = IsInNetworkNamespace(url_no_ref))) | 268 if ((*found_network_namespace = IsInNetworkNamespace(url_no_ref))) |
269 return true; | 269 return true; |
270 | 270 |
271 const Namespace* intercept_namespace = FindInterceptNamespace(url_no_ref); | 271 const AppCacheNamespace* intercept_namespace = |
| 272 FindInterceptNamespace(url_no_ref); |
272 if (intercept_namespace) { | 273 if (intercept_namespace) { |
273 entry = GetEntry(intercept_namespace->target_url); | 274 entry = GetEntry(intercept_namespace->target_url); |
274 DCHECK(entry); | 275 DCHECK(entry); |
275 *found_entry = *entry; | 276 *found_entry = *entry; |
276 *found_intercept_namespace = intercept_namespace->namespace_url; | 277 *found_intercept_namespace = intercept_namespace->namespace_url; |
277 return true; | 278 return true; |
278 } | 279 } |
279 | 280 |
280 const Namespace* fallback_namespace = FindFallbackNamespace(url_no_ref); | 281 const AppCacheNamespace* fallback_namespace = |
| 282 FindFallbackNamespace(url_no_ref); |
281 if (fallback_namespace) { | 283 if (fallback_namespace) { |
282 entry = GetEntry(fallback_namespace->target_url); | 284 entry = GetEntry(fallback_namespace->target_url); |
283 DCHECK(entry); | 285 DCHECK(entry); |
284 *found_fallback_entry = *entry; | 286 *found_fallback_entry = *entry; |
285 *found_fallback_namespace = fallback_namespace->namespace_url; | 287 *found_fallback_namespace = fallback_namespace->namespace_url; |
286 return true; | 288 return true; |
287 } | 289 } |
288 | 290 |
289 *found_network_namespace = online_whitelist_all_; | 291 *found_network_namespace = online_whitelist_all_; |
290 return *found_network_namespace; | 292 return *found_network_namespace; |
(...skipping 12 matching lines...) Expand all Loading... |
303 info.is_intercept = iter->second.IsIntercept(); | 305 info.is_intercept = iter->second.IsIntercept(); |
304 info.is_fallback = iter->second.IsFallback(); | 306 info.is_fallback = iter->second.IsFallback(); |
305 info.is_foreign = iter->second.IsForeign(); | 307 info.is_foreign = iter->second.IsForeign(); |
306 info.is_explicit = iter->second.IsExplicit(); | 308 info.is_explicit = iter->second.IsExplicit(); |
307 info.size = iter->second.response_size(); | 309 info.size = iter->second.response_size(); |
308 info.response_id = iter->second.response_id(); | 310 info.response_id = iter->second.response_id(); |
309 } | 311 } |
310 } | 312 } |
311 | 313 |
312 // static | 314 // static |
313 const Namespace* AppCache::FindNamespace( | 315 const AppCacheNamespace* AppCache::FindNamespace( |
314 const NamespaceVector& namespaces, | 316 const AppCacheNamespaceVector& namespaces, |
315 const GURL& url) { | 317 const GURL& url) { |
316 size_t count = namespaces.size(); | 318 size_t count = namespaces.size(); |
317 for (size_t i = 0; i < count; ++i) { | 319 for (size_t i = 0; i < count; ++i) { |
318 if (namespaces[i].IsMatch(url)) | 320 if (namespaces[i].IsMatch(url)) |
319 return &namespaces[i]; | 321 return &namespaces[i]; |
320 } | 322 } |
321 return NULL; | 323 return NULL; |
322 } | 324 } |
323 | 325 |
324 } // namespace appcache | 326 } // namespace content |
OLD | NEW |