| 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_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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 g_created_callbacks = LAZY_INSTANCE_INITIALIZER; | 114 g_created_callbacks = LAZY_INSTANCE_INITIALIZER; |
| 115 | 115 |
| 116 } // namespace | 116 } // namespace |
| 117 | 117 |
| 118 /////////////////////////////////////////////////////////////////////////////// | 118 /////////////////////////////////////////////////////////////////////////////// |
| 119 // RenderViewHost, public: | 119 // RenderViewHost, public: |
| 120 | 120 |
| 121 // static | 121 // static |
| 122 RenderViewHost* RenderViewHost::FromID(int render_process_id, | 122 RenderViewHost* RenderViewHost::FromID(int render_process_id, |
| 123 int render_view_id) { | 123 int render_view_id) { |
| 124 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id); | 124 RenderWidgetHost* widget = |
| 125 if (!process) | 125 RenderWidgetHost::FromID(render_process_id, render_view_id); |
| 126 return NULL; | |
| 127 RenderWidgetHost* widget = process->GetRenderWidgetHostByID(render_view_id); | |
| 128 if (!widget || !widget->IsRenderView()) | 126 if (!widget || !widget->IsRenderView()) |
| 129 return NULL; | 127 return NULL; |
| 130 return static_cast<RenderViewHostImpl*>(RenderWidgetHostImpl::From(widget)); | 128 return static_cast<RenderViewHostImpl*>(RenderWidgetHostImpl::From(widget)); |
| 131 } | 129 } |
| 132 | 130 |
| 133 // static | 131 // static |
| 134 RenderViewHost* RenderViewHost::From(RenderWidgetHost* rwh) { | 132 RenderViewHost* RenderViewHost::From(RenderWidgetHost* rwh) { |
| 135 DCHECK(rwh->IsRenderView()); | 133 DCHECK(rwh->IsRenderView()); |
| 136 return static_cast<RenderViewHostImpl*>(RenderWidgetHostImpl::From(rwh)); | 134 return static_cast<RenderViewHostImpl*>(RenderWidgetHostImpl::From(rwh)); |
| 137 } | 135 } |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 | 481 |
| 484 // If we are not running the renderer in process and no other tab is using | 482 // If we are not running the renderer in process and no other tab is using |
| 485 // the hung process, consider it eligible to be killed, assuming it is a real | 483 // the hung process, consider it eligible to be killed, assuming it is a real |
| 486 // process (unit tests don't have real processes). | 484 // process (unit tests don't have real processes). |
| 487 if (hung) { | 485 if (hung) { |
| 488 base::ProcessHandle process_handle = GetProcess()->GetHandle(); | 486 base::ProcessHandle process_handle = GetProcess()->GetHandle(); |
| 489 int views = 0; | 487 int views = 0; |
| 490 | 488 |
| 491 // Count the number of widget hosts for the process, which is equivalent to | 489 // Count the number of widget hosts for the process, which is equivalent to |
| 492 // views using the process as of this writing. | 490 // views using the process as of this writing. |
| 491 /* |
| 493 RenderProcessHost::RenderWidgetHostsIterator iter( | 492 RenderProcessHost::RenderWidgetHostsIterator iter( |
| 494 GetProcess()->GetRenderWidgetHostsIterator()); | 493 GetProcess()->GetRenderWidgetHostsIterator()); |
| 495 for (; !iter.IsAtEnd(); iter.Advance()) | 494 for (; !iter.IsAtEnd(); iter.Advance()) |
| 496 ++views; | 495 ++views; |
| 496 */ |
| 497 scoped_ptr<RenderWidgetHost::List> hosts = |
| 498 RenderWidgetHost::GetRenderWidgetHosts(); |
| 499 for (RenderWidgetHost::List::const_iterator it = hosts->begin(); |
| 500 it != hosts->end(); |
| 501 ++it) { |
| 502 const RenderWidgetHost* widget = *it; |
| 503 if (widget->GetProcess()->GetID() == GetProcess()->GetID()) |
| 504 ++views; |
| 505 } |
| 506 |
| 497 | 507 |
| 498 if (!RenderProcessHost::run_renderer_in_process() && | 508 if (!RenderProcessHost::run_renderer_in_process() && |
| 499 process_handle && views <= 1) { | 509 process_handle && views <= 1) { |
| 500 // The process can safely be terminated, only if WebContents sets | 510 // The process can safely be terminated, only if WebContents sets |
| 501 // SuddenTerminationAllowed, which indicates that the timer has expired. | 511 // SuddenTerminationAllowed, which indicates that the timer has expired. |
| 502 // This is not the case if we load data URLs or about:blank. The reason | 512 // This is not the case if we load data URLs or about:blank. The reason |
| 503 // is that those have no network requests and this code is hit without | 513 // is that those have no network requests and this code is hit without |
| 504 // setting the unresponsiveness timer. This allows a corner case where a | 514 // setting the unresponsiveness timer. This allows a corner case where a |
| 505 // navigation to a data URL will leave a process running, if the | 515 // navigation to a data URL will leave a process running, if the |
| 506 // beforeunload handler completes fine, but the unload handler hangs. | 516 // beforeunload handler completes fine, but the unload handler hangs. |
| (...skipping 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2101 const std::vector<base::FilePath>& file_paths = state.GetReferencedFiles(); | 2111 const std::vector<base::FilePath>& file_paths = state.GetReferencedFiles(); |
| 2102 for (std::vector<base::FilePath>::const_iterator file = file_paths.begin(); | 2112 for (std::vector<base::FilePath>::const_iterator file = file_paths.begin(); |
| 2103 file != file_paths.end(); ++file) { | 2113 file != file_paths.end(); ++file) { |
| 2104 if (!policy->CanReadFile(GetProcess()->GetID(), *file)) | 2114 if (!policy->CanReadFile(GetProcess()->GetID(), *file)) |
| 2105 return false; | 2115 return false; |
| 2106 } | 2116 } |
| 2107 return true; | 2117 return true; |
| 2108 } | 2118 } |
| 2109 | 2119 |
| 2110 } // namespace content | 2120 } // namespace content |
| OLD | NEW |