| Index: chrome/browser/memory_purger.cc
|
| diff --git a/chrome/browser/memory_purger.cc b/chrome/browser/memory_purger.cc
|
| index 98ab3011652cfb788548ee695897a33380e4e56a..0055ab3afcf4aea4f805acd4f767e83b56aadb22 100644
|
| --- a/chrome/browser/memory_purger.cc
|
| +++ b/chrome/browser/memory_purger.cc
|
| @@ -8,6 +8,8 @@
|
|
|
| #include "base/allocator/allocator_extension.h"
|
| #include "base/bind.h"
|
| +#include "base/lazy_instance.h"
|
| +#include "base/memory/memory_pressure_notifier.h"
|
| #include "base/threading/thread.h"
|
| #include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/history/history_service.h"
|
| @@ -31,6 +33,8 @@ using content::BrowserContext;
|
| using content::BrowserThread;
|
| using content::ResourceContext;
|
|
|
| +namespace {
|
| +
|
| // PurgeMemoryHelper -----------------------------------------------------------
|
|
|
| // This is a small helper class used to ensure that the objects we want to use
|
| @@ -79,6 +83,32 @@ void PurgeMemoryIOHelper::PurgeMemoryOnIOThread() {
|
| #endif
|
| }
|
|
|
| +void PurgeAllOnMemoryPressure(
|
| + base::MemoryPressureNotifier::MemoryPressureType memory_pressure_type) {
|
| + if (memory_pressure_type ==
|
| + base::MemoryPressureNotifier::MEMORY_PRESSURE_CRITICAL)
|
| + MemoryPurger::PurgeAll();
|
| +}
|
| +
|
| +struct LeakyLazyMemoryPressureListenerTraits {
|
| + static const bool kRegisterOnExit = false;
|
| + static const bool kAllowedToAccessOnNonjoinableThread = true;
|
| +
|
| + static base::MemoryPressureNotifier::Listener* New(void* instance) {
|
| + return new (instance) base::MemoryPressureNotifier::Listener(
|
| + base::Bind(&PurgeAllOnMemoryPressure));
|
| + }
|
| +
|
| + static void Delete(base::MemoryPressureNotifier::Listener* instance) {
|
| + }
|
| +};
|
| +
|
| +base::LazyInstance<base::MemoryPressureNotifier::Listener,
|
| + LeakyLazyMemoryPressureListenerTraits>
|
| + g_memory_pressure_listener = LAZY_INSTANCE_INITIALIZER;
|
| +
|
| +} // namespace
|
| +
|
| // -----------------------------------------------------------------------------
|
|
|
| // static
|
| @@ -161,3 +191,8 @@ void MemoryPurger::PurgeRendererForHost(content::RenderProcessHost* host) {
|
| // Direct the renderer to free everything it can.
|
| host->Send(new ChromeViewMsg_PurgeMemory());
|
| }
|
| +
|
| +// static
|
| +void MemoryPurger::RegisterMemoryPressureListener() {
|
| + CHECK(g_memory_pressure_listener.Pointer());
|
| +}
|
|
|