Index: content/renderer/render_thread_impl.cc |
diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc |
index 37fa09009169697a343cce73cfb9779f66e49937..daff6bc8dad3e7622981b6244ebe279ee38a3540 100644 |
--- a/content/renderer/render_thread_impl.cc |
+++ b/content/renderer/render_thread_impl.cc |
@@ -15,6 +15,7 @@ |
#include "base/lazy_instance.h" |
#include "base/logging.h" |
#include "base/memory/discardable_memory.h" |
+#include "base/memory/discardable_memory_emulated.h" |
#include "base/memory/shared_memory.h" |
#include "base/metrics/field_trial.h" |
#include "base/metrics/histogram.h" |
@@ -179,6 +180,9 @@ const int kMaxRasterThreads = 64; |
// allocation that exceeds this limit. |
const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024; |
+const size_t kEmulatedDiscardableMemoryBytesToKeepWhenWidgetsHidden = |
+ 4 * 1024 * 1024; |
+ |
// Keep the global RenderThreadImpl in a TLS slot so it is impossible to access |
// incorrectly from the wrong thread. |
base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> > |
@@ -545,10 +549,6 @@ void RenderThreadImpl::Init() { |
base::DiscardableMemory::SetPreferredType(type); |
- // Allow discardable memory implementations to register memory pressure |
- // listeners. |
- base::DiscardableMemory::RegisterMemoryPressureListeners(); |
- |
// AllocateGpuMemoryBuffer must be used exclusively on one thread but |
// it doesn't have to be the same thread RenderThreadImpl is created on. |
allocate_gpu_memory_buffer_thread_checker_.DetachFromThread(); |
@@ -1623,6 +1623,12 @@ void RenderThreadImpl::WidgetHidden() { |
hidden_widget_count_++; |
if (widget_count_ && hidden_widget_count_ == widget_count_) { |
+ // TODO(reveman): Remove this when we have a better mechanism to prevent |
+ // total discardable memory used by all renderers from growing too large. |
+ base::internal::DiscardableMemoryEmulated:: |
+ ReduceMemoryUsageUntilWithinLimit( |
+ kEmulatedDiscardableMemoryBytesToKeepWhenWidgetsHidden); |
+ |
if (GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) |
ScheduleIdleHandler(kInitialIdleHandlerDelayMs); |
} |