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

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

Issue 1332583002: Architecture for cross-process memory notification suppressing (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_message_filter.cc
diff --git a/content/browser/memory/memory_message_filter.cc b/content/browser/memory/memory_message_filter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..278e85392767c3183fbf7d3f525e9a2869b289ee
--- /dev/null
+++ b/content/browser/memory/memory_message_filter.cc
@@ -0,0 +1,79 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/memory/memory_message_filter.h"
+
+#include "base/bind.h"
+#include "base/memory/memory_pressure_listener.h"
+#include "content/common/memory_messages.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace content {
+namespace memory {
+
+MemoryMessageFilter::MemoryMessageFilter()
+ : BrowserMessageFilter(MemoryMsgStart) {}
+
+MemoryMessageFilter::~MemoryMessageFilter() {}
+
+void MemoryMessageFilter::OnFilterAdded(IPC::Sender* sender) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(&MemoryMessageFilter::OnFilterAdded,
+ base::Unretained(this), sender));
+ return;
+ }
+ memory_message_filters_.Get().insert(this);
+ if (base::MemoryPressureListener::AreNotificationsSuppressed())
+ SendSetNotificationsSuppressed(true);
+}
+
+void MemoryMessageFilter::OnFilterRemoved() {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(&MemoryMessageFilter::OnFilterRemoved,
+ base::Unretained(this)));
+ return;
+ }
+ memory_message_filters_.Get().erase(this);
+}
+
+bool MemoryMessageFilter::OnMessageReceived(const IPC::Message& message) {
+ return false;
+}
+
+// static
+base::LazyInstance<MemoryMessageFilter::MemoryMessageFilterSet>::Leaky
+ MemoryMessageFilter::memory_message_filters_ = LAZY_INSTANCE_INITIALIZER;
+
+// static
+void MemoryMessageFilter::SendSetNotificationsSuppressedToAllProcesses(
+ bool suppressed) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(
+ &MemoryMessageFilter::SendSetNotificationsSuppressedToAllProcesses,
+ suppressed));
+ return;
+ }
+
+ // Enable/disable suppressing memory notifications in the browser process.
+ base::MemoryPressureListener::SetNotificationsSuppressed(suppressed);
+
+ // Enable/disable suppressing memory notifications in all child processes.
+ MemoryMessageFilterSet& filters = memory_message_filters_.Get();
+ for (MemoryMessageFilterSet::iterator it = filters.begin();
+ it != filters.end(); ++it) {
+ it->get()->SendSetNotificationsSuppressed(suppressed);
+ }
+}
+
+void MemoryMessageFilter::SendSetNotificationsSuppressed(bool suppressed) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ Send(new MemoryMsg_SetNotificationsSuppressed(suppressed));
+}
+
+} // namespace memory
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698