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

Unified Diff: content/browser/renderer_host/render_view_host.cc

Issue 9514016: Fixing a problem, where a hung renderer process is not killed when navigating away (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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/renderer_host/render_view_host.cc
diff --git a/content/browser/renderer_host/render_view_host.cc b/content/browser/renderer_host/render_view_host.cc
index e193dc2e71f586ccbb9a6cb3ec494e4606e7833a..28108894aed084072bd3b9e52595eb88bce8bb19 100644
--- a/content/browser/renderer_host/render_view_host.cc
+++ b/content/browser/renderer_host/render_view_host.cc
@@ -41,6 +41,7 @@
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
+#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host_delegate.h"
#include "content/public/browser/render_view_host_observer.h"
#include "content/public/browser/user_metrics.h"
@@ -380,6 +381,12 @@ void RenderViewHost::WasSwappedOut() {
// Don't bother reporting hung state anymore.
StopHangMonitorTimeout();
+ // If we are still waiting on the unload handler to be run, we consider
+ // the process hung and we should terminate it if there are no other tabs
+ // using the process. If there are other views using this process, the
+ // unresponsive renderer timeout will catch it.
+ bool hung = is_waiting_for_unload_ack_;
+
// Now that we're no longer the active RVH in the tab, start filtering out
// most IPC messages. Usually the renderer will have stopped sending
// messages as of OnSwapOutACK. However, we may have timed out waiting
@@ -388,6 +395,30 @@ void RenderViewHost::WasSwappedOut() {
// still allow synchronous messages through).
SetSwappedOut(true);
+ // If we are not running the renderer in process and no other tab is using
+ // the hung process, kill it, assuming it is a real process (unit tests don't
+ // have real processes).
+ if (hung) {
+ base::ProcessHandle process_handle = process_->GetHandle();
+ if (!content::RenderProcessHost::run_renderer_in_process() &&
+ process_->AllowTerminateOnUnresponsive() && process_handle) {
+ // We expect the delegate for this RVH to be TabContents, as it is the
+ // only one aware of swapping render views on navigation.
Charlie Reis 2012/03/01 21:08:17 More specifically, it is the only class that swaps
nasko 2012/03/01 22:50:15 Done.
+ DCHECK(delegate_->GetRenderViewType() == content::VIEW_TYPE_TAB_CONTENTS);
+
+ // If we load data URLs, such as about:blank, there will be no network
+ // request and we arrive here without timeout. Since the TabContents
+ // sets the sudden termination allowed on real timeout, respect it and
+ // don't kill the process. This allows a corner case where a navigation
+ // to a data URL will leave a process running, if the beforeunload handler
+ // completes fine, but the unload handler is hung. At this time, the
+ // complexity to solve this edge case is not worthwhile.
Charlie Reis 2012/03/01 21:08:17 I'm having trouble following this comment... Not
+ if (SuddenTerminationAllowed()) {
Charlie Reis 2012/03/01 21:08:17 nit: No braces on one-line if.
nasko 2012/03/01 22:50:15 Done.
+ base::KillProcess(process_handle, content::RESULT_CODE_HUNG, false);
+ }
+ }
+ }
+
// Inform the renderer that it can exit if no one else is using it.
Send(new ViewMsg_WasSwappedOut(routing_id()));
}

Powered by Google App Engine
This is Rietveld 408576698