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

Unified Diff: chrome/browser/renderer_host/out_of_memory_message_filter.cc

Issue 6006006: Show OOM notification bar in all tabs sharing same render process (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Send reply to the sync message on the IO thread Created 9 years, 11 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: chrome/browser/renderer_host/out_of_memory_message_filter.cc
diff --git a/chrome/browser/renderer_host/out_of_memory_message_filter.cc b/chrome/browser/renderer_host/out_of_memory_message_filter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..10734b17b14c4771279ba1d1392332ea847ea82f
--- /dev/null
+++ b/chrome/browser/renderer_host/out_of_memory_message_filter.cc
@@ -0,0 +1,54 @@
+// Copyright (c) 2011 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 "chrome/browser/renderer_host/out_of_memory_message_filter.h"
+
+#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
+#include "chrome/common/render_messages.h"
+
+OutOfMemoryMessageFilter::OutOfMemoryMessageFilter(int process_id)
+ : process_id_(process_id) {
+}
+
+OutOfMemoryMessageFilter::~OutOfMemoryMessageFilter() {
+}
+
+bool OutOfMemoryMessageFilter::OnMessageReceived(const IPC::Message& message,
+ bool* message_was_ok) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP_EX(OutOfMemoryMessageFilter, message, *message_was_ok)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RenderProcessOutOfJSMemory,
+ OnRenderProcessOutOfMemory)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void OutOfMemoryMessageFilter::OnRenderProcessOutOfMemory(
+ IPC::Message* reply_msg) {
+ Send(reply_msg);
+
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(
+ this,
+ &OutOfMemoryMessageFilter::OnRenderProcessOutOfMemoryOnUIThread));
+}
+
+void OutOfMemoryMessageFilter::OnRenderProcessOutOfMemoryOnUIThread() {
+ RenderProcessHost* rph = RenderProcessHost::FromID(process_id_);
+ if (!rph)
+ return;
+
+ // Show OOM notification bar in all tabs sharing this render process.
+ RenderProcessHost::listeners_iterator iter = rph->ListenersIterator();
+ while (!iter.IsAtEnd()) {
+ const IPC::Channel::Listener* listener = iter.GetCurrentValue();
+ const_cast<IPC::Channel::Listener*>(listener)->OnMessageReceived(
yurys 2011/02/01 14:00:37 I'd love to avoid const_cast here but I don't see
+ ViewHostMsg_JSOutOfMemory(iter.GetCurrentKey()));
+ iter.Advance();
+ }
+}
+
« no previous file with comments | « chrome/browser/renderer_host/out_of_memory_message_filter.h ('k') | chrome/browser/tab_contents/tab_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698