Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Unified Diff: content/browser/appcache/appcache_database.cc

Issue 924723002: [appcache] Don't write during startup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/appcache/appcache_database.h ('k') | content/browser/appcache/appcache_storage_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..985173be166b49be5017b5ad8e6478488b5307bf 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,30 @@ 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_)
+ UpdateLastAccessTime(pair.first, pair.second);
+ lazy_last_access_times_.clear();
+ return transaction.Commit();
}
bool AppCacheDatabase::InsertGroup(const GroupRecord* record) {
@@ -924,8 +948,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(
« no previous file with comments | « content/browser/appcache/appcache_database.h ('k') | content/browser/appcache/appcache_storage_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698