| 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 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_DATABASE_H_ | 5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_DATABASE_H_ |
| 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_DATABASE_H_ | 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_DATABASE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include <map> | 10 #include <map> |
| 9 #include <set> | 11 #include <set> |
| 10 #include <vector> | 12 #include <vector> |
| 11 | 13 |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 14 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 15 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 17 #include "content/common/appcache_interfaces.h" | 18 #include "content/common/appcache_interfaces.h" |
| 18 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 20 | 21 |
| 21 namespace sql { | 22 namespace sql { |
| 22 class Connection; | 23 class Connection; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 44 FORWARD_DECLARE_TEST(AppCacheDatabaseTest, WasCorrutionDetected); | 45 FORWARD_DECLARE_TEST(AppCacheDatabaseTest, WasCorrutionDetected); |
| 45 class AppCacheDatabaseTest; | 46 class AppCacheDatabaseTest; |
| 46 class AppCacheStorageImplTest; | 47 class AppCacheStorageImplTest; |
| 47 | 48 |
| 48 class CONTENT_EXPORT AppCacheDatabase { | 49 class CONTENT_EXPORT AppCacheDatabase { |
| 49 public: | 50 public: |
| 50 struct CONTENT_EXPORT GroupRecord { | 51 struct CONTENT_EXPORT GroupRecord { |
| 51 GroupRecord(); | 52 GroupRecord(); |
| 52 ~GroupRecord(); | 53 ~GroupRecord(); |
| 53 | 54 |
| 54 int64 group_id; | 55 int64_t group_id; |
| 55 GURL origin; | 56 GURL origin; |
| 56 GURL manifest_url; | 57 GURL manifest_url; |
| 57 base::Time creation_time; | 58 base::Time creation_time; |
| 58 base::Time last_access_time; | 59 base::Time last_access_time; |
| 59 base::Time last_full_update_check_time; | 60 base::Time last_full_update_check_time; |
| 60 base::Time first_evictable_error_time; | 61 base::Time first_evictable_error_time; |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 struct CONTENT_EXPORT CacheRecord { | 64 struct CONTENT_EXPORT CacheRecord { |
| 64 CacheRecord() | 65 CacheRecord() |
| 65 : cache_id(0), group_id(0), online_wildcard(false), cache_size(0) {} | 66 : cache_id(0), group_id(0), online_wildcard(false), cache_size(0) {} |
| 66 | 67 |
| 67 int64 cache_id; | 68 int64_t cache_id; |
| 68 int64 group_id; | 69 int64_t group_id; |
| 69 bool online_wildcard; | 70 bool online_wildcard; |
| 70 base::Time update_time; | 71 base::Time update_time; |
| 71 int64 cache_size; // the sum of all response sizes in this cache | 72 int64_t cache_size; // the sum of all response sizes in this cache |
| 72 }; | 73 }; |
| 73 | 74 |
| 74 struct EntryRecord { | 75 struct EntryRecord { |
| 75 EntryRecord() : cache_id(0), flags(0), response_id(0), response_size(0) {} | 76 EntryRecord() : cache_id(0), flags(0), response_id(0), response_size(0) {} |
| 76 | 77 |
| 77 int64 cache_id; | 78 int64_t cache_id; |
| 78 GURL url; | 79 GURL url; |
| 79 int flags; | 80 int flags; |
| 80 int64 response_id; | 81 int64_t response_id; |
| 81 int64 response_size; | 82 int64_t response_size; |
| 82 }; | 83 }; |
| 83 | 84 |
| 84 struct CONTENT_EXPORT NamespaceRecord { | 85 struct CONTENT_EXPORT NamespaceRecord { |
| 85 NamespaceRecord(); | 86 NamespaceRecord(); |
| 86 ~NamespaceRecord(); | 87 ~NamespaceRecord(); |
| 87 | 88 |
| 88 int64 cache_id; | 89 int64_t cache_id; |
| 89 GURL origin; | 90 GURL origin; |
| 90 AppCacheNamespace namespace_; | 91 AppCacheNamespace namespace_; |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 typedef std::vector<NamespaceRecord> NamespaceRecordVector; | 94 typedef std::vector<NamespaceRecord> NamespaceRecordVector; |
| 94 | 95 |
| 95 struct OnlineWhiteListRecord { | 96 struct OnlineWhiteListRecord { |
| 96 OnlineWhiteListRecord() : cache_id(0), is_pattern(false) {} | 97 OnlineWhiteListRecord() : cache_id(0), is_pattern(false) {} |
| 97 | 98 |
| 98 int64 cache_id; | 99 int64_t cache_id; |
| 99 GURL namespace_url; | 100 GURL namespace_url; |
| 100 bool is_pattern; | 101 bool is_pattern; |
| 101 }; | 102 }; |
| 102 | 103 |
| 103 explicit AppCacheDatabase(const base::FilePath& path); | 104 explicit AppCacheDatabase(const base::FilePath& path); |
| 104 ~AppCacheDatabase(); | 105 ~AppCacheDatabase(); |
| 105 | 106 |
| 106 void Disable(); | 107 void Disable(); |
| 107 bool is_disabled() const { return is_disabled_; } | 108 bool is_disabled() const { return is_disabled_; } |
| 108 bool was_corruption_detected() const { return was_corruption_detected_; } | 109 bool was_corruption_detected() const { return was_corruption_detected_; } |
| 109 | 110 |
| 110 int64 GetOriginUsage(const GURL& origin); | 111 int64_t GetOriginUsage(const GURL& origin); |
| 111 bool GetAllOriginUsage(std::map<GURL, int64>* usage_map); | 112 bool GetAllOriginUsage(std::map<GURL, int64_t>* usage_map); |
| 112 | 113 |
| 113 bool FindOriginsWithGroups(std::set<GURL>* origins); | 114 bool FindOriginsWithGroups(std::set<GURL>* origins); |
| 114 bool FindLastStorageIds( | 115 bool FindLastStorageIds(int64_t* last_group_id, |
| 115 int64* last_group_id, int64* last_cache_id, int64* last_response_id, | 116 int64_t* last_cache_id, |
| 116 int64* last_deletable_response_rowid); | 117 int64_t* last_response_id, |
| 118 int64_t* last_deletable_response_rowid); |
| 117 | 119 |
| 118 bool FindGroup(int64 group_id, GroupRecord* record); | 120 bool FindGroup(int64_t group_id, GroupRecord* record); |
| 119 bool FindGroupForManifestUrl(const GURL& manifest_url, GroupRecord* record); | 121 bool FindGroupForManifestUrl(const GURL& manifest_url, GroupRecord* record); |
| 120 bool FindGroupsForOrigin( | 122 bool FindGroupsForOrigin( |
| 121 const GURL& origin, std::vector<GroupRecord>* records); | 123 const GURL& origin, std::vector<GroupRecord>* records); |
| 122 bool FindGroupForCache(int64 cache_id, GroupRecord* record); | 124 bool FindGroupForCache(int64_t cache_id, GroupRecord* record); |
| 123 bool InsertGroup(const GroupRecord* record); | 125 bool InsertGroup(const GroupRecord* record); |
| 124 bool DeleteGroup(int64 group_id); | 126 bool DeleteGroup(int64_t group_id); |
| 125 | 127 |
| 126 // The access and eviction time update methods do not fail when | 128 // The access and eviction time update methods do not fail when |
| 127 // given invalid group_ids. The return value only indicates whether | 129 // given invalid group_ids. The return value only indicates whether |
| 128 // the database is functioning. | 130 // the database is functioning. |
| 129 bool UpdateLastAccessTime(int64 group_id, | 131 bool UpdateLastAccessTime(int64_t group_id, base::Time last_access_time); |
| 130 base::Time last_access_time); | 132 bool LazyUpdateLastAccessTime(int64_t group_id, base::Time last_access_time); |
| 131 bool LazyUpdateLastAccessTime(int64 group_id, | 133 bool UpdateEvictionTimes(int64_t group_id, |
| 132 base::Time last_access_time); | |
| 133 bool UpdateEvictionTimes(int64 group_id, | |
| 134 base::Time last_full_update_check_time, | 134 base::Time last_full_update_check_time, |
| 135 base::Time first_evictable_error_time); | 135 base::Time first_evictable_error_time); |
| 136 bool CommitLazyLastAccessTimes(); // The destructor calls this too. | 136 bool CommitLazyLastAccessTimes(); // The destructor calls this too. |
| 137 | 137 |
| 138 bool FindCache(int64 cache_id, CacheRecord* record); | 138 bool FindCache(int64_t cache_id, CacheRecord* record); |
| 139 bool FindCacheForGroup(int64 group_id, CacheRecord* record); | 139 bool FindCacheForGroup(int64_t group_id, CacheRecord* record); |
| 140 bool FindCachesForOrigin( | 140 bool FindCachesForOrigin( |
| 141 const GURL& origin, std::vector<CacheRecord>* records); | 141 const GURL& origin, std::vector<CacheRecord>* records); |
| 142 bool InsertCache(const CacheRecord* record); | 142 bool InsertCache(const CacheRecord* record); |
| 143 bool DeleteCache(int64 cache_id); | 143 bool DeleteCache(int64_t cache_id); |
| 144 | 144 |
| 145 bool FindEntriesForCache( | 145 bool FindEntriesForCache(int64_t cache_id, std::vector<EntryRecord>* records); |
| 146 int64 cache_id, std::vector<EntryRecord>* records); | |
| 147 bool FindEntriesForUrl( | 146 bool FindEntriesForUrl( |
| 148 const GURL& url, std::vector<EntryRecord>* records); | 147 const GURL& url, std::vector<EntryRecord>* records); |
| 149 bool FindEntry(int64 cache_id, const GURL& url, EntryRecord* record); | 148 bool FindEntry(int64_t cache_id, const GURL& url, EntryRecord* record); |
| 150 bool InsertEntry(const EntryRecord* record); | 149 bool InsertEntry(const EntryRecord* record); |
| 151 bool InsertEntryRecords( | 150 bool InsertEntryRecords( |
| 152 const std::vector<EntryRecord>& records); | 151 const std::vector<EntryRecord>& records); |
| 153 bool DeleteEntriesForCache(int64 cache_id); | 152 bool DeleteEntriesForCache(int64_t cache_id); |
| 154 bool AddEntryFlags(const GURL& entry_url, int64 cache_id, | 153 bool AddEntryFlags(const GURL& entry_url, |
| 154 int64_t cache_id, |
| 155 int additional_flags); | 155 int additional_flags); |
| 156 bool FindResponseIdsForCacheAsVector( | 156 bool FindResponseIdsForCacheAsVector(int64_t cache_id, |
| 157 int64 cache_id, std::vector<int64>* response_ids) { | 157 std::vector<int64_t>* response_ids) { |
| 158 return FindResponseIdsForCacheHelper(cache_id, response_ids, NULL); | 158 return FindResponseIdsForCacheHelper(cache_id, response_ids, NULL); |
| 159 } | 159 } |
| 160 bool FindResponseIdsForCacheAsSet( | 160 bool FindResponseIdsForCacheAsSet(int64_t cache_id, |
| 161 int64 cache_id, std::set<int64>* response_ids) { | 161 std::set<int64_t>* response_ids) { |
| 162 return FindResponseIdsForCacheHelper(cache_id, NULL, response_ids); | 162 return FindResponseIdsForCacheHelper(cache_id, NULL, response_ids); |
| 163 } | 163 } |
| 164 | 164 |
| 165 bool FindNamespacesForOrigin( | 165 bool FindNamespacesForOrigin( |
| 166 const GURL& origin, | 166 const GURL& origin, |
| 167 NamespaceRecordVector* intercepts, | 167 NamespaceRecordVector* intercepts, |
| 168 NamespaceRecordVector* fallbacks); | 168 NamespaceRecordVector* fallbacks); |
| 169 bool FindNamespacesForCache( | 169 bool FindNamespacesForCache(int64_t cache_id, |
| 170 int64 cache_id, | 170 NamespaceRecordVector* intercepts, |
| 171 NamespaceRecordVector* intercepts, | 171 std::vector<NamespaceRecord>* fallbacks); |
| 172 std::vector<NamespaceRecord>* fallbacks); | |
| 173 bool InsertNamespaceRecords( | 172 bool InsertNamespaceRecords( |
| 174 const NamespaceRecordVector& records); | 173 const NamespaceRecordVector& records); |
| 175 bool InsertNamespace(const NamespaceRecord* record); | 174 bool InsertNamespace(const NamespaceRecord* record); |
| 176 bool DeleteNamespacesForCache(int64 cache_id); | 175 bool DeleteNamespacesForCache(int64_t cache_id); |
| 177 | 176 |
| 178 bool FindOnlineWhiteListForCache( | 177 bool FindOnlineWhiteListForCache(int64_t cache_id, |
| 179 int64 cache_id, std::vector<OnlineWhiteListRecord>* records); | 178 std::vector<OnlineWhiteListRecord>* records); |
| 180 bool InsertOnlineWhiteList(const OnlineWhiteListRecord* record); | 179 bool InsertOnlineWhiteList(const OnlineWhiteListRecord* record); |
| 181 bool InsertOnlineWhiteListRecords( | 180 bool InsertOnlineWhiteListRecords( |
| 182 const std::vector<OnlineWhiteListRecord>& records); | 181 const std::vector<OnlineWhiteListRecord>& records); |
| 183 bool DeleteOnlineWhiteListForCache(int64 cache_id); | 182 bool DeleteOnlineWhiteListForCache(int64_t cache_id); |
| 184 | 183 |
| 185 bool GetDeletableResponseIds(std::vector<int64>* response_ids, | 184 bool GetDeletableResponseIds(std::vector<int64_t>* response_ids, |
| 186 int64 max_rowid, int limit); | 185 int64_t max_rowid, |
| 187 bool InsertDeletableResponseIds(const std::vector<int64>& response_ids); | 186 int limit); |
| 188 bool DeleteDeletableResponseIds(const std::vector<int64>& response_ids); | 187 bool InsertDeletableResponseIds(const std::vector<int64_t>& response_ids); |
| 188 bool DeleteDeletableResponseIds(const std::vector<int64_t>& response_ids); |
| 189 | 189 |
| 190 // So our callers can wrap operations in transactions. | 190 // So our callers can wrap operations in transactions. |
| 191 sql::Connection* db_connection() { | 191 sql::Connection* db_connection() { |
| 192 LazyOpen(true); | 192 LazyOpen(true); |
| 193 return db_.get(); | 193 return db_.get(); |
| 194 } | 194 } |
| 195 | 195 |
| 196 private: | 196 private: |
| 197 bool RunCachedStatementWithIds( | 197 bool RunCachedStatementWithIds(const sql::StatementID& statement_id, |
| 198 const sql::StatementID& statement_id, const char* sql, | 198 const char* sql, |
| 199 const std::vector<int64>& ids); | 199 const std::vector<int64_t>& ids); |
| 200 bool RunUniqueStatementWithInt64Result(const char* sql, int64* result); | 200 bool RunUniqueStatementWithInt64Result(const char* sql, int64_t* result); |
| 201 | 201 |
| 202 bool FindResponseIdsForCacheHelper( | 202 bool FindResponseIdsForCacheHelper(int64_t cache_id, |
| 203 int64 cache_id, std::vector<int64>* ids_vector, | 203 std::vector<int64_t>* ids_vector, |
| 204 std::set<int64>* ids_set); | 204 std::set<int64_t>* ids_set); |
| 205 | 205 |
| 206 // Record retrieval helpers | 206 // Record retrieval helpers |
| 207 void ReadGroupRecord(const sql::Statement& statement, GroupRecord* record); | 207 void ReadGroupRecord(const sql::Statement& statement, GroupRecord* record); |
| 208 void ReadCacheRecord(const sql::Statement& statement, CacheRecord* record); | 208 void ReadCacheRecord(const sql::Statement& statement, CacheRecord* record); |
| 209 void ReadEntryRecord(const sql::Statement& statement, EntryRecord* record); | 209 void ReadEntryRecord(const sql::Statement& statement, EntryRecord* record); |
| 210 void ReadNamespaceRecords( | 210 void ReadNamespaceRecords( |
| 211 sql::Statement* statement, | 211 sql::Statement* statement, |
| 212 NamespaceRecordVector* intercepts, | 212 NamespaceRecordVector* intercepts, |
| 213 NamespaceRecordVector* fallbacks); | 213 NamespaceRecordVector* fallbacks); |
| 214 void ReadNamespaceRecord( | 214 void ReadNamespaceRecord( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 227 // Deletes the existing database file and the entire directory containing | 227 // Deletes the existing database file and the entire directory containing |
| 228 // the database file including the disk cache in which response headers | 228 // the database file including the disk cache in which response headers |
| 229 // and bodies are stored, and then creates a new database file. | 229 // and bodies are stored, and then creates a new database file. |
| 230 bool DeleteExistingAndCreateNewDatabase(); | 230 bool DeleteExistingAndCreateNewDatabase(); |
| 231 | 231 |
| 232 void OnDatabaseError(int err, sql::Statement* stmt); | 232 void OnDatabaseError(int err, sql::Statement* stmt); |
| 233 | 233 |
| 234 base::FilePath db_file_path_; | 234 base::FilePath db_file_path_; |
| 235 scoped_ptr<sql::Connection> db_; | 235 scoped_ptr<sql::Connection> db_; |
| 236 scoped_ptr<sql::MetaTable> meta_table_; | 236 scoped_ptr<sql::MetaTable> meta_table_; |
| 237 std::map<int64, base::Time> lazy_last_access_times_; | 237 std::map<int64_t, base::Time> lazy_last_access_times_; |
| 238 bool is_disabled_; | 238 bool is_disabled_; |
| 239 bool is_recreating_; | 239 bool is_recreating_; |
| 240 bool was_corruption_detected_; | 240 bool was_corruption_detected_; |
| 241 | 241 |
| 242 friend class content::AppCacheDatabaseTest; | 242 friend class content::AppCacheDatabaseTest; |
| 243 friend class content::AppCacheStorageImplTest; | 243 friend class content::AppCacheStorageImplTest; |
| 244 | 244 |
| 245 FRIEND_TEST_ALL_PREFIXES(content::AppCacheDatabaseTest, CacheRecords); | 245 FRIEND_TEST_ALL_PREFIXES(content::AppCacheDatabaseTest, CacheRecords); |
| 246 FRIEND_TEST_ALL_PREFIXES(content::AppCacheDatabaseTest, EntryRecords); | 246 FRIEND_TEST_ALL_PREFIXES(content::AppCacheDatabaseTest, EntryRecords); |
| 247 FRIEND_TEST_ALL_PREFIXES(content::AppCacheDatabaseTest, QuickIntegrityCheck); | 247 FRIEND_TEST_ALL_PREFIXES(content::AppCacheDatabaseTest, QuickIntegrityCheck); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 260 FRIEND_TEST_ALL_PREFIXES(content::AppCacheDatabaseTest, UpgradeSchema4to7); | 260 FRIEND_TEST_ALL_PREFIXES(content::AppCacheDatabaseTest, UpgradeSchema4to7); |
| 261 FRIEND_TEST_ALL_PREFIXES(content::AppCacheDatabaseTest, UpgradeSchema5or6to7); | 261 FRIEND_TEST_ALL_PREFIXES(content::AppCacheDatabaseTest, UpgradeSchema5or6to7); |
| 262 FRIEND_TEST_ALL_PREFIXES(content::AppCacheDatabaseTest, WasCorrutionDetected); | 262 FRIEND_TEST_ALL_PREFIXES(content::AppCacheDatabaseTest, WasCorrutionDetected); |
| 263 | 263 |
| 264 DISALLOW_COPY_AND_ASSIGN(AppCacheDatabase); | 264 DISALLOW_COPY_AND_ASSIGN(AppCacheDatabase); |
| 265 }; | 265 }; |
| 266 | 266 |
| 267 } // namespace content | 267 } // namespace content |
| 268 | 268 |
| 269 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_DATABASE_H_ | 269 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_DATABASE_H_ |
| OLD | NEW |