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

Unified Diff: components/history/core/browser/history_database.cc

Issue 2297243004: [WIP] histroy: Adjust cache size OnMemoryStateChange() (Closed)
Patch Set: Created 4 years, 3 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
Index: components/history/core/browser/history_database.cc
diff --git a/components/history/core/browser/history_database.cc b/components/history/core/browser/history_database.cc
index 260f0578f4dd3c88c251afa021cb29852df38efb..2a383b8b2579cf6096bb5756b9e7e22aafc681b2 100644
--- a/components/history/core/browser/history_database.cc
+++ b/components/history/core/browser/history_database.cc
@@ -40,6 +40,7 @@ const int kCurrentVersionNumber = 32;
const int kCompatibleVersionNumber = 16;
const char kEarlyExpirationThresholdKey[] = "early_expiration_threshold";
const int kMaxHostsInMemory = 10000;
+const int kDefaultCacheSize = 1000;
} // namespace
@@ -66,7 +67,7 @@ sql::InitStatus HistoryDatabase::Init(const base::FilePath& history_name) {
// value, tells us how much memory the cache will use maximum.
// 1000 * 4kB = 4MB
// TODO(brettw) scale this value to the amount of available memory.
- db_.set_cache_size(1000);
+ db_.set_cache_size(kDefaultCacheSize);
// Note that we don't set exclusive locking here. That's done by
// BeginExclusiveMode below which is called later (we have to be in shared
@@ -295,6 +296,16 @@ void HistoryDatabase::TrimMemory(bool aggressively) {
db_.TrimMemory(aggressively);
}
+void HistoryDatabase::AdjustCacheMemory(memory_coordinator::MemoryState state) {
+ int cache_size = kDefaultCacheSize;
+ if (state == memory_coordinator::MemoryState::THROTTLED) {
+ cache_size = cache_size / 2;
+ } else if (state == memory_coordinator::MemoryState::SUSPENDED) {
+ cache_size = cache_size / 4;
+ }
+ db_.UpdateCacheSize(cache_size);
+}
+
bool HistoryDatabase::Raze() {
return db_.Raze();
}

Powered by Google App Engine
This is Rietveld 408576698