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

Unified Diff: base/memory/discardable_memory_provider.cc

Issue 111713008: base: Refactor DiscardableMemoryProvider to build and be tested on all platforms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix native_discardable_memory on ios. Created 7 years 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: base/memory/discardable_memory_provider.cc
diff --git a/base/memory/discardable_memory_provider.cc b/base/memory/discardable_memory_provider.cc
index f7511a1a07e350af3af3a6a0462bd326d3721afe..1c84339eba7aea5877446f893a94a019c2605def 100644
--- a/base/memory/discardable_memory_provider.cc
+++ b/base/memory/discardable_memory_provider.cc
@@ -8,8 +8,6 @@
#include "base/containers/hash_tables.h"
#include "base/containers/mru_cache.h"
#include "base/debug/trace_event.h"
-#include "base/lazy_instance.h"
-#include "base/memory/discardable_memory.h"
#include "base/synchronization/lock.h"
#include "base/sys_info.h"
@@ -18,13 +16,6 @@ namespace internal {
namespace {
-static base::LazyInstance<DiscardableMemoryProvider>::Leaky g_provider =
- LAZY_INSTANCE_INITIALIZER;
-
-// If this is given a valid value via SetInstanceForTest, this pointer will be
-// returned by GetInstance rather than |g_provider|.
-static DiscardableMemoryProvider* g_provider_for_test = NULL;
-
// This is admittedly pretty magical. It's approximately enough memory for two
// 2560x1600 images.
static const size_t kDefaultDiscardableMemoryLimit = 32 * 1024 * 1024;
@@ -40,7 +31,8 @@ DiscardableMemoryProvider::DiscardableMemoryProvider()
bytes_to_reclaim_under_moderate_pressure_(
kDefaultBytesToReclaimUnderModeratePressure),
memory_pressure_listener_(
- base::Bind(&DiscardableMemoryProvider::NotifyMemoryPressure)) {
+ base::Bind(&DiscardableMemoryProvider::NotifyMemoryPressure,
+ Unretained(this))) {
}
DiscardableMemoryProvider::~DiscardableMemoryProvider() {
@@ -48,28 +40,14 @@ DiscardableMemoryProvider::~DiscardableMemoryProvider() {
DCHECK_EQ(0u, bytes_allocated_);
}
-// static
-DiscardableMemoryProvider* DiscardableMemoryProvider::GetInstance() {
- if (g_provider_for_test)
- return g_provider_for_test;
- return g_provider.Pointer();
-}
-
-// static
-void DiscardableMemoryProvider::SetInstanceForTest(
- DiscardableMemoryProvider* provider) {
- g_provider_for_test = provider;
-}
-
-// static
void DiscardableMemoryProvider::NotifyMemoryPressure(
MemoryPressureListener::MemoryPressureLevel pressure_level) {
switch (pressure_level) {
case MemoryPressureListener::MEMORY_PRESSURE_MODERATE:
- DiscardableMemoryProvider::GetInstance()->Purge();
+ Purge();
return;
case MemoryPressureListener::MEMORY_PRESSURE_CRITICAL:
- DiscardableMemoryProvider::GetInstance()->PurgeAll();
+ PurgeAll();
return;
}

Powered by Google App Engine
This is Rietveld 408576698