diff options
author | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-19 03:12:12 +0000 |
---|---|---|
committer | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-19 03:12:12 +0000 |
commit | 0b52f1c47868cb6d7b132a15bd7c0a94df08de79 (patch) | |
tree | 7ecce97440c40f357f65672305d8597b51775faa /webkit/appcache/appcache_storage_impl.cc | |
parent | c112093004963fb24639127d4a7ce3b2fdfda508 (diff) | |
download | chromium_src-0b52f1c47868cb6d7b132a15bd7c0a94df08de79.zip chromium_src-0b52f1c47868cb6d7b132a15bd7c0a94df08de79.tar.gz chromium_src-0b52f1c47868cb6d7b132a15bd7c0a94df08de79.tar.bz2 |
Alter the relative priorities of network vs fallback namespaces in the appcache. If a resource url is in an appcache's network namespace and fallback namespace, the network namespace wins (with the exception of the special '*' network namespace which does not take priority over the fallback namespace.
BUG=WK49292
TEST=unit test, also a new layout test (not landed yet)
Review URL: http://codereview.chromium.org/4807001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66731 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_storage_impl.cc')
-rw-r--r-- | webkit/appcache/appcache_storage_impl.cc | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/webkit/appcache/appcache_storage_impl.cc b/webkit/appcache/appcache_storage_impl.cc index b0aa25a..8d21105 100644 --- a/webkit/appcache/appcache_storage_impl.cc +++ b/webkit/appcache/appcache_storage_impl.cc @@ -558,13 +558,52 @@ class AppCacheStorageImpl::FindMainResponseTask : public DatabaseTask { GURL manifest_url_; }; +// Helpers for FindMainResponseTask::Run() namespace { bool SortByLength( const AppCacheDatabase::FallbackNameSpaceRecord& lhs, const AppCacheDatabase::FallbackNameSpaceRecord& rhs) { return lhs.namespace_url.spec().length() > rhs.namespace_url.spec().length(); } -} + +class NetworkNamespaceHelper { + public: + explicit NetworkNamespaceHelper(AppCacheDatabase* database) + : database_(database) { + } + + bool IsInNetworkNamespace(const GURL& url, int64 cache_id) { + static const std::vector<GURL> kEmptyVector; + typedef std::pair<WhiteListMap::iterator, bool> InsertResult; + InsertResult result = namespaces_map_.insert( + WhiteListMap::value_type(cache_id, kEmptyVector)); + if (result.second) + GetOnlineWhiteListForCache(cache_id, &result.first->second); + return AppCache::IsInNetworkNamespace(url, result.first->second); + } + + private: + void GetOnlineWhiteListForCache( + int64 cache_id, std::vector<GURL>* urls) { + DCHECK(urls && urls->empty()); + typedef std::vector<AppCacheDatabase::OnlineWhiteListRecord> + WhiteListVector; + WhiteListVector records; + if (!database_->FindOnlineWhiteListForCache(cache_id, &records)) + return; + WhiteListVector::const_iterator iter = records.begin(); + while (iter != records.end()) { + urls->push_back(iter->namespace_url); + ++iter; + } + } + + // Key is cache id + typedef std::map<int64, std::vector<GURL> > WhiteListMap; + WhiteListMap namespaces_map_; + AppCacheDatabase* database_; +}; +} // namespace void AppCacheStorageImpl::FindMainResponseTask::Run() { // We have a bias for hits from caches that are in use. @@ -615,7 +654,13 @@ void AppCacheStorageImpl::FindMainResponseTask::Run() { bool has_candidate = false; GURL candidate_fallback_namespace; std::vector<AppCacheDatabase::FallbackNameSpaceRecord>::iterator iter; + NetworkNamespaceHelper network_namespace_helper(database_); for (iter = fallbacks.begin(); iter < fallbacks.end(); ++iter) { + // Skip this fallback namespace if the requested url falls into a network + // namespace of the containing appcache. + if (network_namespace_helper.IsInNetworkNamespace(url_, iter->cache_id)) + continue; + if (has_candidate && (candidate_fallback_namespace.spec().length() > iter->namespace_url.spec().length())) { |