| 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::EnsureHasChannel() { |
| 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 1125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2161 connection_filter_id_ = | 2170 connection_filter_id_ = |
| 2162 ServiceManagerConnection::kInvalidConnectionFilterId; | 2171 ServiceManagerConnection::kInvalidConnectionFilterId; |
| 2163 } | 2172 } |
| 2164 | 2173 |
| 2165 #ifndef NDEBUG | 2174 #ifndef NDEBUG |
| 2166 is_self_deleted_ = true; | 2175 is_self_deleted_ = true; |
| 2167 #endif | 2176 #endif |
| 2168 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 2177 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| 2169 deleting_soon_ = true; | 2178 deleting_soon_ = true; |
| 2170 | 2179 |
| 2171 #if USE_ATTACHMENT_BROKER | |
| 2172 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | |
| 2173 channel_.get()); | |
| 2174 #endif | |
| 2175 | |
| 2176 // It's important not to wait for the DeleteTask to delete the channel | 2180 // It's important not to wait for the DeleteTask to delete the channel |
| 2177 // proxy. Kill it off now. That way, in case the profile is going away, the | 2181 // proxy. Kill it off now. That way, in case the profile is going away, the |
| 2178 // rest of the objects attached to this RenderProcessHost start going | 2182 // rest of the objects attached to this RenderProcessHost start going |
| 2179 // away first, since deleting the channel proxy will post a | 2183 // away first, since deleting the channel proxy will post a |
| 2180 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. | 2184 // OnChannelClosed() to IPC::ChannelProxy::Context on the IO thread. |
| 2181 channel_.reset(); | 2185 ResetChannelProxy(); |
| 2182 | 2186 |
| 2183 // The following members should be cleared in ProcessDied() as well! | 2187 // The following members should be cleared in ProcessDied() as well! |
| 2184 message_port_message_filter_ = NULL; | 2188 message_port_message_filter_ = NULL; |
| 2185 | 2189 |
| 2186 // Its important to remove the kSessionStorageHolder after the channel | 2190 // Its important to remove the kSessionStorageHolder after the channel |
| 2187 // has been reset to avoid deleting the underlying namespaces prior | 2191 // has been reset to avoid deleting the underlying namespaces prior |
| 2188 // to processing ipcs referring to them. | 2192 // to processing ipcs referring to them. |
| 2189 DCHECK(!channel_); | 2193 DCHECK(!channel_); |
| 2190 RemoveUserData(kSessionStorageHolderKey); | 2194 RemoveUserData(kSessionStorageHolderKey); |
| 2191 | 2195 |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2658 // TERMINATION_STATUS_STILL_RUNNING, since this will break WebContentsImpl | 2662 // TERMINATION_STATUS_STILL_RUNNING, since this will break WebContentsImpl |
| 2659 // logic. | 2663 // logic. |
| 2660 status = base::TERMINATION_STATUS_PROCESS_CRASHED; | 2664 status = base::TERMINATION_STATUS_PROCESS_CRASHED; |
| 2661 } | 2665 } |
| 2662 } | 2666 } |
| 2663 | 2667 |
| 2664 RendererClosedDetails details(status, exit_code); | 2668 RendererClosedDetails details(status, exit_code); |
| 2665 | 2669 |
| 2666 child_process_launcher_.reset(); | 2670 child_process_launcher_.reset(); |
| 2667 is_dead_ = true; | 2671 is_dead_ = true; |
| 2668 | 2672 ResetChannelProxy(); |
| 2669 // Clear all cached associated interface proxies as well, since these are | |
| 2670 // effectively bound to the lifetime of the Channel. | |
| 2671 remote_route_provider_.reset(); | |
| 2672 renderer_interface_.reset(); | |
| 2673 | 2673 |
| 2674 UpdateProcessPriority(); | 2674 UpdateProcessPriority(); |
| 2675 DCHECK(!is_process_backgrounded_); | 2675 DCHECK(!is_process_backgrounded_); |
| 2676 | 2676 |
| 2677 within_process_died_observer_ = true; | 2677 within_process_died_observer_ = true; |
| 2678 NotificationService::current()->Notify( | 2678 NotificationService::current()->Notify( |
| 2679 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), | 2679 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), |
| 2680 Details<RendererClosedDetails>(&details)); | 2680 Details<RendererClosedDetails>(&details)); |
| 2681 for (auto& observer : observers_) | 2681 for (auto& observer : observers_) |
| 2682 observer.RenderProcessExited(this, status, exit_code); | 2682 observer.RenderProcessExited(this, status, exit_code); |
| 2683 within_process_died_observer_ = false; | 2683 within_process_died_observer_ = false; |
| 2684 | 2684 |
| 2685 message_port_message_filter_ = NULL; | 2685 message_port_message_filter_ = NULL; |
| 2686 | 2686 |
| 2687 RemoveUserData(kSessionStorageHolderKey); | 2687 RemoveUserData(kSessionStorageHolderKey); |
| 2688 | 2688 |
| 2689 IDMap<IPC::Listener>::iterator iter(&listeners_); | 2689 IDMap<IPC::Listener>::iterator iter(&listeners_); |
| 2690 while (!iter.IsAtEnd()) { | 2690 while (!iter.IsAtEnd()) { |
| 2691 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( | 2691 iter.GetCurrentValue()->OnMessageReceived(FrameHostMsg_RenderProcessGone( |
| 2692 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); | 2692 iter.GetCurrentKey(), static_cast<int>(status), exit_code)); |
| 2693 iter.Advance(); | 2693 iter.Advance(); |
| 2694 } | 2694 } |
| 2695 | 2695 |
| 2696 // Initialize a new ChannelProxy in case this host is re-used for a new | 2696 // Initialize a new ChannelProxy in case this host is re-used for a new |
| 2697 // process. This ensures that new messages can be sent on the host ASAP (even | 2697 // process. This ensures that new messages can be sent on the host ASAP (even |
| 2698 // before Init()) and they'll eventually reach the new process. | 2698 // before Init()) and they'll eventually reach the new process. |
| 2699 InitializeChannelProxy(); | 2699 // |
| 2700 // Note that this may have already been called by one of the above observers |
| 2701 EnsureHasChannel(); |
| 2700 | 2702 |
| 2701 // It's possible that one of the calls out to the observers might have caused | 2703 // It's possible that one of the calls out to the observers might have caused |
| 2702 // this object to be no longer needed. | 2704 // this object to be no longer needed. |
| 2703 if (delayed_cleanup_needed_) | 2705 if (delayed_cleanup_needed_) |
| 2704 Cleanup(); | 2706 Cleanup(); |
| 2705 | 2707 |
| 2706 // This object is not deleted at this point and might be reused later. | 2708 // This object is not deleted at this point and might be reused later. |
| 2707 // TODO(darin): clean this up | 2709 // TODO(darin): clean this up |
| 2708 } | 2710 } |
| 2709 | 2711 |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3005 bad_message::ReceivedBadMessage(render_process_id, | 3007 bad_message::ReceivedBadMessage(render_process_id, |
| 3006 bad_message::RPH_MOJO_PROCESS_ERROR); | 3008 bad_message::RPH_MOJO_PROCESS_ERROR); |
| 3007 } | 3009 } |
| 3008 | 3010 |
| 3009 void RenderProcessHostImpl::CreateURLLoaderFactory( | 3011 void RenderProcessHostImpl::CreateURLLoaderFactory( |
| 3010 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) { | 3012 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) { |
| 3011 URLLoaderFactoryImpl::Create(resource_message_filter_, std::move(request)); | 3013 URLLoaderFactoryImpl::Create(resource_message_filter_, std::move(request)); |
| 3012 } | 3014 } |
| 3013 | 3015 |
| 3014 } // namespace content | 3016 } // namespace content |
| OLD | NEW |