OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); | 921 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); |
922 } | 922 } |
923 | 923 |
924 power_monitor_broadcaster_.Init(); | 924 power_monitor_broadcaster_.Init(); |
925 | 925 |
926 is_initialized_ = true; | 926 is_initialized_ = true; |
927 init_time_ = base::TimeTicks::Now(); | 927 init_time_ = base::TimeTicks::Now(); |
928 return true; | 928 return true; |
929 } | 929 } |
930 | 930 |
| 931 void RenderProcessHostImpl::EnableSendQueue() { |
| 932 if (!channel_) |
| 933 InitializeChannelProxy(); |
| 934 } |
| 935 |
931 void RenderProcessHostImpl::InitializeChannelProxy() { | 936 void RenderProcessHostImpl::InitializeChannelProxy() { |
932 // Generate a token used to identify the new child process. | 937 // Generate a token used to identify the new child process. |
933 child_token_ = mojo::edk::GenerateRandomToken(); | 938 child_token_ = mojo::edk::GenerateRandomToken(); |
934 | 939 |
935 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = | 940 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = |
936 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); | 941 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); |
937 | 942 |
938 // Acquire a Connector which will route connections to a new instance of the | 943 // Acquire a Connector which will route connections to a new instance of the |
939 // renderer service. | 944 // renderer service. |
940 service_manager::Connector* connector = | 945 service_manager::Connector* connector = |
(...skipping 24 matching lines...) Expand all Loading... |
965 // Send an interface request to bootstrap the IPC::Channel. Note that this | 970 // Send an interface request to bootstrap the IPC::Channel. Note that this |
966 // request will happily sit on the pipe until the process is launched and | 971 // request will happily sit on the pipe until the process is launched and |
967 // connected to the ServiceManager. We take the other end immediately and | 972 // connected to the ServiceManager. We take the other end immediately and |
968 // plug it into a new ChannelProxy. | 973 // plug it into a new ChannelProxy. |
969 IPC::mojom::ChannelBootstrapPtr bootstrap; | 974 IPC::mojom::ChannelBootstrapPtr bootstrap; |
970 GetRemoteInterfaces()->GetInterface(&bootstrap); | 975 GetRemoteInterfaces()->GetInterface(&bootstrap); |
971 std::unique_ptr<IPC::ChannelFactory> channel_factory = | 976 std::unique_ptr<IPC::ChannelFactory> channel_factory = |
972 IPC::ChannelMojo::CreateServerFactory( | 977 IPC::ChannelMojo::CreateServerFactory( |
973 bootstrap.PassInterface().PassHandle(), io_task_runner); | 978 bootstrap.PassInterface().PassHandle(), io_task_runner); |
974 | 979 |
975 #if USE_ATTACHMENT_BROKER | 980 ResetChannelProxy(); |
976 if (channel_) { | |
977 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | |
978 channel_.get()); | |
979 } | |
980 #endif | |
981 | |
982 channel_.reset(); | |
983 channel_connected_ = false; | |
984 | 981 |
985 // Do NOT expand ifdef or run time condition checks here! Synchronous | 982 // Do NOT expand ifdef or run time condition checks here! Synchronous |
986 // IPCs from browser process are banned. It is only narrowly allowed | 983 // IPCs from browser process are banned. It is only narrowly allowed |
987 // for Android WebView to maintain backward compatibility. | 984 // for Android WebView to maintain backward compatibility. |
988 // See crbug.com/526842 for details. | 985 // See crbug.com/526842 for details. |
989 #if defined(OS_ANDROID) | 986 #if defined(OS_ANDROID) |
990 if (GetContentClient()->UsingSynchronousCompositing()) { | 987 if (GetContentClient()->UsingSynchronousCompositing()) { |
991 channel_ = IPC::SyncChannel::Create( | 988 channel_ = IPC::SyncChannel::Create( |
992 this, io_task_runner.get(), &never_signaled_); | 989 this, io_task_runner.get(), &never_signaled_); |
993 } | 990 } |
(...skipping 22 matching lines...) Expand all Loading... |
1016 // See OnProcessLaunched() for some additional details of this somewhat | 1013 // See OnProcessLaunched() for some additional details of this somewhat |
1017 // surprising behavior. | 1014 // surprising behavior. |
1018 channel_->GetRemoteAssociatedInterface(&remote_route_provider_); | 1015 channel_->GetRemoteAssociatedInterface(&remote_route_provider_); |
1019 channel_->GetRemoteAssociatedInterface(&renderer_interface_); | 1016 channel_->GetRemoteAssociatedInterface(&renderer_interface_); |
1020 | 1017 |
1021 // We start the Channel in a paused state. It will be briefly unpaused again | 1018 // We start the Channel in a paused state. It will be briefly unpaused again |
1022 // in Init() if applicable, before process launch is initiated. | 1019 // in Init() if applicable, before process launch is initiated. |
1023 channel_->Pause(); | 1020 channel_->Pause(); |
1024 } | 1021 } |
1025 | 1022 |
| 1023 void RenderProcessHostImpl::ResetChannelProxy() { |
| 1024 if (!channel_) |
| 1025 return; |
| 1026 |
| 1027 #if USE_ATTACHMENT_BROKER |
| 1028 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( |
| 1029 channel_.get()); |
| 1030 #endif |
| 1031 channel_.reset(); |
| 1032 channel_connected_ = false; |
| 1033 } |
| 1034 |
1026 void RenderProcessHostImpl::CreateMessageFilters() { | 1035 void RenderProcessHostImpl::CreateMessageFilters() { |
1027 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1036 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1028 AddFilter(new ResourceSchedulerFilter(GetID())); | 1037 AddFilter(new ResourceSchedulerFilter(GetID())); |
1029 MediaInternals* media_internals = MediaInternals::GetInstance(); | 1038 MediaInternals* media_internals = MediaInternals::GetInstance(); |
1030 // Add BrowserPluginMessageFilter to ensure it gets the first stab at messages | 1039 // Add BrowserPluginMessageFilter to ensure it gets the first stab at messages |
1031 // from guests. | 1040 // from guests. |
1032 scoped_refptr<BrowserPluginMessageFilter> bp_message_filter( | 1041 scoped_refptr<BrowserPluginMessageFilter> bp_message_filter( |
1033 new BrowserPluginMessageFilter(GetID())); | 1042 new BrowserPluginMessageFilter(GetID())); |
1034 AddFilter(bp_message_filter.get()); | 1043 AddFilter(bp_message_filter.get()); |
1035 | 1044 |
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2159 connection_filter_id_ = | 2168 connection_filter_id_ = |
2160 ServiceManagerConnection::kInvalidConnectionFilterId; | 2169 ServiceManagerConnection::kInvalidConnectionFilterId; |
2161 } | 2170 } |
2162 | 2171 |
2163 #ifndef NDEBUG | 2172 #ifndef NDEBUG |
2164 is_self_deleted_ = true; | 2173 is_self_deleted_ = true; |
2165 #endif | 2174 #endif |
2166 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 2175 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
2167 deleting_soon_ = true; | 2176 deleting_soon_ = true; |
2168 | 2177 |
2169 #if USE_ATTACHMENT_BROKER | |
2170 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | |
2171 channel_.get()); | |
2172 #endif | |
2173 | |
2174 // It's important not to wait for the DeleteTask to delete the channel | 2178 // It's important not to wait for the DeleteTask to delete the channel |
2175 // proxy. Kill it off now. That way, in case the profile is going away, the | 2179 // proxy. Kill it off now. That way, in case the profile is going away, the |
2176 // rest of the objects attached to this RenderProcessHost start going | 2180 // rest of the objects attached to this RenderProcessHost start going |
2177 // away first, since deleting the channel proxy will post a | 2181 // away first, since deleting the channel proxy will post a |
2178 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. | 2182 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. |
2179 channel_.reset(); | 2183 ResetChannelProxy(); |
2180 | 2184 |
2181 // The following members should be cleared in ProcessDied() as well! | 2185 // The following members should be cleared in ProcessDied() as well! |
2182 message_port_message_filter_ = NULL; | 2186 message_port_message_filter_ = NULL; |
2183 | 2187 |
2184 // Its important to remove the kSessionStorageHolder after the channel | 2188 // Its important to remove the kSessionStorageHolder after the channel |
2185 // has been reset to avoid deleting the underlying namespaces prior | 2189 // has been reset to avoid deleting the underlying namespaces prior |
2186 // to processing ipcs referring to them. | 2190 // to processing ipcs referring to them. |
2187 DCHECK(!channel_); | 2191 DCHECK(!channel_); |
2188 RemoveUserData(kSessionStorageHolderKey); | 2192 RemoveUserData(kSessionStorageHolderKey); |
2189 | 2193 |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2656 // TERMINATION_STATUS_STILL_RUNNING, since this will break WebContentsImpl | 2660 // TERMINATION_STATUS_STILL_RUNNING, since this will break WebContentsImpl |
2657 // logic. | 2661 // logic. |
2658 status = base::TERMINATION_STATUS_PROCESS_CRASHED; | 2662 status = base::TERMINATION_STATUS_PROCESS_CRASHED; |
2659 } | 2663 } |
2660 } | 2664 } |
2661 | 2665 |
2662 RendererClosedDetails details(status, exit_code); | 2666 RendererClosedDetails details(status, exit_code); |
2663 | 2667 |
2664 child_process_launcher_.reset(); | 2668 child_process_launcher_.reset(); |
2665 is_dead_ = true; | 2669 is_dead_ = true; |
2666 | 2670 ResetChannelProxy(); |
2667 // Clear all cached associated interface proxies as well, since these are | |
2668 // effectively bound to the lifetime of the Channel. | |
2669 remote_route_provider_.reset(); | |
2670 renderer_interface_.reset(); | |
2671 | 2671 |
2672 UpdateProcessPriority(); | 2672 UpdateProcessPriority(); |
2673 DCHECK(!is_process_backgrounded_); | 2673 DCHECK(!is_process_backgrounded_); |
2674 | 2674 |
2675 within_process_died_observer_ = true; | 2675 within_process_died_observer_ = true; |
2676 NotificationService::current()->Notify( | 2676 NotificationService::current()->Notify( |
2677 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), | 2677 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), |
2678 Details<RendererClosedDetails>(&details)); | 2678 Details<RendererClosedDetails>(&details)); |
2679 for (auto& observer : observers_) | 2679 for (auto& observer : observers_) |
2680 observer.RenderProcessExited(this, status, exit_code); | 2680 observer.RenderProcessExited(this, status, exit_code); |
2681 within_process_died_observer_ = false; | 2681 within_process_died_observer_ = false; |
2682 | 2682 |
2683 message_port_message_filter_ = NULL; | 2683 message_port_message_filter_ = NULL; |
2684 | 2684 |
2685 RemoveUserData(kSessionStorageHolderKey); | 2685 RemoveUserData(kSessionStorageHolderKey); |
2686 | 2686 |
2687 IDMap<IPC::Listener>::iterator iter(&listeners_); | 2687 IDMap<IPC::Listener>::iterator iter(&listeners_); |
2688 while (!iter.IsAtEnd()) { | 2688 while (!iter.IsAtEnd()) { |
2689 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( | 2689 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( |
2690 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); | 2690 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); |
2691 iter.Advance(); | 2691 iter.Advance(); |
2692 } | 2692 } |
2693 | 2693 |
2694 // Initialize a new ChannelProxy in case this host is re-used for a new | 2694 // Initialize a new ChannelProxy in case this host is re-used for a new |
2695 // process. This ensures that new messages can be sent on the host ASAP (even | 2695 // process. This ensures that new messages can be sent on the host ASAP (even |
2696 // before Init()) and they'll eventually reach the new process. | 2696 // before Init()) and they'll eventually reach the new process. |
2697 InitializeChannelProxy(); | 2697 // |
| 2698 // Note that this may have already been called by one of the above observers |
| 2699 EnableSendQueue(); |
2698 | 2700 |
2699 // It's possible that one of the calls out to the observers might have caused | 2701 // It's possible that one of the calls out to the observers might have caused |
2700 // this object to be no longer needed. | 2702 // this object to be no longer needed. |
2701 if (delayed_cleanup_needed_) | 2703 if (delayed_cleanup_needed_) |
2702 Cleanup(); | 2704 Cleanup(); |
2703 | 2705 |
2704 // This object is not deleted at this point and might be reused later. | 2706 // This object is not deleted at this point and might be reused later. |
2705 // TODO(darin): clean this up | 2707 // TODO(darin): clean this up |
2706 } | 2708 } |
2707 | 2709 |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3003 bad_message::ReceivedBadMessage(render_process_id, | 3005 bad_message::ReceivedBadMessage(render_process_id, |
3004 bad_message::RPH_MOJO_PROCESS_ERROR); | 3006 bad_message::RPH_MOJO_PROCESS_ERROR); |
3005 } | 3007 } |
3006 | 3008 |
3007 void RenderProcessHostImpl::CreateURLLoaderFactory( | 3009 void RenderProcessHostImpl::CreateURLLoaderFactory( |
3008 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) { | 3010 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) { |
3009 URLLoaderFactoryImpl::Create(resource_message_filter_, std::move(request)); | 3011 URLLoaderFactoryImpl::Create(resource_message_filter_, std::move(request)); |
3010 } | 3012 } |
3011 | 3013 |
3012 } // namespace content | 3014 } // namespace content |
OLD | NEW |