OLD | NEW |
---|---|
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.h" | 5 #include "content/browser/renderer_host/render_view_host.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 Loading... | |
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" | |
44 #include "content/public/browser/render_view_host_delegate.h" | 45 #include "content/public/browser/render_view_host_delegate.h" |
45 #include "content/public/browser/render_view_host_observer.h" | 46 #include "content/public/browser/render_view_host_observer.h" |
46 #include "content/public/browser/user_metrics.h" | 47 #include "content/public/browser/user_metrics.h" |
47 #include "content/public/common/bindings_policy.h" | 48 #include "content/public/common/bindings_policy.h" |
48 #include "content/public/common/content_constants.h" | 49 #include "content/public/common/content_constants.h" |
49 #include "content/public/common/content_switches.h" | 50 #include "content/public/common/content_switches.h" |
50 #include "content/public/common/context_menu_params.h" | 51 #include "content/public/common/context_menu_params.h" |
51 #include "content/public/common/result_codes.h" | 52 #include "content/public/common/result_codes.h" |
52 #include "content/public/common/url_constants.h" | 53 #include "content/public/common/url_constants.h" |
53 #include "net/base/net_util.h" | 54 #include "net/base/net_util.h" |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 // Stop the hang monitor now that the unload handler has finished. | 374 // Stop the hang monitor now that the unload handler has finished. |
374 StopHangMonitorTimeout(); | 375 StopHangMonitorTimeout(); |
375 is_waiting_for_unload_ack_ = false; | 376 is_waiting_for_unload_ack_ = false; |
376 delegate_->SwappedOut(this); | 377 delegate_->SwappedOut(this); |
377 } | 378 } |
378 | 379 |
379 void RenderViewHost::WasSwappedOut() { | 380 void RenderViewHost::WasSwappedOut() { |
380 // Don't bother reporting hung state anymore. | 381 // Don't bother reporting hung state anymore. |
381 StopHangMonitorTimeout(); | 382 StopHangMonitorTimeout(); |
382 | 383 |
384 // If we are still waiting on the unload handler to be run, we consider | |
385 // the process hung and we should terminate it if there are no other tabs | |
386 // using the process. If there are other views using this process, the | |
387 // unresponsive renderer timeout will catch it. | |
388 bool hung = is_waiting_for_unload_ack_; | |
389 | |
383 // Now that we're no longer the active RVH in the tab, start filtering out | 390 // Now that we're no longer the active RVH in the tab, start filtering out |
384 // most IPC messages. Usually the renderer will have stopped sending | 391 // most IPC messages. Usually the renderer will have stopped sending |
385 // messages as of OnSwapOutACK. However, we may have timed out waiting | 392 // messages as of OnSwapOutACK. However, we may have timed out waiting |
386 // for that message, and additional IPC messages may keep streaming in. | 393 // for that message, and additional IPC messages may keep streaming in. |
387 // We filter them out, as long as that won't cause problems (e.g., we | 394 // We filter them out, as long as that won't cause problems (e.g., we |
388 // still allow synchronous messages through). | 395 // still allow synchronous messages through). |
389 SetSwappedOut(true); | 396 SetSwappedOut(true); |
390 | 397 |
398 // If we are not running the renderer in process and no other tab is using | |
399 // the hung process, kill it, assuming it is a real process (unit tests don't | |
400 // have real processes). | |
401 if (hung) { | |
402 base::ProcessHandle process_handle = process_->GetHandle(); | |
403 if (!content::RenderProcessHost::run_renderer_in_process() && | |
404 process_->AllowTerminateOnUnresponsive() && process_handle) { | |
405 // We expect the delegate for this RVH to be TabContents, as it is the | |
406 // 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.
| |
407 DCHECK(delegate_->GetRenderViewType() == content::VIEW_TYPE_TAB_CONTENTS); | |
408 | |
409 // If we load data URLs, such as about:blank, there will be no network | |
410 // request and we arrive here without timeout. Since the TabContents | |
411 // sets the sudden termination allowed on real timeout, respect it and | |
412 // don't kill the process. This allows a corner case where a navigation | |
413 // to a data URL will leave a process running, if the beforeunload handler | |
414 // completes fine, but the unload handler is hung. At this time, the | |
415 // 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
| |
416 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.
| |
417 base::KillProcess(process_handle, content::RESULT_CODE_HUNG, false); | |
418 } | |
419 } | |
420 } | |
421 | |
391 // Inform the renderer that it can exit if no one else is using it. | 422 // Inform the renderer that it can exit if no one else is using it. |
392 Send(new ViewMsg_WasSwappedOut(routing_id())); | 423 Send(new ViewMsg_WasSwappedOut(routing_id())); |
393 } | 424 } |
394 | 425 |
395 void RenderViewHost::ClosePage() { | 426 void RenderViewHost::ClosePage() { |
396 // Start the hang monitor in case the renderer hangs in the unload handler. | 427 // Start the hang monitor in case the renderer hangs in the unload handler. |
397 is_waiting_for_unload_ack_ = true; | 428 is_waiting_for_unload_ack_ = true; |
398 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); | 429 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); |
399 | 430 |
400 if (IsRenderViewLive()) { | 431 if (IsRenderViewLive()) { |
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1600 // Whenever we change swap out state, we should not be waiting for | 1631 // Whenever we change swap out state, we should not be waiting for |
1601 // beforeunload or unload acks. We clear them here to be safe, since they | 1632 // beforeunload or unload acks. We clear them here to be safe, since they |
1602 // can cause navigations to be ignored in OnMsgNavigate. | 1633 // can cause navigations to be ignored in OnMsgNavigate. |
1603 is_waiting_for_beforeunload_ack_ = false; | 1634 is_waiting_for_beforeunload_ack_ = false; |
1604 is_waiting_for_unload_ack_ = false; | 1635 is_waiting_for_unload_ack_ = false; |
1605 } | 1636 } |
1606 | 1637 |
1607 void RenderViewHost::ClearPowerSaveBlockers() { | 1638 void RenderViewHost::ClearPowerSaveBlockers() { |
1608 STLDeleteValues(&power_save_blockers_); | 1639 STLDeleteValues(&power_save_blockers_); |
1609 } | 1640 } |
OLD | NEW |