Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: content/browser/renderer_host/render_process_host_impl.cc

Issue 16431010: Refactor RenderProcessHost to use IPC::Listener instead of RenderWidgetHost (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing Windows compile error. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // Represents the browser side of the browser <--> renderer communication 5 // Represents the browser side of the browser <--> renderer communication
6 // channel. There will be one RenderProcessHost per renderer process. 6 // channel. There will be one RenderProcessHost per renderer process.
7 7
8 #include "content/browser/renderer_host/render_process_host_impl.h" 8 #include "content/browser/renderer_host/render_process_host_impl.h"
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 #include "content/common/child_process_messages.h" 98 #include "content/common/child_process_messages.h"
99 #include "content/common/gpu/gpu_messages.h" 99 #include "content/common/gpu/gpu_messages.h"
100 #include "content/common/resource_messages.h" 100 #include "content/common/resource_messages.h"
101 #include "content/common/view_messages.h" 101 #include "content/common/view_messages.h"
102 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" 102 #include "content/port/browser/render_widget_host_view_frame_subscriber.h"
103 #include "content/public/browser/browser_context.h" 103 #include "content/public/browser/browser_context.h"
104 #include "content/public/browser/content_browser_client.h" 104 #include "content/public/browser/content_browser_client.h"
105 #include "content/public/browser/notification_service.h" 105 #include "content/public/browser/notification_service.h"
106 #include "content/public/browser/notification_types.h" 106 #include "content/public/browser/notification_types.h"
107 #include "content/public/browser/render_process_host_factory.h" 107 #include "content/public/browser/render_process_host_factory.h"
108 #include "content/public/browser/render_widget_host.h"
108 #include "content/public/browser/resource_context.h" 109 #include "content/public/browser/resource_context.h"
109 #include "content/public/browser/user_metrics.h" 110 #include "content/public/browser/user_metrics.h"
110 #include "content/public/common/content_constants.h" 111 #include "content/public/common/content_constants.h"
111 #include "content/public/common/content_switches.h" 112 #include "content/public/common/content_switches.h"
112 #include "content/public/common/process_type.h" 113 #include "content/public/common/process_type.h"
113 #include "content/public/common/result_codes.h" 114 #include "content/public/common/result_codes.h"
114 #include "content/public/common/url_constants.h" 115 #include "content/public/common/url_constants.h"
115 #include "content/renderer/render_process_impl.h" 116 #include "content/renderer/render_process_impl.h"
116 #include "content/renderer/render_thread_impl.h" 117 #include "content/renderer/render_thread_impl.h"
117 #include "gpu/command_buffer/service/gpu_switches.h" 118 #include "gpu/command_buffer/service/gpu_switches.h"
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 if (CommandLine::ForCurrentProcess()->HasSwitch( 710 if (CommandLine::ForCurrentProcess()->HasSwitch(
710 switches::kEnableMemoryBenchmarking)) 711 switches::kEnableMemoryBenchmarking))
711 channel_->AddFilter(new MemoryBenchmarkMessageFilter()); 712 channel_->AddFilter(new MemoryBenchmarkMessageFilter());
712 #endif 713 #endif
713 } 714 }
714 715
715 int RenderProcessHostImpl::GetNextRoutingID() { 716 int RenderProcessHostImpl::GetNextRoutingID() {
716 return widget_helper_->GetNextRoutingID(); 717 return widget_helper_->GetNextRoutingID();
717 } 718 }
718 719
720 void RenderProcessHostImpl::AddRoute(
721 int32 routing_id,
722 IPC::Listener* listener) {
723 listeners_.AddWithID(listener, routing_id);
724 }
725
726 void RenderProcessHostImpl::RemoveRoute(int32 routing_id) {
727 DCHECK(listeners_.Lookup(routing_id) != NULL);
728 listeners_.Remove(routing_id);
729
730 #if defined(OS_WIN)
731 // Dump the handle table if handle auditing is enabled.
732 const CommandLine& browser_command_line =
733 *CommandLine::ForCurrentProcess();
734 if (browser_command_line.HasSwitch(switches::kAuditHandles) ||
735 browser_command_line.HasSwitch(switches::kAuditAllHandles)) {
736 DumpHandles();
737
738 // We wait to close the channels until the child process has finished
739 // dumping handles and sends us ChildProcessHostMsg_DumpHandlesDone.
740 return;
741 }
742 #endif
743 // Keep the one renderer thread around forever in single process mode.
744 if (!run_renderer_in_process())
745 Cleanup();
746 }
747
719 void RenderProcessHostImpl::SimulateSwapOutACK( 748 void RenderProcessHostImpl::SimulateSwapOutACK(
720 const ViewMsg_SwapOut_Params& params) { 749 const ViewMsg_SwapOut_Params& params) {
721 widget_helper_->SimulateSwapOutACK(params); 750 widget_helper_->SimulateSwapOutACK(params);
722 } 751 }
723 752
724 bool RenderProcessHostImpl::WaitForBackingStoreMsg( 753 bool RenderProcessHostImpl::WaitForBackingStoreMsg(
725 int render_widget_id, 754 int render_widget_id,
726 const base::TimeDelta& max_delay, 755 const base::TimeDelta& max_delay,
727 IPC::Message* msg) { 756 IPC::Message* msg) {
728 // The post task to this thread with the process id could be in queue, and we 757 // The post task to this thread with the process id could be in queue, and we
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 if (!msg_is_ok) { 1220 if (!msg_is_ok) {
1192 // The message had a handler, but its de-serialization failed. 1221 // The message had a handler, but its de-serialization failed.
1193 // We consider this a capital crime. Kill the renderer if we have one. 1222 // We consider this a capital crime. Kill the renderer if we have one.
1194 LOG(ERROR) << "bad message " << msg.type() << " terminating renderer."; 1223 LOG(ERROR) << "bad message " << msg.type() << " terminating renderer.";
1195 RecordAction(UserMetricsAction("BadMessageTerminate_BRPH")); 1224 RecordAction(UserMetricsAction("BadMessageTerminate_BRPH"));
1196 ReceivedBadMessage(); 1225 ReceivedBadMessage();
1197 } 1226 }
1198 return true; 1227 return true;
1199 } 1228 }
1200 1229
1201 // Dispatch incoming messages to the appropriate RenderView/WidgetHost. 1230 // Dispatch incoming messages to the appropriate IPC::Listener.
1202 RenderWidgetHost* rwh = render_widget_hosts_.Lookup(msg.routing_id()); 1231 IPC::Listener* listener = listeners_.Lookup(msg.routing_id());
1203 if (!rwh) { 1232 if (!listener) {
1204 if (msg.is_sync()) { 1233 if (msg.is_sync()) {
1205 // The listener has gone away, so we must respond or else the caller will 1234 // The listener has gone away, so we must respond or else the caller will
1206 // hang waiting for a reply. 1235 // hang waiting for a reply.
1207 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); 1236 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg);
1208 reply->set_reply_error(); 1237 reply->set_reply_error();
1209 Send(reply); 1238 Send(reply);
1210 } 1239 }
1211 1240
1212 // If this is a SwapBuffers, we need to ack it if we're not going to handle 1241 // If this is a SwapBuffers, we need to ack it if we're not going to handle
1213 // it so that the GPU process doesn't get stuck in unscheduled state. 1242 // it so that the GPU process doesn't get stuck in unscheduled state.
1214 bool msg_is_ok = true; 1243 bool msg_is_ok = true;
1215 IPC_BEGIN_MESSAGE_MAP_EX(RenderProcessHostImpl, msg, msg_is_ok) 1244 IPC_BEGIN_MESSAGE_MAP_EX(RenderProcessHostImpl, msg, msg_is_ok)
1216 IPC_MESSAGE_HANDLER(ViewHostMsg_CompositorSurfaceBuffersSwapped, 1245 IPC_MESSAGE_HANDLER(ViewHostMsg_CompositorSurfaceBuffersSwapped,
1217 OnCompositorSurfaceBuffersSwappedNoHost) 1246 OnCompositorSurfaceBuffersSwappedNoHost)
1218 IPC_END_MESSAGE_MAP_EX() 1247 IPC_END_MESSAGE_MAP_EX()
1219 return true; 1248 return true;
1220 } 1249 }
1221 return RenderWidgetHostImpl::From(rwh)->OnMessageReceived(msg); 1250 return listener->OnMessageReceived(msg);
1222 } 1251 }
1223 1252
1224 void RenderProcessHostImpl::OnChannelConnected(int32 peer_pid) { 1253 void RenderProcessHostImpl::OnChannelConnected(int32 peer_pid) {
1225 #if defined(IPC_MESSAGE_LOG_ENABLED) 1254 #if defined(IPC_MESSAGE_LOG_ENABLED)
1226 Send(new ChildProcessMsg_SetIPCLoggingEnabled( 1255 Send(new ChildProcessMsg_SetIPCLoggingEnabled(
1227 IPC::Logging::GetInstance()->Enabled())); 1256 IPC::Logging::GetInstance()->Enabled()));
1228 #endif 1257 #endif
1229 1258
1230 tracked_objects::ThreadData::Status status = 1259 tracked_objects::ThreadData::Status status =
1231 tracked_objects::ThreadData::status(); 1260 tracked_objects::ThreadData::status();
(...skipping 14 matching lines...) Expand all
1246 } 1275 }
1247 1276
1248 int RenderProcessHostImpl::GetID() const { 1277 int RenderProcessHostImpl::GetID() const {
1249 return id_; 1278 return id_;
1250 } 1279 }
1251 1280
1252 bool RenderProcessHostImpl::HasConnection() const { 1281 bool RenderProcessHostImpl::HasConnection() const {
1253 return channel_.get() != NULL; 1282 return channel_.get() != NULL;
1254 } 1283 }
1255 1284
1256 RenderWidgetHost* RenderProcessHostImpl::GetRenderWidgetHostByID(
1257 int routing_id) {
1258 return render_widget_hosts_.Lookup(routing_id);
1259 }
1260
1261 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { 1285 void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) {
1262 ignore_input_events_ = ignore_input_events; 1286 ignore_input_events_ = ignore_input_events;
1263 } 1287 }
1264 1288
1265 bool RenderProcessHostImpl::IgnoreInputEvents() const { 1289 bool RenderProcessHostImpl::IgnoreInputEvents() const {
1266 return ignore_input_events_; 1290 return ignore_input_events_;
1267 } 1291 }
1268 1292
1269 void RenderProcessHostImpl::Attach(RenderWidgetHost* host,
1270 int routing_id) {
1271 render_widget_hosts_.AddWithID(host, routing_id);
1272 }
1273
1274 void RenderProcessHostImpl::Release(int routing_id) {
1275 DCHECK(render_widget_hosts_.Lookup(routing_id) != NULL);
1276 render_widget_hosts_.Remove(routing_id);
1277
1278 #if defined(OS_WIN)
1279 // Dump the handle table if handle auditing is enabled.
1280 const CommandLine& browser_command_line =
1281 *CommandLine::ForCurrentProcess();
1282 if (browser_command_line.HasSwitch(switches::kAuditHandles) ||
1283 browser_command_line.HasSwitch(switches::kAuditAllHandles)) {
1284 DumpHandles();
1285
1286 // We wait to close the channels until the child process has finished
1287 // dumping handles and sends us ChildProcessHostMsg_DumpHandlesDone.
1288 return;
1289 }
1290 #endif
1291 // Keep the one renderer thread around forever in single process mode.
1292 if (!run_renderer_in_process())
1293 Cleanup();
1294 }
1295
1296 void RenderProcessHostImpl::Cleanup() { 1293 void RenderProcessHostImpl::Cleanup() {
1297 // When no other owners of this object, we can delete ourselves 1294 // When no other owners of this object, we can delete ourselves
1298 if (render_widget_hosts_.IsEmpty()) { 1295 if (listeners_.IsEmpty()) {
1299 DCHECK_EQ(0, pending_views_); 1296 DCHECK_EQ(0, pending_views_);
1300 NotificationService::current()->Notify( 1297 NotificationService::current()->Notify(
1301 NOTIFICATION_RENDERER_PROCESS_TERMINATED, 1298 NOTIFICATION_RENDERER_PROCESS_TERMINATED,
1302 Source<RenderProcessHost>(this), 1299 Source<RenderProcessHost>(this),
1303 NotificationService::NoDetails()); 1300 NotificationService::NoDetails());
1304 1301
1305 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 1302 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
1306 deleting_soon_ = true; 1303 deleting_soon_ = true;
1307 // It's important not to wait for the DeleteTask to delete the channel 1304 // It's important not to wait for the DeleteTask to delete the channel
1308 // proxy. Kill it off now. That way, in case the profile is going away, the 1305 // proxy. Kill it off now. That way, in case the profile is going away, the
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1349 } 1346 }
1350 1347
1351 void RenderProcessHostImpl::ResumeRequestsForView(int route_id) { 1348 void RenderProcessHostImpl::ResumeRequestsForView(int route_id) {
1352 widget_helper_->ResumeRequestsForView(route_id); 1349 widget_helper_->ResumeRequestsForView(route_id);
1353 } 1350 }
1354 1351
1355 IPC::ChannelProxy* RenderProcessHostImpl::GetChannel() { 1352 IPC::ChannelProxy* RenderProcessHostImpl::GetChannel() {
1356 return channel_.get(); 1353 return channel_.get();
1357 } 1354 }
1358 1355
1359 RenderProcessHost::RenderWidgetHostsIterator
1360 RenderProcessHostImpl::GetRenderWidgetHostsIterator() {
1361 return RenderWidgetHostsIterator(&render_widget_hosts_);
1362 }
1363
1364 bool RenderProcessHostImpl::FastShutdownForPageCount(size_t count) { 1356 bool RenderProcessHostImpl::FastShutdownForPageCount(size_t count) {
1365 if (render_widget_hosts_.size() == count) 1357 if (static_cast<size_t>(GetActiveViewCount()) == count)
1366 return FastShutdownIfPossible(); 1358 return FastShutdownIfPossible();
1367 return false; 1359 return false;
1368 } 1360 }
1369 1361
1370 bool RenderProcessHostImpl::FastShutdownStarted() const { 1362 bool RenderProcessHostImpl::FastShutdownStarted() const {
1371 return fast_shutdown_started_; 1363 return fast_shutdown_started_;
1372 } 1364 }
1373 1365
1374 // static 1366 // static
1375 void RenderProcessHostImpl::RegisterHost(int host_id, RenderProcessHost* host) { 1367 void RenderProcessHostImpl::RegisterHost(int host_id, RenderProcessHost* host) {
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 RendererClosedDetails details(GetHandle(), status, exit_code); 1608 RendererClosedDetails details(GetHandle(), status, exit_code);
1617 NotificationService::current()->Notify( 1609 NotificationService::current()->Notify(
1618 NOTIFICATION_RENDERER_PROCESS_CLOSED, 1610 NOTIFICATION_RENDERER_PROCESS_CLOSED,
1619 Source<RenderProcessHost>(this), 1611 Source<RenderProcessHost>(this),
1620 Details<RendererClosedDetails>(&details)); 1612 Details<RendererClosedDetails>(&details));
1621 1613
1622 child_process_launcher_.reset(); 1614 child_process_launcher_.reset();
1623 channel_.reset(); 1615 channel_.reset();
1624 gpu_message_filter_ = NULL; 1616 gpu_message_filter_ = NULL;
1625 1617
1626 IDMap<RenderWidgetHost>::iterator iter(&render_widget_hosts_); 1618 RenderWidgetHost::List widgets = RenderWidgetHost::GetRenderWidgetHosts();
1627 while (!iter.IsAtEnd()) { 1619 for (RenderWidgetHost::List::const_iterator it = widgets.begin();
jam 2013/06/12 19:59:59 dito
nasko 2013/06/12 21:18:59 Done.
1628 RenderWidgetHostImpl::From(iter.GetCurrentValue())->OnMessageReceived( 1620 it != widgets.end(); ++it) {
1629 ViewHostMsg_RenderViewGone(iter.GetCurrentKey(), 1621 const RenderWidgetHost* widget = *it;
1630 static_cast<int>(status), 1622 if (widget->GetProcess()->GetID() != GetID())
1631 exit_code)); 1623 continue;
1632 iter.Advance(); 1624 RenderWidgetHostImpl::From(
1625 const_cast<RenderWidgetHost*>(widget))->OnMessageReceived(
1626 ViewHostMsg_RenderViewGone(widget->GetRoutingID(),
1627 static_cast<int>(status),
1628 exit_code));
1629
1633 } 1630 }
1634 1631
1635 ClearTransportDIBCache(); 1632 ClearTransportDIBCache();
1636 1633
1637 // this object is not deleted at this point and may be reused later. 1634 // this object is not deleted at this point and may be reused later.
1638 // TODO(darin): clean this up 1635 // TODO(darin): clean this up
1639 } 1636 }
1640 1637
1641 int RenderProcessHostImpl::GetActiveViewCount() { 1638 int RenderProcessHostImpl::GetActiveViewCount() {
1642 int num_active_views = 0; 1639 int num_active_views = 0;
1643 for (RenderWidgetHostsIterator iter = GetRenderWidgetHostsIterator(); 1640 RenderWidgetHost::List widgets = RenderWidgetHost::GetRenderWidgetHosts();
1644 !iter.IsAtEnd(); 1641 for (RenderWidgetHost::List::const_iterator it = widgets.begin();
1645 iter.Advance()) { 1642 it != widgets.end(); ++it) {
jam 2013/06/12 19:59:59 ditto
nasko 2013/06/12 21:18:59 Done.
1646 const RenderWidgetHost* widget = iter.GetCurrentValue(); 1643 const RenderWidgetHost* widget = *it;
1647 DCHECK(widget); 1644 DCHECK(widget);
1648 if (!widget) 1645 if (!widget)
1649 continue; 1646 continue;
1650 1647
1648 // Count only RenderWidgetHosts in this process.
1649 if (widget->GetProcess()->GetID() != GetID())
1650 continue;
1651
1651 // All RenderWidgetHosts are swapped in. 1652 // All RenderWidgetHosts are swapped in.
1652 if (!widget->IsRenderView()) { 1653 if (!widget->IsRenderView()) {
1653 num_active_views++; 1654 num_active_views++;
1654 continue; 1655 continue;
1655 } 1656 }
1656 1657
1657 // Don't count swapped out views. 1658 // Don't count swapped out views.
1658 RenderViewHost* rvh = 1659 RenderViewHost* rvh =
1659 RenderViewHost::From(const_cast<RenderWidgetHost*>(widget)); 1660 RenderViewHost::From(const_cast<RenderWidgetHost*>(widget));
1660 if (!static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out()) 1661 if (!static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out())
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1782 TRACE_EVENT0("renderer_host", 1783 TRACE_EVENT0("renderer_host",
1783 "RenderWidgetHostImpl::OnCompositorSurfaceBuffersSwappedNoHost"); 1784 "RenderWidgetHostImpl::OnCompositorSurfaceBuffersSwappedNoHost");
1784 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; 1785 AcceleratedSurfaceMsg_BufferPresented_Params ack_params;
1785 ack_params.sync_point = 0; 1786 ack_params.sync_point = 0;
1786 RenderWidgetHostImpl::AcknowledgeBufferPresent(params.route_id, 1787 RenderWidgetHostImpl::AcknowledgeBufferPresent(params.route_id,
1787 params.gpu_process_host_id, 1788 params.gpu_process_host_id,
1788 ack_params); 1789 ack_params);
1789 } 1790 }
1790 1791
1791 void RenderProcessHostImpl::OnGpuSwitching() { 1792 void RenderProcessHostImpl::OnGpuSwitching() {
1792 for (RenderWidgetHostsIterator iter = GetRenderWidgetHostsIterator(); 1793 RenderWidgetHost::List widgets = RenderWidgetHost::GetRenderWidgetHosts();
1793 !iter.IsAtEnd(); 1794 for (RenderWidgetHost::List::const_iterator it = widgets.begin();
1794 iter.Advance()) { 1795 it != widgets.end(); ++it) {
jam 2013/06/12 19:59:59 ditto
nasko 2013/06/12 21:18:59 Done.
1795 const RenderWidgetHost* widget = iter.GetCurrentValue(); 1796 const RenderWidgetHost* widget = *it;
1796 DCHECK(widget); 1797 DCHECK(widget);
1797 if (!widget || !widget->IsRenderView()) 1798 if (!widget || !widget->IsRenderView())
1798 continue; 1799 continue;
1799 1800
1801 // Skip widgets in other processes.
1802 if (widget->GetProcess()->GetID() != GetID())
1803 continue;
1804
1800 RenderViewHost* rvh = 1805 RenderViewHost* rvh =
1801 RenderViewHost::From(const_cast<RenderWidgetHost*>(widget)); 1806 RenderViewHost::From(const_cast<RenderWidgetHost*>(widget));
1802 1807
1803 rvh->UpdateWebkitPreferences(rvh->GetWebkitPreferences()); 1808 rvh->UpdateWebkitPreferences(rvh->GetWebkitPreferences());
1804 } 1809 }
1805 } 1810 }
1806 1811
1807 } // namespace content 1812 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698