| OLD | NEW |
| 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 #ifndef WEBKIT_APPCACHE_APPCACHE_DATABASE_H_ | 5 #ifndef WEBKIT_APPCACHE_APPCACHE_DATABASE_H_ |
| 6 #define WEBKIT_APPCACHE_APPCACHE_DATABASE_H_ | 6 #define WEBKIT_APPCACHE_APPCACHE_DATABASE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 18 #include "webkit/appcache/appcache_export.h" | 18 #include "webkit/appcache/appcache_export.h" |
| 19 #include "webkit/appcache/appcache_interfaces.h" |
| 19 | 20 |
| 20 namespace sql { | 21 namespace sql { |
| 21 class Connection; | 22 class Connection; |
| 22 class MetaTable; | 23 class MetaTable; |
| 23 class Statement; | 24 class Statement; |
| 24 class StatementID; | 25 class StatementID; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace appcache { | 28 namespace appcache { |
| 28 | 29 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 53 struct EntryRecord { | 54 struct EntryRecord { |
| 54 EntryRecord() : cache_id(0), flags(0), response_id(0), response_size(0) {} | 55 EntryRecord() : cache_id(0), flags(0), response_id(0), response_size(0) {} |
| 55 | 56 |
| 56 int64 cache_id; | 57 int64 cache_id; |
| 57 GURL url; | 58 GURL url; |
| 58 int flags; | 59 int flags; |
| 59 int64 response_id; | 60 int64 response_id; |
| 60 int64 response_size; | 61 int64 response_size; |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 struct APPCACHE_EXPORT FallbackNameSpaceRecord { | 64 struct APPCACHE_EXPORT NamespaceRecord { |
| 64 FallbackNameSpaceRecord(); | 65 NamespaceRecord(); |
| 65 ~FallbackNameSpaceRecord(); | 66 ~NamespaceRecord(); |
| 66 | 67 |
| 67 int64 cache_id; | 68 int64 cache_id; |
| 68 GURL origin; // intentionally not normalized | 69 GURL origin; |
| 70 NamespaceType type; |
| 69 GURL namespace_url; | 71 GURL namespace_url; |
| 70 GURL fallback_entry_url; | 72 GURL target_url; |
| 71 }; | 73 }; |
| 72 | 74 |
| 75 typedef std::vector<NamespaceRecord> NamespaceRecordVector; |
| 76 |
| 73 struct OnlineWhiteListRecord { | 77 struct OnlineWhiteListRecord { |
| 74 OnlineWhiteListRecord() : cache_id(0) {} | 78 OnlineWhiteListRecord() : cache_id(0) {} |
| 75 | 79 |
| 76 int64 cache_id; | 80 int64 cache_id; |
| 77 GURL namespace_url; | 81 GURL namespace_url; |
| 78 }; | 82 }; |
| 79 | 83 |
| 80 explicit AppCacheDatabase(const FilePath& path); | 84 explicit AppCacheDatabase(const FilePath& path); |
| 81 ~AppCacheDatabase(); | 85 ~AppCacheDatabase(); |
| 82 | 86 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 int additional_flags); | 126 int additional_flags); |
| 123 bool FindResponseIdsForCacheAsVector( | 127 bool FindResponseIdsForCacheAsVector( |
| 124 int64 cache_id, std::vector<int64>* response_ids) { | 128 int64 cache_id, std::vector<int64>* response_ids) { |
| 125 return FindResponseIdsForCacheHelper(cache_id, response_ids, NULL); | 129 return FindResponseIdsForCacheHelper(cache_id, response_ids, NULL); |
| 126 } | 130 } |
| 127 bool FindResponseIdsForCacheAsSet( | 131 bool FindResponseIdsForCacheAsSet( |
| 128 int64 cache_id, std::set<int64>* response_ids) { | 132 int64 cache_id, std::set<int64>* response_ids) { |
| 129 return FindResponseIdsForCacheHelper(cache_id, NULL, response_ids); | 133 return FindResponseIdsForCacheHelper(cache_id, NULL, response_ids); |
| 130 } | 134 } |
| 131 | 135 |
| 132 bool FindFallbackNameSpacesForOrigin( | 136 bool FindNamespacesForOrigin( |
| 133 const GURL& origin, std::vector<FallbackNameSpaceRecord>* records); | 137 const GURL& origin, |
| 134 bool FindFallbackNameSpacesForCache( | 138 NamespaceRecordVector* intercepts, |
| 135 int64 cache_id, std::vector<FallbackNameSpaceRecord>* records); | 139 NamespaceRecordVector* fallbacks); |
| 136 bool InsertFallbackNameSpace(const FallbackNameSpaceRecord* record); | 140 bool FindNamespacesForCache( |
| 137 bool InsertFallbackNameSpaceRecords( | 141 int64 cache_id, |
| 138 const std::vector<FallbackNameSpaceRecord>& records); | 142 NamespaceRecordVector* intercepts, |
| 139 bool DeleteFallbackNameSpacesForCache(int64 cache_id); | 143 std::vector<NamespaceRecord>* fallbacks); |
| 144 bool InsertNamespaceRecords( |
| 145 const NamespaceRecordVector& records); |
| 146 bool InsertNamespace(const NamespaceRecord* record); |
| 147 bool DeleteNamespacesForCache(int64 cache_id); |
| 140 | 148 |
| 141 bool FindOnlineWhiteListForCache( | 149 bool FindOnlineWhiteListForCache( |
| 142 int64 cache_id, std::vector<OnlineWhiteListRecord>* records); | 150 int64 cache_id, std::vector<OnlineWhiteListRecord>* records); |
| 143 bool InsertOnlineWhiteList(const OnlineWhiteListRecord* record); | 151 bool InsertOnlineWhiteList(const OnlineWhiteListRecord* record); |
| 144 bool InsertOnlineWhiteListRecords( | 152 bool InsertOnlineWhiteListRecords( |
| 145 const std::vector<OnlineWhiteListRecord>& records); | 153 const std::vector<OnlineWhiteListRecord>& records); |
| 146 bool DeleteOnlineWhiteListForCache(int64 cache_id); | 154 bool DeleteOnlineWhiteListForCache(int64 cache_id); |
| 147 | 155 |
| 148 bool GetDeletableResponseIds(std::vector<int64>* response_ids, | 156 bool GetDeletableResponseIds(std::vector<int64>* response_ids, |
| 149 int64 max_rowid, int limit); | 157 int64 max_rowid, int limit); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 167 const sql::StatementID& id, const char* sql, sql::Statement* statement); | 175 const sql::StatementID& id, const char* sql, sql::Statement* statement); |
| 168 | 176 |
| 169 bool FindResponseIdsForCacheHelper( | 177 bool FindResponseIdsForCacheHelper( |
| 170 int64 cache_id, std::vector<int64>* ids_vector, | 178 int64 cache_id, std::vector<int64>* ids_vector, |
| 171 std::set<int64>* ids_set); | 179 std::set<int64>* ids_set); |
| 172 | 180 |
| 173 // Record retrieval helpers | 181 // Record retrieval helpers |
| 174 void ReadGroupRecord(const sql::Statement& statement, GroupRecord* record); | 182 void ReadGroupRecord(const sql::Statement& statement, GroupRecord* record); |
| 175 void ReadCacheRecord(const sql::Statement& statement, CacheRecord* record); | 183 void ReadCacheRecord(const sql::Statement& statement, CacheRecord* record); |
| 176 void ReadEntryRecord(const sql::Statement& statement, EntryRecord* record); | 184 void ReadEntryRecord(const sql::Statement& statement, EntryRecord* record); |
| 177 void ReadFallbackNameSpaceRecord( | 185 void ReadNamespaceRecords( |
| 178 const sql::Statement& statement, FallbackNameSpaceRecord* record); | 186 sql::Statement* statement, |
| 187 NamespaceRecordVector* intercepts, |
| 188 NamespaceRecordVector* fallbacks); |
| 189 void ReadNamespaceRecord( |
| 190 const sql::Statement* statement, NamespaceRecord* record); |
| 179 void ReadOnlineWhiteListRecord( | 191 void ReadOnlineWhiteListRecord( |
| 180 const sql::Statement& statement, OnlineWhiteListRecord* record); | 192 const sql::Statement& statement, OnlineWhiteListRecord* record); |
| 181 | 193 |
| 182 // Database creation | 194 // Database creation |
| 183 bool LazyOpen(bool create_if_needed); | 195 bool LazyOpen(bool create_if_needed); |
| 184 bool EnsureDatabaseVersion(); | 196 bool EnsureDatabaseVersion(); |
| 185 bool CreateSchema(); | 197 bool CreateSchema(); |
| 186 bool UpgradeSchema(); | 198 bool UpgradeSchema(); |
| 187 | 199 |
| 188 void ResetConnectionAndTables(); | 200 void ResetConnectionAndTables(); |
| 189 | 201 |
| 190 // Deletes the existing database file and the entire directory containing | 202 // Deletes the existing database file and the entire directory containing |
| 191 // the database file including the disk cache in which response headers | 203 // the database file including the disk cache in which response headers |
| 192 // and bodies are stored, and then creates a new database file. | 204 // and bodies are stored, and then creates a new database file. |
| 193 bool DeleteExistingAndCreateNewDatabase(); | 205 bool DeleteExistingAndCreateNewDatabase(); |
| 194 | 206 |
| 195 FilePath db_file_path_; | 207 FilePath db_file_path_; |
| 196 scoped_ptr<sql::Connection> db_; | 208 scoped_ptr<sql::Connection> db_; |
| 197 scoped_ptr<sql::MetaTable> meta_table_; | 209 scoped_ptr<sql::MetaTable> meta_table_; |
| 198 bool is_disabled_; | 210 bool is_disabled_; |
| 199 bool is_recreating_; | 211 bool is_recreating_; |
| 200 | 212 |
| 201 FRIEND_TEST_ALL_PREFIXES(AppCacheDatabaseTest, CacheRecords); | 213 FRIEND_TEST_ALL_PREFIXES(AppCacheDatabaseTest, CacheRecords); |
| 202 FRIEND_TEST_ALL_PREFIXES(AppCacheDatabaseTest, EntryRecords); | 214 FRIEND_TEST_ALL_PREFIXES(AppCacheDatabaseTest, EntryRecords); |
| 203 FRIEND_TEST_ALL_PREFIXES(AppCacheDatabaseTest, FallbackNameSpaceRecords); | 215 FRIEND_TEST_ALL_PREFIXES(AppCacheDatabaseTest, NamespaceRecords); |
| 204 FRIEND_TEST_ALL_PREFIXES(AppCacheDatabaseTest, GroupRecords); | 216 FRIEND_TEST_ALL_PREFIXES(AppCacheDatabaseTest, GroupRecords); |
| 205 FRIEND_TEST_ALL_PREFIXES(AppCacheDatabaseTest, LazyOpen); | 217 FRIEND_TEST_ALL_PREFIXES(AppCacheDatabaseTest, LazyOpen); |
| 206 FRIEND_TEST_ALL_PREFIXES(AppCacheDatabaseTest, OnlineWhiteListRecords); | 218 FRIEND_TEST_ALL_PREFIXES(AppCacheDatabaseTest, OnlineWhiteListRecords); |
| 207 FRIEND_TEST_ALL_PREFIXES(AppCacheDatabaseTest, ReCreate); | 219 FRIEND_TEST_ALL_PREFIXES(AppCacheDatabaseTest, ReCreate); |
| 208 FRIEND_TEST_ALL_PREFIXES(AppCacheDatabaseTest, DeletableResponseIds); | 220 FRIEND_TEST_ALL_PREFIXES(AppCacheDatabaseTest, DeletableResponseIds); |
| 209 FRIEND_TEST_ALL_PREFIXES(AppCacheDatabaseTest, OriginUsage); | 221 FRIEND_TEST_ALL_PREFIXES(AppCacheDatabaseTest, OriginUsage); |
| 222 FRIEND_TEST_ALL_PREFIXES(AppCacheDatabaseTest, UpgradeSchema3to4); |
| 210 | 223 |
| 211 DISALLOW_COPY_AND_ASSIGN(AppCacheDatabase); | 224 DISALLOW_COPY_AND_ASSIGN(AppCacheDatabase); |
| 212 }; | 225 }; |
| 213 | 226 |
| 214 } // namespace appcache | 227 } // namespace appcache |
| 215 | 228 |
| 216 #endif // WEBKIT_APPCACHE_APPCACHE_DATABASE_H_ | 229 #endif // WEBKIT_APPCACHE_APPCACHE_DATABASE_H_ |
| OLD | NEW |