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

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: Address Primiano's comments 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..6b21be32550385315e9ea0b7d00ae924037c6a44 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"
@@ -51,7 +50,7 @@ void MemoryPressureController::SetPressureNotificationsSuppressedInAllProcesses(
bool suppressed) {
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).
+ // controller is a leaky singleton.
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&MemoryPressureController::
@@ -64,10 +63,31 @@ void MemoryPressureController::SetPressureNotificationsSuppressedInAllProcesses(
base::MemoryPressureListener::SetNotificationsSuppressed(suppressed);
// Enable/disable suppressing memory notifications in all child processes.
- for (MemoryMessageFilterSet::iterator it = memory_message_filters_.begin();
- it != memory_message_filters_.end(); ++it) {
- it->get()->SendSetPressureNotificationsSuppressed(suppressed);
+ for (const scoped_refptr<MemoryMessageFilter>& mf : memory_message_filters_)
nasko 2015/09/30 16:44:58 nit: s/mf/filter/
petrcermak 2015/09/30 18:18:36 Done.
+ mf->SendSetPressureNotificationsSuppressed(suppressed);
+}
+
+void MemoryPressureController::SimulatePressureNotificationInAllProcesses(
+ base::MemoryPressureListener::MemoryPressureLevel level) {
+ DCHECK_NE(level, base::MemoryPressureListener::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.
+ 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 (const scoped_refptr<MemoryMessageFilter>& mf : memory_message_filters_)
nasko 2015/09/30 16:44:58 nit: s/mf/filter/
petrcermak 2015/09/30 18:18:36 Done.
+ mf->SendSimulatePressureNotification(level);
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698