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

Unified Diff: content/browser/memory/memory_pressure_controller.cc

Issue 1362233003: Add architecture for simulating memory pressure notifications in all processes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
Index: content/browser/memory/memory_pressure_controller.cc
diff --git a/content/browser/memory/memory_pressure_controller.cc b/content/browser/memory/memory_pressure_controller.cc
index 41738e5206a8e26f2629d131dda05d3bdd63f492..a93302c312d2819d3bd038b8dda7ac3232256f0a 100644
--- a/content/browser/memory/memory_pressure_controller.cc
+++ b/content/browser/memory/memory_pressure_controller.cc
@@ -5,7 +5,6 @@
#include "content/browser/memory/memory_pressure_controller.h"
#include "base/bind.h"
-#include "base/memory/memory_pressure_listener.h"
#include "content/browser/memory/memory_message_filter.h"
#include "content/public/browser/browser_thread.h"
@@ -70,4 +69,29 @@ void MemoryPressureController::SetPressureNotificationsSuppressedInAllProcesses(
}
}
+void MemoryPressureController::SimulatePressureNotificationInAllProcesses(
+ MemoryPressureLevel level) {
+ DCHECK_NE(level, MemoryPressureLevel::MEMORY_PRESSURE_LEVEL_NONE);
+
+ if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
+ // Note that passing base::Unretained(this) is safe here because the
+ // controller is a leaky singleton (i.e. it is never deleted).
Primiano Tucci (use gerrit) 2015/09/28 12:47:31 the i.e. part in parenthesis is really superfluos
petrcermak 2015/09/28 15:39:32 Done (removed in both methods).
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&MemoryPressureController::
+ SimulatePressureNotificationInAllProcesses,
+ base::Unretained(this), level));
+ return;
+ }
+
+ // Simulate memory pressure notification in the browser process.
+ base::MemoryPressureListener::SimulatePressureNotification(level);
+
+ // Simulate memory pressure notification in all child processes.
+ for (MemoryMessageFilterSet::iterator it = memory_message_filters_.begin();
Primiano Tucci (use gerrit) 2015/09/28 12:47:31 you could use a one-line C++11 style foreach here
petrcermak 2015/09/28 15:39:32 Done (in both methods).
+ it != memory_message_filters_.end(); ++it) {
+ it->get()->SendSimulatePressureNotification(level);
Primiano Tucci (use gerrit) 2015/09/28 12:47:32 ..and that will avoid you to use the ->get() What
petrcermak 2015/09/28 15:39:32 Done.
+ }
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698