Chromium Code Reviews| 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/public/test/mock_render_process_host.h" | 5 #include "content/public/test/mock_render_process_host.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "content/browser/child_process_security_policy_impl.h" | 10 #include "content/browser/child_process_security_policy_impl.h" |
| 11 #include "content/browser/renderer_host/render_process_host_impl.h" | 11 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 12 #include "content/browser/renderer_host/render_view_host_impl.h" | |
| 12 #include "content/browser/renderer_host/render_widget_host_impl.h" | 13 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 13 #include "content/common/child_process_host_impl.h" | 14 #include "content/common/child_process_host_impl.h" |
| 14 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
| 15 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
| 16 #include "content/public/browser/storage_partition.h" | 17 #include "content/public/browser/storage_partition.h" |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 | 20 |
| 20 MockRenderProcessHost::MockRenderProcessHost( | 21 MockRenderProcessHost::MockRenderProcessHost( |
| 21 BrowserContext* browser_context) | 22 BrowserContext* browser_context) |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 46 | 47 |
| 47 bool MockRenderProcessHost::Init() { | 48 bool MockRenderProcessHost::Init() { |
| 48 return true; | 49 return true; |
| 49 } | 50 } |
| 50 | 51 |
| 51 int MockRenderProcessHost::GetNextRoutingID() { | 52 int MockRenderProcessHost::GetNextRoutingID() { |
| 52 static int prev_routing_id = 0; | 53 static int prev_routing_id = 0; |
| 53 return ++prev_routing_id; | 54 return ++prev_routing_id; |
| 54 } | 55 } |
| 55 | 56 |
| 57 void MockRenderProcessHost::AddRoute( | |
| 58 int32 routing_id, | |
| 59 IPC::Listener* listener) { | |
| 60 listeners_.AddWithID(listener, routing_id); | |
| 61 } | |
| 62 | |
| 63 void MockRenderProcessHost::RemoveRoute(int32 routing_id) { | |
| 64 DCHECK(listeners_.Lookup(routing_id) != NULL); | |
| 65 listeners_.Remove(routing_id); | |
| 66 Cleanup(); | |
| 67 } | |
| 68 | |
| 56 void MockRenderProcessHost::SimulateSwapOutACK( | 69 void MockRenderProcessHost::SimulateSwapOutACK( |
| 57 const ViewMsg_SwapOut_Params& params) { | 70 const ViewMsg_SwapOut_Params& params) { |
| 58 } | 71 } |
| 59 | 72 |
| 60 bool MockRenderProcessHost::WaitForBackingStoreMsg( | 73 bool MockRenderProcessHost::WaitForBackingStoreMsg( |
| 61 int render_widget_id, | 74 int render_widget_id, |
| 62 const base::TimeDelta& max_delay, | 75 const base::TimeDelta& max_delay, |
| 63 IPC::Message* msg) { | 76 IPC::Message* msg) { |
| 64 return false; | 77 return false; |
| 65 } | 78 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 return true; | 163 return true; |
| 151 } | 164 } |
| 152 | 165 |
| 153 void MockRenderProcessHost::SetIgnoreInputEvents(bool ignore_input_events) { | 166 void MockRenderProcessHost::SetIgnoreInputEvents(bool ignore_input_events) { |
| 154 } | 167 } |
| 155 | 168 |
| 156 bool MockRenderProcessHost::IgnoreInputEvents() const { | 169 bool MockRenderProcessHost::IgnoreInputEvents() const { |
| 157 return false; | 170 return false; |
| 158 } | 171 } |
| 159 | 172 |
| 160 void MockRenderProcessHost::Attach(RenderWidgetHost* host, | |
| 161 int routing_id) { | |
| 162 render_widget_hosts_.AddWithID(host, routing_id); | |
| 163 } | |
| 164 | |
| 165 void MockRenderProcessHost::Release(int routing_id) { | |
| 166 render_widget_hosts_.Remove(routing_id); | |
| 167 Cleanup(); | |
| 168 } | |
| 169 | |
| 170 void MockRenderProcessHost::Cleanup() { | 173 void MockRenderProcessHost::Cleanup() { |
| 171 if (render_widget_hosts_.IsEmpty()) { | 174 if (listeners_.IsEmpty()) { |
| 172 NotificationService::current()->Notify( | 175 NotificationService::current()->Notify( |
| 173 NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 176 NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 174 Source<RenderProcessHost>(this), | 177 Source<RenderProcessHost>(this), |
| 175 NotificationService::NoDetails()); | 178 NotificationService::NoDetails()); |
| 176 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 179 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 177 RenderProcessHostImpl::UnregisterHost(GetID()); | 180 RenderProcessHostImpl::UnregisterHost(GetID()); |
| 178 } | 181 } |
| 179 } | 182 } |
| 180 | 183 |
| 181 void MockRenderProcessHost::AddPendingView() { | 184 void MockRenderProcessHost::AddPendingView() { |
| 182 } | 185 } |
| 183 | 186 |
| 184 void MockRenderProcessHost::RemovePendingView() { | 187 void MockRenderProcessHost::RemovePendingView() { |
| 185 } | 188 } |
| 186 | 189 |
| 187 void MockRenderProcessHost::SetSuddenTerminationAllowed(bool allowed) { | 190 void MockRenderProcessHost::SetSuddenTerminationAllowed(bool allowed) { |
| 188 } | 191 } |
| 189 | 192 |
| 190 bool MockRenderProcessHost::SuddenTerminationAllowed() const { | 193 bool MockRenderProcessHost::SuddenTerminationAllowed() const { |
| 191 return true; | 194 return true; |
| 192 } | 195 } |
| 193 | 196 |
| 194 RenderWidgetHost* MockRenderProcessHost::GetRenderWidgetHostByID( | |
| 195 int routing_id) { | |
| 196 return render_widget_hosts_.Lookup(routing_id); | |
| 197 } | |
| 198 | |
| 199 BrowserContext* MockRenderProcessHost::GetBrowserContext() const { | 197 BrowserContext* MockRenderProcessHost::GetBrowserContext() const { |
| 200 return browser_context_; | 198 return browser_context_; |
| 201 } | 199 } |
| 202 | 200 |
| 203 bool MockRenderProcessHost::InSameStoragePartition( | 201 bool MockRenderProcessHost::InSameStoragePartition( |
| 204 StoragePartition* partition) const { | 202 StoragePartition* partition) const { |
| 205 // Mock RPHs only have one partition. | 203 // Mock RPHs only have one partition. |
| 206 return true; | 204 return true; |
| 207 } | 205 } |
| 208 | 206 |
| 209 IPC::ChannelProxy* MockRenderProcessHost::GetChannel() { | 207 IPC::ChannelProxy* MockRenderProcessHost::GetChannel() { |
| 210 return NULL; | 208 return NULL; |
| 211 } | 209 } |
| 212 | 210 |
| 211 int MockRenderProcessHost::GetActiveViewCount() { | |
| 212 int num_active_views = 0; | |
| 213 RenderWidgetHost::List widgets = RenderWidgetHost::GetRenderWidgetHosts(); | |
| 214 for (RenderWidgetHost::List::const_iterator it = widgets.begin(); | |
| 215 it != widgets.end(); ++it) { | |
| 216 const RenderWidgetHost* widget = *it; | |
| 217 DCHECK(widget); | |
| 218 if (!widget) | |
|
jam
2013/06/12 19:59:59
when can this happen?
nasko
2013/06/12 21:18:59
Missed that, fixed now.
| |
| 219 continue; | |
| 220 | |
| 221 // Count only RenderWidgetHosts in this process. | |
| 222 if (widget->GetProcess()->GetID() != GetID()) | |
| 223 continue; | |
| 224 | |
| 225 // All RenderWidgetHosts are swapped in. | |
| 226 if (!widget->IsRenderView()) { | |
| 227 num_active_views++; | |
| 228 continue; | |
| 229 } | |
| 230 | |
| 231 // Don't count swapped out views. | |
| 232 RenderViewHost* rvh = | |
| 233 RenderViewHost::From(const_cast<RenderWidgetHost*>(widget)); | |
| 234 if (!static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out()) | |
| 235 num_active_views++; | |
| 236 } | |
| 237 return num_active_views; | |
| 238 } | |
| 239 | |
| 213 bool MockRenderProcessHost::FastShutdownForPageCount(size_t count) { | 240 bool MockRenderProcessHost::FastShutdownForPageCount(size_t count) { |
| 214 if (render_widget_hosts_.size() == count) | 241 if (static_cast<size_t>(GetActiveViewCount()) == count) |
| 215 return FastShutdownIfPossible(); | 242 return FastShutdownIfPossible(); |
| 216 return false; | 243 return false; |
| 217 } | 244 } |
| 218 | 245 |
| 219 base::TimeDelta MockRenderProcessHost::GetChildProcessIdleTime() const { | 246 base::TimeDelta MockRenderProcessHost::GetChildProcessIdleTime() const { |
| 220 return base::TimeDelta::FromMilliseconds(0); | 247 return base::TimeDelta::FromMilliseconds(0); |
| 221 } | 248 } |
| 222 | 249 |
| 223 void MockRenderProcessHost::SurfaceUpdated(int32 surface_id) { | 250 void MockRenderProcessHost::SurfaceUpdated(int32 surface_id) { |
| 224 } | 251 } |
| 225 | 252 |
| 226 void MockRenderProcessHost::ResumeRequestsForView(int route_id) { | 253 void MockRenderProcessHost::ResumeRequestsForView(int route_id) { |
| 227 } | 254 } |
| 228 | 255 |
| 229 RenderProcessHost::RenderWidgetHostsIterator | |
| 230 MockRenderProcessHost::GetRenderWidgetHostsIterator() { | |
| 231 return RenderWidgetHostsIterator(&render_widget_hosts_); | |
| 232 } | |
| 233 | 256 |
| 234 bool MockRenderProcessHost::OnMessageReceived(const IPC::Message& msg) { | 257 bool MockRenderProcessHost::OnMessageReceived(const IPC::Message& msg) { |
| 235 RenderWidgetHost* rwh = render_widget_hosts_.Lookup(msg.routing_id()); | 258 IPC::Listener* listener = listeners_.Lookup(msg.routing_id()); |
| 236 if (rwh) | 259 if (listener) |
| 237 return RenderWidgetHostImpl::From(rwh)->OnMessageReceived(msg); | 260 return listener->OnMessageReceived(msg); |
| 238 return false; | 261 return false; |
| 239 } | 262 } |
| 240 | 263 |
| 241 void MockRenderProcessHost::OnChannelConnected(int32 peer_pid) { | 264 void MockRenderProcessHost::OnChannelConnected(int32 peer_pid) { |
| 242 } | 265 } |
| 243 | 266 |
| 244 MockRenderProcessHostFactory::MockRenderProcessHostFactory() {} | 267 MockRenderProcessHostFactory::MockRenderProcessHostFactory() {} |
| 245 | 268 |
| 246 MockRenderProcessHostFactory::~MockRenderProcessHostFactory() { | 269 MockRenderProcessHostFactory::~MockRenderProcessHostFactory() { |
| 247 // Detach this object from MockRenderProcesses to prevent STLDeleteElements() | 270 // Detach this object from MockRenderProcesses to prevent STLDeleteElements() |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 267 for (ScopedVector<MockRenderProcessHost>::iterator it = processes_.begin(); | 290 for (ScopedVector<MockRenderProcessHost>::iterator it = processes_.begin(); |
| 268 it != processes_.end(); ++it) { | 291 it != processes_.end(); ++it) { |
| 269 if (*it == host) { | 292 if (*it == host) { |
| 270 processes_.weak_erase(it); | 293 processes_.weak_erase(it); |
| 271 break; | 294 break; |
| 272 } | 295 } |
| 273 } | 296 } |
| 274 } | 297 } |
| 275 | 298 |
| 276 } // content | 299 } // content |
| OLD | NEW |