Chromium Code Reviews| Index: content/browser/appcache/appcache_database.cc |
| diff --git a/content/browser/appcache/appcache_database.cc b/content/browser/appcache/appcache_database.cc |
| index 3e502813a1b73c32ce795cde8e23b0c37fc7be7f..c8ed34cbf56428d5a6e13c142a0228b4a0bf0b7a 100644 |
| --- a/content/browser/appcache/appcache_database.cc |
| +++ b/content/browser/appcache/appcache_database.cc |
| @@ -210,6 +210,7 @@ AppCacheDatabase::AppCacheDatabase(const base::FilePath& path) |
| } |
| AppCacheDatabase::~AppCacheDatabase() { |
| + CommitLazyLastAccessTimes(); |
| } |
| void AppCacheDatabase::Disable() { |
| @@ -392,7 +393,7 @@ bool AppCacheDatabase::FindGroupForCache(int64 cache_id, GroupRecord* record) { |
| return true; |
| } |
| -bool AppCacheDatabase::UpdateGroupLastAccessTime( |
| +bool AppCacheDatabase::UpdateLastAccessTime( |
| int64 group_id, base::Time time) { |
| if (!LazyOpen(true)) |
| return false; |
| @@ -404,7 +405,35 @@ bool AppCacheDatabase::UpdateGroupLastAccessTime( |
| statement.BindInt64(0, time.ToInternalValue()); |
| statement.BindInt64(1, group_id); |
| - return statement.Run() && db_->GetLastChangeCount(); |
| + return statement.Run(); |
| +} |
| + |
| +bool AppCacheDatabase::LazyUpdateLastAccessTime( |
| + int64 group_id, base::Time time) { |
| + if (!LazyOpen(true)) |
| + return false; |
| + lazy_last_access_times_[group_id] = time; |
| + return true; |
| +} |
| + |
| +bool AppCacheDatabase::CommitLazyLastAccessTimes() { |
| + if (lazy_last_access_times_.empty()) |
| + return true; |
| + if (!LazyOpen(false)) |
| + return false; |
| + |
| + sql::Transaction transaction(db_.get()); |
| + if (!transaction.Begin()) |
| + return false; |
| + for (const auto& pair : lazy_last_access_times_) { |
| + if (!UpdateLastAccessTime(pair.first, pair.second)) |
| + return false; |
| + } |
| + if (!transaction.Commit()) |
|
cmumford
2015/02/13 23:06:15
If we fail to update or commit the last access tim
michaeln
2015/02/14 01:35:03
Done, the method easier to read now too.
|
| + return false; |
| + |
| + lazy_last_access_times_.clear(); |
| + return true; |
| } |
| bool AppCacheDatabase::InsertGroup(const GroupRecord* record) { |
| @@ -924,8 +953,14 @@ void AppCacheDatabase::ReadGroupRecord( |
| record->manifest_url = GURL(statement.ColumnString(2)); |
| record->creation_time = |
| base::Time::FromInternalValue(statement.ColumnInt64(3)); |
| - record->last_access_time = |
| - base::Time::FromInternalValue(statement.ColumnInt64(4)); |
| + |
| + const auto found = lazy_last_access_times_.find(record->group_id); |
| + if (found != lazy_last_access_times_.end()) { |
| + record->last_access_time = found->second; |
| + } else { |
| + record->last_access_time = |
| + base::Time::FromInternalValue(statement.ColumnInt64(4)); |
| + } |
| } |
| void AppCacheDatabase::ReadCacheRecord( |