diff options
author | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-13 20:57:50 +0000 |
---|---|---|
committer | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-13 20:57:50 +0000 |
commit | a84e7b5ec1cbdfe2d6943693d8bd71fcb6c64ce7 (patch) | |
tree | df6dbcf9a6bca8343355ffef01eeed49f6059b83 /webkit/appcache/appcache_database.cc | |
parent | 45699d6054f62173d0cd9df0f43af65047d76d79 (diff) | |
download | chromium_src-a84e7b5ec1cbdfe2d6943693d8bd71fcb6c64ce7.zip chromium_src-a84e7b5ec1cbdfe2d6943693d8bd71fcb6c64ce7.tar.gz chromium_src-a84e7b5ec1cbdfe2d6943693d8bd71fcb6c64ce7.tar.bz2 |
Trigger the deletion of unused responses when caches are updated and made obsolete (deleted).
BUG=none
TEST=not yet
Review URL: http://codereview.chromium.org/542021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36166 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_database.cc')
-rw-r--r-- | webkit/appcache/appcache_database.cc | 67 |
1 files changed, 53 insertions, 14 deletions
diff --git a/webkit/appcache/appcache_database.cc b/webkit/appcache/appcache_database.cc index ddfa34d..8b9da0a 100644 --- a/webkit/appcache/appcache_database.cc +++ b/webkit/appcache/appcache_database.cc @@ -94,6 +94,11 @@ const struct { "(cache_id, url)", true }, + { "EntriesResponseIdIndex", + kEntriesTable, + "(response_id)", + true }, + { "FallbackNameSpacesCacheIndex", kFallbackNameSpacesTable, "(cache_id)", @@ -179,26 +184,33 @@ bool AppCacheDatabase::FindLastStorageIds( const char* kMaxGroupIdSql = "SELECT MAX(group_id) FROM Groups"; const char* kMaxCacheIdSql = "SELECT MAX(cache_id) FROM Caches"; + const char* kMaxResponseIdFromEntriesSql = + "SELECT MAX(response_id) FROM Entries"; + const char* kMaxResponseIdFromDeletablesSql = + "SELECT MAX(response_id) FROM DeletableResponseIds"; const char* kMaxDeletableResponseRowIdSql = "SELECT MAX(rowid) FROM DeletableResponseIds"; - int64 group_id; - int64 cache_id; - int64 deletable_response_rowid; - if (!RunUniqueStatementWithInt64Result(kMaxGroupIdSql, &group_id) || - !RunUniqueStatementWithInt64Result(kMaxCacheIdSql, &cache_id) || + int64 max_group_id; + int64 max_cache_id; + int64 max_response_id_from_entries; + int64 max_response_id_from_deletables; + int64 max_deletable_response_rowid; + if (!RunUniqueStatementWithInt64Result(kMaxGroupIdSql, &max_group_id) || + !RunUniqueStatementWithInt64Result(kMaxCacheIdSql, &max_cache_id) || + !RunUniqueStatementWithInt64Result(kMaxResponseIdFromEntriesSql, + &max_response_id_from_entries) || + !RunUniqueStatementWithInt64Result(kMaxResponseIdFromDeletablesSql, + &max_response_id_from_deletables) || !RunUniqueStatementWithInt64Result(kMaxDeletableResponseRowIdSql, - &deletable_response_rowid)) { + &max_deletable_response_rowid)) { return false; } - // TODO(michaeln): SELECT MAX(responseId) FROM somewhere, - // or retrieve from the meta_table. - int64 response_id = 0; - - *last_group_id = group_id; - *last_cache_id = cache_id; - *last_response_id = response_id; - *last_deletable_response_rowid = deletable_response_rowid; + *last_group_id = max_group_id; + *last_cache_id = max_cache_id; + *last_response_id = std::max(max_response_id_from_entries, + max_response_id_from_deletables); + *last_deletable_response_rowid = max_deletable_response_rowid; return true; } @@ -812,6 +824,33 @@ bool AppCacheDatabase::PrepareCachedStatement( return true; } +bool AppCacheDatabase::FindResponseIdsForCacheHelper( + int64 cache_id, std::vector<int64>* ids_vector, + std::set<int64>* ids_set) { + DCHECK(ids_vector || ids_set); + DCHECK(!(ids_vector && ids_set)); + if (!LazyOpen(false)) + return false; + + const char* kSql = + "SELECT response_id FROM Entries WHERE cache_id = ?"; + + sql::Statement statement; + if (!PrepareCachedStatement(SQL_FROM_HERE, kSql, &statement)) + return false; + + statement.BindInt64(0, cache_id); + while (statement.Step()) { + int64 id = statement.ColumnInt64(0); + if (ids_set) + ids_set->insert(id); + else + ids_vector->push_back(id); + } + + return statement.Succeeded(); +} + void AppCacheDatabase::ReadGroupRecord( const sql::Statement& statement, GroupRecord* record) { record->group_id = statement.ColumnInt64(0); |