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

Unified Diff: chrome/browser/memory_purger.cc

Issue 15995014: Adds MemoryPressureListener. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Joth's comments Created 7 years, 6 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
« base/memory/memory_pressure_notifier.h ('K') | « chrome/browser/memory_purger.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
+}
« base/memory/memory_pressure_notifier.h ('K') | « chrome/browser/memory_purger.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698