Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: webkit/appcache/appcache.cc

Issue 8949001: Fix some loose ends around recently introduced AppCache INTERCEPT namespaces (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "webkit/appcache/appcache.h" 7 #include "webkit/appcache/appcache.h"
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 const AppCacheEntry* AppCache::GetEntryWithResponseId(int64 response_id) { 73 const AppCacheEntry* AppCache::GetEntryWithResponseId(int64 response_id) {
74 for (EntryMap::const_iterator iter = entries_.begin(); 74 for (EntryMap::const_iterator iter = entries_.begin();
75 iter != entries_.end(); ++iter) { 75 iter != entries_.end(); ++iter) {
76 if (iter->second.response_id() == response_id) 76 if (iter->second.response_id() == response_id)
77 return &iter->second; 77 return &iter->second;
78 } 78 }
79 return NULL; 79 return NULL;
80 } 80 }
81 81
82 GURL AppCache::GetFallbackEntryUrl(const GURL& namespace_url) const { 82 GURL AppCache::GetNamespaceEntryUrl(const NamespaceVector& namespaces,
83 size_t count = fallback_namespaces_.size(); 83 const GURL& namespace_url) const {
84 size_t count = namespaces.size();
84 for (size_t i = 0; i < count; ++i) { 85 for (size_t i = 0; i < count; ++i) {
85 if (fallback_namespaces_[i].namespace_url == namespace_url) 86 if (namespaces[i].namespace_url == namespace_url)
86 return fallback_namespaces_[i].target_url; 87 return namespaces[i].target_url;
87 } 88 }
88 NOTREACHED(); 89 NOTREACHED();
89 return GURL(); 90 return GURL();
90 } 91 }
91 92
92 namespace { 93 namespace {
93 bool SortNamespacesByLength( 94 bool SortNamespacesByLength(
94 const Namespace& lhs, const Namespace& rhs) { 95 const Namespace& lhs, const Namespace& rhs) {
95 return lhs.namespace_url.spec().length() > rhs.namespace_url.spec().length(); 96 return lhs.namespace_url.spec().length() > rhs.namespace_url.spec().length();
96 } 97 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 for (size_t i = 0; i < online_whitelist_namespaces_.size(); ++i) { 213 for (size_t i = 0; i < online_whitelist_namespaces_.size(); ++i) {
213 whitelists->push_back(AppCacheDatabase::OnlineWhiteListRecord()); 214 whitelists->push_back(AppCacheDatabase::OnlineWhiteListRecord());
214 AppCacheDatabase::OnlineWhiteListRecord& record = whitelists->back(); 215 AppCacheDatabase::OnlineWhiteListRecord& record = whitelists->back();
215 record.cache_id = cache_id_; 216 record.cache_id = cache_id_;
216 record.namespace_url = online_whitelist_namespaces_[i]; 217 record.namespace_url = online_whitelist_namespaces_[i];
217 } 218 }
218 } 219 }
219 } 220 }
220 221
221 bool AppCache::FindResponseForRequest(const GURL& url, 222 bool AppCache::FindResponseForRequest(const GURL& url,
222 AppCacheEntry* found_entry, AppCacheEntry* found_fallback_entry, 223 AppCacheEntry* found_entry, GURL* found_intercept_namespace,
223 GURL* found_fallback_namespace, bool* found_network_namespace) { 224 AppCacheEntry* found_fallback_entry, GURL* found_fallback_namespace,
225 bool* found_network_namespace) {
224 // Ignore fragments when looking up URL in the cache. 226 // Ignore fragments when looking up URL in the cache.
225 GURL url_no_ref; 227 GURL url_no_ref;
226 if (url.has_ref()) { 228 if (url.has_ref()) {
227 GURL::Replacements replacements; 229 GURL::Replacements replacements;
228 replacements.ClearRef(); 230 replacements.ClearRef();
229 url_no_ref = url.ReplaceComponents(replacements); 231 url_no_ref = url.ReplaceComponents(replacements);
230 } else { 232 } else {
231 url_no_ref = url; 233 url_no_ref = url;
232 } 234 }
233 235
234 // 6.6.6 Changes to the networking model 236 // 6.6.6 Changes to the networking model
235 237
236 AppCacheEntry* entry = GetEntry(url_no_ref); 238 AppCacheEntry* entry = GetEntry(url_no_ref);
237 if (entry) { 239 if (entry) {
238 *found_entry = *entry; 240 *found_entry = *entry;
239 return true; 241 return true;
240 } 242 }
241 243
242 if ((*found_network_namespace = 244 if ((*found_network_namespace =
243 IsInNetworkNamespace(url_no_ref, online_whitelist_namespaces_))) { 245 IsInNetworkNamespace(url_no_ref, online_whitelist_namespaces_))) {
244 return true; 246 return true;
245 } 247 }
246 248
247 const Namespace* intercept_namespace = FindInterceptNamespace(url_no_ref); 249 const Namespace* intercept_namespace = FindInterceptNamespace(url_no_ref);
248 if (intercept_namespace) { 250 if (intercept_namespace) {
249 entry = GetEntry(intercept_namespace->target_url); 251 entry = GetEntry(intercept_namespace->target_url);
250 DCHECK(entry); 252 DCHECK(entry);
251 *found_entry = *entry; 253 *found_entry = *entry;
254 *found_intercept_namespace = intercept_namespace->namespace_url;
252 return true; 255 return true;
253 } 256 }
254 257
255 const Namespace* fallback_namespace = FindFallbackNamespace(url_no_ref); 258 const Namespace* fallback_namespace = FindFallbackNamespace(url_no_ref);
256 if (fallback_namespace) { 259 if (fallback_namespace) {
257 entry = GetEntry(fallback_namespace->target_url); 260 entry = GetEntry(fallback_namespace->target_url);
258 DCHECK(entry); 261 DCHECK(entry);
259 *found_fallback_entry = *entry; 262 *found_fallback_entry = *entry;
260 *found_fallback_namespace = fallback_namespace->namespace_url; 263 *found_fallback_namespace = fallback_namespace->namespace_url;
261 return true; 264 return true;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 // structures and algorithms that can be applied here and above. 306 // structures and algorithms that can be applied here and above.
304 size_t count = namespaces.size(); 307 size_t count = namespaces.size();
305 for (size_t i = 0; i < count; ++i) { 308 for (size_t i = 0; i < count; ++i) {
306 if (StartsWithASCII(url.spec(), namespaces[i].spec(), true)) 309 if (StartsWithASCII(url.spec(), namespaces[i].spec(), true))
307 return true; 310 return true;
308 } 311 }
309 return false; 312 return false;
310 } 313 }
311 314
312 } // namespace appcache 315 } // namespace appcache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698