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

Unified Diff: base/memory/discardable_memory_manager.cc

Issue 448173002: Re-land: base: Introduce an explicit call for reducing emulated discardable memory usage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: disable EmulatedDiscardableMemoryDiscardedWhenWidgetsHidden with lsan Created 6 years, 4 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 | « base/memory/discardable_memory_manager.h ('k') | base/memory/discardable_memory_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/discardable_memory_manager.cc
diff --git a/base/memory/discardable_memory_manager.cc b/base/memory/discardable_memory_manager.cc
index d976da203c4a88494dfffa6e73dd167bee6c2c11..3647b7b2f91a682d2805c2752a981ad771f99e40 100644
--- a/base/memory/discardable_memory_manager.cc
+++ b/base/memory/discardable_memory_manager.cc
@@ -18,14 +18,11 @@ namespace internal {
DiscardableMemoryManager::DiscardableMemoryManager(
size_t memory_limit,
size_t soft_memory_limit,
- size_t bytes_to_keep_under_moderate_pressure,
TimeDelta hard_memory_limit_expiration_time)
: allocations_(AllocationMap::NO_AUTO_EVICT),
bytes_allocated_(0u),
memory_limit_(memory_limit),
soft_memory_limit_(soft_memory_limit),
- bytes_to_keep_under_moderate_pressure_(
- bytes_to_keep_under_moderate_pressure),
hard_memory_limit_expiration_time_(hard_memory_limit_expiration_time) {
BytesAllocatedChanged(bytes_allocated_);
}
@@ -35,20 +32,6 @@ DiscardableMemoryManager::~DiscardableMemoryManager() {
DCHECK_EQ(0u, bytes_allocated_);
}
-void DiscardableMemoryManager::RegisterMemoryPressureListener() {
- AutoLock lock(lock_);
- DCHECK(base::MessageLoop::current());
- DCHECK(!memory_pressure_listener_);
- memory_pressure_listener_.reset(new MemoryPressureListener(base::Bind(
- &DiscardableMemoryManager::OnMemoryPressure, Unretained(this))));
-}
-
-void DiscardableMemoryManager::UnregisterMemoryPressureListener() {
- AutoLock lock(lock_);
- DCHECK(memory_pressure_listener_);
- memory_pressure_listener_.reset();
-}
-
void DiscardableMemoryManager::SetMemoryLimit(size_t bytes) {
AutoLock lock(lock_);
memory_limit_ = bytes;
@@ -61,12 +44,6 @@ void DiscardableMemoryManager::SetSoftMemoryLimit(size_t bytes) {
soft_memory_limit_ = bytes;
}
-void DiscardableMemoryManager::SetBytesToKeepUnderModeratePressure(
- size_t bytes) {
- AutoLock lock(lock_);
- bytes_to_keep_under_moderate_pressure_ = bytes;
-}
-
void DiscardableMemoryManager::SetHardMemoryLimitExpirationTime(
TimeDelta hard_memory_limit_expiration_time) {
AutoLock lock(lock_);
@@ -77,13 +54,14 @@ bool DiscardableMemoryManager::ReduceMemoryUsage() {
return PurgeIfNotUsedSinceHardLimitCutoffUntilWithinSoftMemoryLimit();
}
+void DiscardableMemoryManager::ReduceMemoryUsageUntilWithinLimit(size_t bytes) {
+ AutoLock lock(lock_);
+ PurgeIfNotUsedSinceTimestampUntilUsageIsWithinLimitWithLockAcquired(Now(),
+ bytes);
+}
+
void DiscardableMemoryManager::Register(Allocation* allocation, size_t bytes) {
AutoLock lock(lock_);
- // A registered memory listener is currently required. This DCHECK can be
- // moved or removed if we decide that it's useful to relax this condition.
- // TODO(reveman): Enable this DCHECK when skia and blink are able to
- // register memory pressure listeners. crbug.com/333907
- // DCHECK(memory_pressure_listener_);
DCHECK(allocations_.Peek(allocation) == allocations_.end());
allocations_.Put(allocation, AllocationInfo(bytes));
}
@@ -182,28 +160,6 @@ size_t DiscardableMemoryManager::GetBytesAllocatedForTest() const {
return bytes_allocated_;
}
-void DiscardableMemoryManager::OnMemoryPressure(
- MemoryPressureListener::MemoryPressureLevel pressure_level) {
- switch (pressure_level) {
- case MemoryPressureListener::MEMORY_PRESSURE_MODERATE:
- PurgeUntilWithinBytesToKeepUnderModeratePressure();
- return;
- case MemoryPressureListener::MEMORY_PRESSURE_CRITICAL:
- PurgeAll();
- return;
- }
-
- NOTREACHED();
-}
-
-void
-DiscardableMemoryManager::PurgeUntilWithinBytesToKeepUnderModeratePressure() {
- AutoLock lock(lock_);
-
- PurgeIfNotUsedSinceTimestampUntilUsageIsWithinLimitWithLockAcquired(
- Now(), bytes_to_keep_under_moderate_pressure_);
-}
-
bool DiscardableMemoryManager::
PurgeIfNotUsedSinceHardLimitCutoffUntilWithinSoftMemoryLimit() {
AutoLock lock(lock_);
« no previous file with comments | « base/memory/discardable_memory_manager.h ('k') | base/memory/discardable_memory_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698