Chromium Code Reviews| Index: chrome/browser/memory_purger.cc |
| diff --git a/chrome/browser/memory_purger.cc b/chrome/browser/memory_purger.cc |
| index 98ab3011652cfb788548ee695897a33380e4e56a..6b22b6fa439e592182bb0b635d5e457919c50337 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_handler.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::MemoryPressureHandler::MemoryPressureType memory_pressure_type) { |
| + if (memory_pressure_type >= |
| + base::MemoryPressureHandler::MEMORY_PRESSURE_MODERATE) |
| + MemoryPurger::PurgeAll(); |
|
joth
2013/06/05 16:51:23
this seems completely wrong use of MemoryPurger::P
bulach
2013/06/05 19:02:11
should I separate this for the time being then?
joth
2013/06/05 19:28:58
Yes. Given pkasting's general skeptism about Memor
bulach
2013/06/06 09:28:30
sgtm.. removed this altogether from the latest pat
|
| +} |
| + |
| +struct LeakyLazyMemoryPressureListenerTraits { |
| + static const bool kRegisterOnExit = false; |
| + static const bool kAllowedToAccessOnNonjoinableThread = true; |
| + |
| + static base::MemoryPressureHandler::Listener* New(void* instance) { |
| + return new (instance) base::MemoryPressureHandler::Listener( |
| + base::Bind(&PurgeAllOnMemoryPressure)); |
| + } |
| + |
| + static void Delete(base::MemoryPressureHandler::Listener* instance) { |
| + } |
| +}; |
| + |
| +base::LazyInstance<base::MemoryPressureHandler::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()); |
| +} |