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

Side by Side Diff: content/browser/renderer_host/render_view_host_impl.cc

Issue 9691009: Revert 126199 - 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, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/render_view_host_impl.h" 5 #include "content/browser/renderer_host/render_view_host_impl.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 23 matching lines...) Expand all
34 #include "content/common/view_messages.h" 34 #include "content/common/view_messages.h"
35 #include "content/port/browser/render_widget_host_view_port.h" 35 #include "content/port/browser/render_widget_host_view_port.h"
36 #include "content/public/browser/browser_context.h" 36 #include "content/public/browser/browser_context.h"
37 #include "content/public/browser/browser_message_filter.h" 37 #include "content/public/browser/browser_message_filter.h"
38 #include "content/public/browser/content_browser_client.h" 38 #include "content/public/browser/content_browser_client.h"
39 #include "content/public/browser/dom_operation_notification_details.h" 39 #include "content/public/browser/dom_operation_notification_details.h"
40 #include "content/public/browser/native_web_keyboard_event.h" 40 #include "content/public/browser/native_web_keyboard_event.h"
41 #include "content/public/browser/notification_details.h" 41 #include "content/public/browser/notification_details.h"
42 #include "content/public/browser/notification_service.h" 42 #include "content/public/browser/notification_service.h"
43 #include "content/public/browser/notification_types.h" 43 #include "content/public/browser/notification_types.h"
44 #include "content/public/browser/render_process_host.h"
45 #include "content/public/browser/render_view_host_delegate.h" 44 #include "content/public/browser/render_view_host_delegate.h"
46 #include "content/public/browser/render_view_host_observer.h" 45 #include "content/public/browser/render_view_host_observer.h"
47 #include "content/public/browser/user_metrics.h" 46 #include "content/public/browser/user_metrics.h"
48 #include "content/public/common/bindings_policy.h" 47 #include "content/public/common/bindings_policy.h"
49 #include "content/public/common/content_constants.h" 48 #include "content/public/common/content_constants.h"
50 #include "content/public/common/content_switches.h" 49 #include "content/public/common/content_switches.h"
51 #include "content/public/common/context_menu_params.h" 50 #include "content/public/common/context_menu_params.h"
52 #include "content/public/common/result_codes.h" 51 #include "content/public/common/result_codes.h"
53 #include "content/public/common/url_constants.h" 52 #include "content/public/common/url_constants.h"
54 #include "net/base/net_util.h" 53 #include "net/base/net_util.h"
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 // Stop the hang monitor now that the unload handler has finished. 411 // Stop the hang monitor now that the unload handler has finished.
413 StopHangMonitorTimeout(); 412 StopHangMonitorTimeout();
414 is_waiting_for_unload_ack_ = false; 413 is_waiting_for_unload_ack_ = false;
415 delegate_->SwappedOut(this); 414 delegate_->SwappedOut(this);
416 } 415 }
417 416
418 void RenderViewHostImpl::WasSwappedOut() { 417 void RenderViewHostImpl::WasSwappedOut() {
419 // Don't bother reporting hung state anymore. 418 // Don't bother reporting hung state anymore.
420 StopHangMonitorTimeout(); 419 StopHangMonitorTimeout();
421 420
422 // If we are still waiting on the unload handler to be run, we consider
423 // the process hung and we should terminate it if there are no other tabs
424 // using the process. If there are other views using this process, the
425 // unresponsive renderer timeout will catch it.
426 bool hung = is_waiting_for_unload_ack_;
427
428 // Now that we're no longer the active RVH in the tab, start filtering out 421 // Now that we're no longer the active RVH in the tab, start filtering out
429 // most IPC messages. Usually the renderer will have stopped sending 422 // most IPC messages. Usually the renderer will have stopped sending
430 // messages as of OnSwapOutACK. However, we may have timed out waiting 423 // messages as of OnSwapOutACK. However, we may have timed out waiting
431 // for that message, and additional IPC messages may keep streaming in. 424 // for that message, and additional IPC messages may keep streaming in.
432 // We filter them out, as long as that won't cause problems (e.g., we 425 // We filter them out, as long as that won't cause problems (e.g., we
433 // still allow synchronous messages through). 426 // still allow synchronous messages through).
434 SetSwappedOut(true); 427 SetSwappedOut(true);
435 428
436 // If we are not running the renderer in process and no other tab is using
437 // the hung process, kill it, assuming it is a real process (unit tests don't
438 // have real processes).
439 if (hung) {
440 base::ProcessHandle process_handle = GetProcess()->GetHandle();
441 int views = 0;
442
443 // Count the number of listeners for the process, which is equivalent to
444 // views using the process as of this writing.
445 content::RenderProcessHost::listeners_iterator iter(
446 GetProcess()->ListenersIterator());
447 for (; !iter.IsAtEnd(); iter.Advance())
448 ++views;
449
450 if (!content::RenderProcessHost::run_renderer_in_process() &&
451 process_handle && views <= 1) {
452 // We expect the delegate for this RVH to be TabContents, as it is the
453 // only class that swaps out render view hosts on navigation.
454 DCHECK(delegate_->GetRenderViewType() == content::VIEW_TYPE_TAB_CONTENTS);
455
456 // Kill the process only if TabContents sets SuddenTerminationAllowed,
457 // which indicates that the timer has expired.
458 // This is not the case if we load data URLs or about:blank. The reason
459 // is that there is no network requests and this code is hit without
460 // setting the unresponsiveness timer. This allows a corner case where a
461 // navigation to a data URL will leave a process running, if the
462 // beforeunload handler completes fine, but the unload handler hangs.
463 // At this time, the complexity to solve this edge case is not worthwhile.
464 if (SuddenTerminationAllowed())
465 base::KillProcess(process_handle, content::RESULT_CODE_HUNG, false);
466 }
467 }
468
469 // Inform the renderer that it can exit if no one else is using it. 429 // Inform the renderer that it can exit if no one else is using it.
470 Send(new ViewMsg_WasSwappedOut(GetRoutingID())); 430 Send(new ViewMsg_WasSwappedOut(GetRoutingID()));
471 } 431 }
472 432
473 void RenderViewHostImpl::ClosePage() { 433 void RenderViewHostImpl::ClosePage() {
474 // Start the hang monitor in case the renderer hangs in the unload handler. 434 // Start the hang monitor in case the renderer hangs in the unload handler.
475 is_waiting_for_unload_ack_ = true; 435 is_waiting_for_unload_ack_ = true;
476 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); 436 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
477 437
478 if (IsRenderViewLive()) { 438 if (IsRenderViewLive()) {
(...skipping 1282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1761 // can cause navigations to be ignored in OnMsgNavigate. 1721 // can cause navigations to be ignored in OnMsgNavigate.
1762 is_waiting_for_beforeunload_ack_ = false; 1722 is_waiting_for_beforeunload_ack_ = false;
1763 is_waiting_for_unload_ack_ = false; 1723 is_waiting_for_unload_ack_ = false;
1764 } 1724 }
1765 1725
1766 void RenderViewHostImpl::ClearPowerSaveBlockers() { 1726 void RenderViewHostImpl::ClearPowerSaveBlockers() {
1767 STLDeleteValues(&power_save_blockers_); 1727 STLDeleteValues(&power_save_blockers_);
1768 } 1728 }
1769 1729
1770 } // namespace content 1730 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_process_host_browsertest.cc ('k') | content/test/data/english_page.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698