Chromium Code Reviews| Index: content/public/test/mock_render_process_host.cc |
| diff --git a/content/public/test/mock_render_process_host.cc b/content/public/test/mock_render_process_host.cc |
| index 8d25ba223d402c4569ca4234ee5591793b64e100..840b16ba5ee2c8c9663542fcaaaf1ba18230c235 100644 |
| --- a/content/public/test/mock_render_process_host.cc |
| +++ b/content/public/test/mock_render_process_host.cc |
| @@ -9,6 +9,7 @@ |
| #include "base/time.h" |
| #include "content/browser/child_process_security_policy_impl.h" |
| #include "content/browser/renderer_host/render_process_host_impl.h" |
| +#include "content/browser/renderer_host/render_view_host_impl.h" |
| #include "content/browser/renderer_host/render_widget_host_impl.h" |
| #include "content/common/child_process_host_impl.h" |
| #include "content/public/browser/notification_service.h" |
| @@ -53,6 +54,18 @@ int MockRenderProcessHost::GetNextRoutingID() { |
| return ++prev_routing_id; |
| } |
| +void MockRenderProcessHost::AddRoute( |
| + int32 routing_id, |
| + IPC::Listener* listener) { |
| + listeners_.AddWithID(listener, routing_id); |
| +} |
| + |
| +void MockRenderProcessHost::RemoveRoute(int32 routing_id) { |
| + DCHECK(listeners_.Lookup(routing_id) != NULL); |
| + listeners_.Remove(routing_id); |
| + Cleanup(); |
| +} |
| + |
| void MockRenderProcessHost::SimulateSwapOutACK( |
| const ViewMsg_SwapOut_Params& params) { |
| } |
| @@ -157,18 +170,8 @@ bool MockRenderProcessHost::IgnoreInputEvents() const { |
| return false; |
| } |
| -void MockRenderProcessHost::Attach(RenderWidgetHost* host, |
| - int routing_id) { |
| - render_widget_hosts_.AddWithID(host, routing_id); |
| -} |
| - |
| -void MockRenderProcessHost::Release(int routing_id) { |
| - render_widget_hosts_.Remove(routing_id); |
| - Cleanup(); |
| -} |
| - |
| void MockRenderProcessHost::Cleanup() { |
| - if (render_widget_hosts_.IsEmpty()) { |
| + if (listeners_.IsEmpty()) { |
| NotificationService::current()->Notify( |
| NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| Source<RenderProcessHost>(this), |
| @@ -191,11 +194,6 @@ bool MockRenderProcessHost::SuddenTerminationAllowed() const { |
| return true; |
| } |
| -RenderWidgetHost* MockRenderProcessHost::GetRenderWidgetHostByID( |
| - int routing_id) { |
| - return render_widget_hosts_.Lookup(routing_id); |
| -} |
| - |
| BrowserContext* MockRenderProcessHost::GetBrowserContext() const { |
| return browser_context_; |
| } |
| @@ -210,8 +208,37 @@ IPC::ChannelProxy* MockRenderProcessHost::GetChannel() { |
| return NULL; |
| } |
| +int MockRenderProcessHost::GetActiveViewCount() { |
| + int num_active_views = 0; |
| + RenderWidgetHost::List widgets = RenderWidgetHost::GetRenderWidgetHosts(); |
| + for (RenderWidgetHost::List::const_iterator it = widgets.begin(); |
| + it != widgets.end(); ++it) { |
| + const RenderWidgetHost* widget = *it; |
| + DCHECK(widget); |
| + if (!widget) |
|
jam
2013/06/12 19:59:59
when can this happen?
nasko
2013/06/12 21:18:59
Missed that, fixed now.
|
| + continue; |
| + |
| + // Count only RenderWidgetHosts in this process. |
| + if (widget->GetProcess()->GetID() != GetID()) |
| + continue; |
| + |
| + // All RenderWidgetHosts are swapped in. |
| + if (!widget->IsRenderView()) { |
| + num_active_views++; |
| + continue; |
| + } |
| + |
| + // Don't count swapped out views. |
| + RenderViewHost* rvh = |
| + RenderViewHost::From(const_cast<RenderWidgetHost*>(widget)); |
| + if (!static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out()) |
| + num_active_views++; |
| + } |
| + return num_active_views; |
| +} |
| + |
| bool MockRenderProcessHost::FastShutdownForPageCount(size_t count) { |
| - if (render_widget_hosts_.size() == count) |
| + if (static_cast<size_t>(GetActiveViewCount()) == count) |
| return FastShutdownIfPossible(); |
| return false; |
| } |
| @@ -226,15 +253,11 @@ void MockRenderProcessHost::SurfaceUpdated(int32 surface_id) { |
| void MockRenderProcessHost::ResumeRequestsForView(int route_id) { |
| } |
| -RenderProcessHost::RenderWidgetHostsIterator |
| - MockRenderProcessHost::GetRenderWidgetHostsIterator() { |
| - return RenderWidgetHostsIterator(&render_widget_hosts_); |
| -} |
| bool MockRenderProcessHost::OnMessageReceived(const IPC::Message& msg) { |
| - RenderWidgetHost* rwh = render_widget_hosts_.Lookup(msg.routing_id()); |
| - if (rwh) |
| - return RenderWidgetHostImpl::From(rwh)->OnMessageReceived(msg); |
| + IPC::Listener* listener = listeners_.Lookup(msg.routing_id()); |
| + if (listener) |
| + return listener->OnMessageReceived(msg); |
| return false; |
| } |