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

Unified Diff: components/discardable_memory/service/discardable_shared_memory_manager.cc

Issue 2667343004: Move purging memory from OnMemoryStateChange() to OnPurgeMemory() in discardable_memory (Closed)
Patch Set: comment Created 3 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 | « components/discardable_memory/service/discardable_shared_memory_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/discardable_memory/service/discardable_shared_memory_manager.cc
diff --git a/components/discardable_memory/service/discardable_shared_memory_manager.cc b/components/discardable_memory/service/discardable_shared_memory_manager.cc
index a974b2d9e27d8f35d1a59a9fcc7a5e8fdfc6e0e0..e2966c798c78bfafbc28f69e0d85095aa9f89582 100644
--- a/components/discardable_memory/service/discardable_shared_memory_manager.cc
+++ b/components/discardable_memory/service/discardable_shared_memory_manager.cc
@@ -405,12 +405,15 @@ size_t DiscardableSharedMemoryManager::GetBytesAllocated() {
void DiscardableSharedMemoryManager::OnMemoryStateChange(
base::MemoryState state) {
+ // Don't use SetMemoryLimit() as it frees up existing allocations.
+ // OnPurgeMemory() is called to actually free up memory.
+ base::AutoLock lock(lock_);
switch (state) {
case base::MemoryState::NORMAL:
- SetMemoryLimit(default_memory_limit_);
+ memory_limit_ = default_memory_limit_;
break;
case base::MemoryState::THROTTLED:
- SetMemoryLimit(0);
+ memory_limit_ = 0;
break;
case base::MemoryState::SUSPENDED:
// Note that SUSPENDED never occurs in the main browser process so far.
@@ -421,6 +424,11 @@ void DiscardableSharedMemoryManager::OnMemoryStateChange(
}
}
+void DiscardableSharedMemoryManager::OnPurgeMemory() {
+ base::AutoLock lock(lock_);
+ ReduceMemoryUsageUntilWithinLimit(0);
+}
+
void DiscardableSharedMemoryManager::AllocateLockedDiscardableSharedMemory(
int client_id,
size_t size,
« no previous file with comments | « components/discardable_memory/service/discardable_shared_memory_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698