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_storage_impl.h" | 5 #include "content/browser/appcache/appcache_storage_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "content/browser/appcache/appcache.h" |
| 20 #include "content/browser/appcache/appcache_database.h" |
| 21 #include "content/browser/appcache/appcache_entry.h" |
| 22 #include "content/browser/appcache/appcache_group.h" |
| 23 #include "content/browser/appcache/appcache_histograms.h" |
| 24 #include "content/browser/appcache/appcache_quota_client.h" |
| 25 #include "content/browser/appcache/appcache_response.h" |
| 26 #include "content/browser/appcache/appcache_service_impl.h" |
19 #include "net/base/cache_type.h" | 27 #include "net/base/cache_type.h" |
20 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
21 #include "sql/connection.h" | 29 #include "sql/connection.h" |
22 #include "sql/transaction.h" | 30 #include "sql/transaction.h" |
23 #include "webkit/browser/appcache/appcache.h" | |
24 #include "webkit/browser/appcache/appcache_database.h" | |
25 #include "webkit/browser/appcache/appcache_entry.h" | |
26 #include "webkit/browser/appcache/appcache_group.h" | |
27 #include "webkit/browser/appcache/appcache_histograms.h" | |
28 #include "webkit/browser/appcache/appcache_quota_client.h" | |
29 #include "webkit/browser/appcache/appcache_response.h" | |
30 #include "webkit/browser/appcache/appcache_service_impl.h" | |
31 #include "webkit/browser/quota/quota_client.h" | 31 #include "webkit/browser/quota/quota_client.h" |
32 #include "webkit/browser/quota/quota_manager.h" | 32 #include "webkit/browser/quota/quota_manager.h" |
33 #include "webkit/browser/quota/quota_manager_proxy.h" | 33 #include "webkit/browser/quota/quota_manager_proxy.h" |
34 #include "webkit/browser/quota/special_storage_policy.h" | 34 #include "webkit/browser/quota/special_storage_policy.h" |
35 | 35 |
36 namespace appcache { | 36 namespace content { |
37 | 37 |
38 // Hard coded default when not using quota management. | 38 // Hard coded default when not using quota management. |
39 static const int kDefaultQuota = 5 * 1024 * 1024; | 39 static const int kDefaultQuota = 5 * 1024 * 1024; |
40 | 40 |
41 static const int kMaxDiskCacheSize = 250 * 1024 * 1024; | 41 static const int kMaxDiskCacheSize = 250 * 1024 * 1024; |
42 static const int kMaxMemDiskCacheSize = 10 * 1024 * 1024; | 42 static const int kMaxMemDiskCacheSize = 10 * 1024 * 1024; |
43 static const base::FilePath::CharType kDiskCacheDirectoryName[] = | 43 static const base::FilePath::CharType kDiskCacheDirectoryName[] = |
44 FILE_PATH_LITERAL("Cache"); | 44 FILE_PATH_LITERAL("Cache"); |
45 | 45 |
46 namespace { | 46 namespace { |
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 | 834 |
835 class NetworkNamespaceHelper { | 835 class NetworkNamespaceHelper { |
836 public: | 836 public: |
837 explicit NetworkNamespaceHelper(AppCacheDatabase* database) | 837 explicit NetworkNamespaceHelper(AppCacheDatabase* database) |
838 : database_(database) { | 838 : database_(database) { |
839 } | 839 } |
840 | 840 |
841 bool IsInNetworkNamespace(const GURL& url, int64 cache_id) { | 841 bool IsInNetworkNamespace(const GURL& url, int64 cache_id) { |
842 typedef std::pair<WhiteListMap::iterator, bool> InsertResult; | 842 typedef std::pair<WhiteListMap::iterator, bool> InsertResult; |
843 InsertResult result = namespaces_map_.insert( | 843 InsertResult result = namespaces_map_.insert( |
844 WhiteListMap::value_type(cache_id, NamespaceVector())); | 844 WhiteListMap::value_type(cache_id, AppCacheNamespaceVector())); |
845 if (result.second) | 845 if (result.second) |
846 GetOnlineWhiteListForCache(cache_id, &result.first->second); | 846 GetOnlineWhiteListForCache(cache_id, &result.first->second); |
847 return AppCache::FindNamespace(result.first->second, url) != NULL; | 847 return AppCache::FindNamespace(result.first->second, url) != NULL; |
848 } | 848 } |
849 | 849 |
850 private: | 850 private: |
851 void GetOnlineWhiteListForCache( | 851 void GetOnlineWhiteListForCache( |
852 int64 cache_id, NamespaceVector* namespaces) { | 852 int64 cache_id, AppCacheNamespaceVector* namespaces) { |
853 DCHECK(namespaces && namespaces->empty()); | 853 DCHECK(namespaces && namespaces->empty()); |
854 typedef std::vector<AppCacheDatabase::OnlineWhiteListRecord> | 854 typedef std::vector<AppCacheDatabase::OnlineWhiteListRecord> |
855 WhiteListVector; | 855 WhiteListVector; |
856 WhiteListVector records; | 856 WhiteListVector records; |
857 if (!database_->FindOnlineWhiteListForCache(cache_id, &records)) | 857 if (!database_->FindOnlineWhiteListForCache(cache_id, &records)) |
858 return; | 858 return; |
859 WhiteListVector::const_iterator iter = records.begin(); | 859 WhiteListVector::const_iterator iter = records.begin(); |
860 while (iter != records.end()) { | 860 while (iter != records.end()) { |
861 namespaces->push_back( | 861 namespaces->push_back( |
862 Namespace(APPCACHE_NETWORK_NAMESPACE, iter->namespace_url, GURL(), | 862 AppCacheNamespace(APPCACHE_NETWORK_NAMESPACE, iter->namespace_url, |
863 iter->is_pattern)); | 863 GURL(), iter->is_pattern)); |
864 ++iter; | 864 ++iter; |
865 } | 865 } |
866 } | 866 } |
867 | 867 |
868 // Key is cache id | 868 // Key is cache id |
869 typedef std::map<int64, NamespaceVector> WhiteListMap; | 869 typedef std::map<int64, AppCacheNamespaceVector> WhiteListMap; |
870 WhiteListMap namespaces_map_; | 870 WhiteListMap namespaces_map_; |
871 AppCacheDatabase* database_; | 871 AppCacheDatabase* database_; |
872 }; | 872 }; |
873 | 873 |
874 } // namespace | 874 } // namespace |
875 | 875 |
876 class AppCacheStorageImpl::FindMainResponseTask : public DatabaseTask { | 876 class AppCacheStorageImpl::FindMainResponseTask : public DatabaseTask { |
877 public: | 877 public: |
878 FindMainResponseTask(AppCacheStorageImpl* storage, | 878 FindMainResponseTask(AppCacheStorageImpl* storage, |
879 const GURL& url, | 879 const GURL& url, |
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1850 cache_directory_, true), | 1850 cache_directory_, true), |
1851 base::Bind(&AppCacheStorageImpl::CallScheduleReinitialize, | 1851 base::Bind(&AppCacheStorageImpl::CallScheduleReinitialize, |
1852 weak_factory_.GetWeakPtr())); | 1852 weak_factory_.GetWeakPtr())); |
1853 } | 1853 } |
1854 | 1854 |
1855 void AppCacheStorageImpl::CallScheduleReinitialize() { | 1855 void AppCacheStorageImpl::CallScheduleReinitialize() { |
1856 service_->ScheduleReinitialize(); | 1856 service_->ScheduleReinitialize(); |
1857 // note: 'this' may be deleted at this point. | 1857 // note: 'this' may be deleted at this point. |
1858 } | 1858 } |
1859 | 1859 |
1860 } // namespace appcache | 1860 } // namespace content |
OLD | NEW |