Chromium Code Reviews| Index: content/browser/renderer_host/render_process_host_impl.cc |
| diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc |
| index ecd4139d42d3e8efd3941311dd8cdde8d3e41bb6..0c7efc9a4feb271f0e5dfe868be41ad879447c96 100644 |
| --- a/content/browser/renderer_host/render_process_host_impl.cc |
| +++ b/content/browser/renderer_host/render_process_host_impl.cc |
| @@ -105,6 +105,7 @@ |
| #include "content/public/browser/notification_service.h" |
| #include "content/public/browser/notification_types.h" |
| #include "content/public/browser/render_process_host_factory.h" |
| +#include "content/public/browser/render_widget_host.h" |
| #include "content/public/browser/resource_context.h" |
| #include "content/public/browser/user_metrics.h" |
| #include "content/public/common/content_constants.h" |
| @@ -716,6 +717,34 @@ int RenderProcessHostImpl::GetNextRoutingID() { |
| return widget_helper_->GetNextRoutingID(); |
| } |
| +void RenderProcessHostImpl::AddRoute( |
| + int32 routing_id, |
| + IPC::Listener* listener) { |
| + listeners_.AddWithID(listener, routing_id); |
| +} |
| + |
| +void RenderProcessHostImpl::RemoveRoute(int32 routing_id) { |
| + DCHECK(listeners_.Lookup(routing_id) != NULL); |
| + listeners_.Remove(routing_id); |
| + |
| +#if defined(OS_WIN) |
| + // Dump the handle table if handle auditing is enabled. |
| + const CommandLine& browser_command_line = |
| + *CommandLine::ForCurrentProcess(); |
| + if (browser_command_line.HasSwitch(switches::kAuditHandles) || |
| + browser_command_line.HasSwitch(switches::kAuditAllHandles)) { |
| + DumpHandles(); |
| + |
| + // We wait to close the channels until the child process has finished |
| + // dumping handles and sends us ChildProcessHostMsg_DumpHandlesDone. |
| + return; |
| + } |
| +#endif |
| + // Keep the one renderer thread around forever in single process mode. |
| + if (!run_renderer_in_process()) |
| + Cleanup(); |
| +} |
| + |
| void RenderProcessHostImpl::SimulateSwapOutACK( |
| const ViewMsg_SwapOut_Params& params) { |
| widget_helper_->SimulateSwapOutACK(params); |
| @@ -1198,9 +1227,9 @@ bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { |
| return true; |
| } |
| - // Dispatch incoming messages to the appropriate RenderView/WidgetHost. |
| - RenderWidgetHost* rwh = render_widget_hosts_.Lookup(msg.routing_id()); |
| - if (!rwh) { |
| + // Dispatch incoming messages to the appropriate IPC::Listener. |
| + IPC::Listener* listener = listeners_.Lookup(msg.routing_id()); |
| + if (!listener) { |
| if (msg.is_sync()) { |
| // The listener has gone away, so we must respond or else the caller will |
| // hang waiting for a reply. |
| @@ -1218,7 +1247,7 @@ bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { |
| IPC_END_MESSAGE_MAP_EX() |
| return true; |
| } |
| - return RenderWidgetHostImpl::From(rwh)->OnMessageReceived(msg); |
| + return listener->OnMessageReceived(msg); |
| } |
| void RenderProcessHostImpl::OnChannelConnected(int32 peer_pid) { |
| @@ -1253,11 +1282,6 @@ bool RenderProcessHostImpl::HasConnection() const { |
| return channel_.get() != NULL; |
| } |
| -RenderWidgetHost* RenderProcessHostImpl::GetRenderWidgetHostByID( |
| - int routing_id) { |
| - return render_widget_hosts_.Lookup(routing_id); |
| -} |
| - |
| void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { |
| ignore_input_events_ = ignore_input_events; |
| } |
| @@ -1266,36 +1290,9 @@ bool RenderProcessHostImpl::IgnoreInputEvents() const { |
| return ignore_input_events_; |
| } |
| -void RenderProcessHostImpl::Attach(RenderWidgetHost* host, |
| - int routing_id) { |
| - render_widget_hosts_.AddWithID(host, routing_id); |
| -} |
| - |
| -void RenderProcessHostImpl::Release(int routing_id) { |
| - DCHECK(render_widget_hosts_.Lookup(routing_id) != NULL); |
| - render_widget_hosts_.Remove(routing_id); |
| - |
| -#if defined(OS_WIN) |
| - // Dump the handle table if handle auditing is enabled. |
| - const CommandLine& browser_command_line = |
| - *CommandLine::ForCurrentProcess(); |
| - if (browser_command_line.HasSwitch(switches::kAuditHandles) || |
| - browser_command_line.HasSwitch(switches::kAuditAllHandles)) { |
| - DumpHandles(); |
| - |
| - // We wait to close the channels until the child process has finished |
| - // dumping handles and sends us ChildProcessHostMsg_DumpHandlesDone. |
| - return; |
| - } |
| -#endif |
| - // Keep the one renderer thread around forever in single process mode. |
| - if (!run_renderer_in_process()) |
| - Cleanup(); |
| -} |
| - |
| void RenderProcessHostImpl::Cleanup() { |
| // When no other owners of this object, we can delete ourselves |
| - if (render_widget_hosts_.IsEmpty()) { |
| + if (listeners_.IsEmpty()) { |
| DCHECK_EQ(0, pending_views_); |
| NotificationService::current()->Notify( |
| NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| @@ -1356,13 +1353,8 @@ IPC::ChannelProxy* RenderProcessHostImpl::GetChannel() { |
| return channel_.get(); |
| } |
| -RenderProcessHost::RenderWidgetHostsIterator |
| - RenderProcessHostImpl::GetRenderWidgetHostsIterator() { |
| - return RenderWidgetHostsIterator(&render_widget_hosts_); |
| -} |
| - |
| bool RenderProcessHostImpl::FastShutdownForPageCount(size_t count) { |
| - if (render_widget_hosts_.size() == count) |
| + if (static_cast<size_t>(GetActiveViewCount()) == count) |
| return FastShutdownIfPossible(); |
| return false; |
| } |
| @@ -1623,13 +1615,18 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead) { |
| channel_.reset(); |
| gpu_message_filter_ = NULL; |
| - IDMap<RenderWidgetHost>::iterator iter(&render_widget_hosts_); |
| - while (!iter.IsAtEnd()) { |
| - RenderWidgetHostImpl::From(iter.GetCurrentValue())->OnMessageReceived( |
| - ViewHostMsg_RenderViewGone(iter.GetCurrentKey(), |
| - static_cast<int>(status), |
| - exit_code)); |
| - iter.Advance(); |
| + RenderWidgetHost::List widgets = RenderWidgetHost::GetRenderWidgetHosts(); |
| + for (RenderWidgetHost::List::const_iterator it = widgets.begin(); |
|
jam
2013/06/12 19:59:59
dito
nasko
2013/06/12 21:18:59
Done.
|
| + it != widgets.end(); ++it) { |
| + const RenderWidgetHost* widget = *it; |
| + if (widget->GetProcess()->GetID() != GetID()) |
| + continue; |
| + RenderWidgetHostImpl::From( |
| + const_cast<RenderWidgetHost*>(widget))->OnMessageReceived( |
| + ViewHostMsg_RenderViewGone(widget->GetRoutingID(), |
| + static_cast<int>(status), |
| + exit_code)); |
| + |
| } |
| ClearTransportDIBCache(); |
| @@ -1640,14 +1637,18 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead) { |
| int RenderProcessHostImpl::GetActiveViewCount() { |
| int num_active_views = 0; |
| - for (RenderWidgetHostsIterator iter = GetRenderWidgetHostsIterator(); |
| - !iter.IsAtEnd(); |
| - iter.Advance()) { |
| - const RenderWidgetHost* widget = iter.GetCurrentValue(); |
| + RenderWidgetHost::List widgets = RenderWidgetHost::GetRenderWidgetHosts(); |
| + for (RenderWidgetHost::List::const_iterator it = widgets.begin(); |
| + it != widgets.end(); ++it) { |
|
jam
2013/06/12 19:59:59
ditto
nasko
2013/06/12 21:18:59
Done.
|
| + const RenderWidgetHost* widget = *it; |
| DCHECK(widget); |
| if (!widget) |
| continue; |
| + // Count only RenderWidgetHosts in this process. |
| + if (widget->GetProcess()->GetID() != GetID()) |
| + continue; |
| + |
| // All RenderWidgetHosts are swapped in. |
| if (!widget->IsRenderView()) { |
| num_active_views++; |
| @@ -1789,14 +1790,18 @@ void RenderProcessHostImpl::OnCompositorSurfaceBuffersSwappedNoHost( |
| } |
| void RenderProcessHostImpl::OnGpuSwitching() { |
| - for (RenderWidgetHostsIterator iter = GetRenderWidgetHostsIterator(); |
| - !iter.IsAtEnd(); |
| - iter.Advance()) { |
| - const RenderWidgetHost* widget = iter.GetCurrentValue(); |
| + RenderWidgetHost::List widgets = RenderWidgetHost::GetRenderWidgetHosts(); |
| + for (RenderWidgetHost::List::const_iterator it = widgets.begin(); |
| + it != widgets.end(); ++it) { |
|
jam
2013/06/12 19:59:59
ditto
nasko
2013/06/12 21:18:59
Done.
|
| + const RenderWidgetHost* widget = *it; |
| DCHECK(widget); |
| if (!widget || !widget->IsRenderView()) |
| continue; |
| + // Skip widgets in other processes. |
| + if (widget->GetProcess()->GetID() != GetID()) |
| + continue; |
| + |
| RenderViewHost* rvh = |
| RenderViewHost::From(const_cast<RenderWidgetHost*>(widget)); |