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 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 if (renderer_path.empty()) | 823 if (renderer_path.empty()) |
824 return false; | 824 return false; |
825 | 825 |
826 sent_render_process_ready_ = false; | 826 sent_render_process_ready_ = false; |
827 | 827 |
828 // We may reach Init() during process death notification (e.g. | 828 // We may reach Init() during process death notification (e.g. |
829 // RenderProcessExited on some observer). In this case the Channel may be | 829 // RenderProcessExited on some observer). In this case the Channel may be |
830 // null, so we re-initialize it here. | 830 // null, so we re-initialize it here. |
831 if (!channel_) | 831 if (!channel_) |
832 InitializeChannelProxy(); | 832 InitializeChannelProxy(); |
| 833 DCHECK(pending_connection_); |
833 | 834 |
834 // Unpause the Channel briefly. This will be paused again below if we launch a | 835 // Unpause the Channel briefly. This will be paused again below if we launch a |
835 // real child process. Note that messages may be sent in the short window | 836 // real child process. Note that messages may be sent in the short window |
836 // between now and then (e.g. in response to RenderProcessWillLaunch) and we | 837 // between now and then (e.g. in response to RenderProcessWillLaunch) and we |
837 // depend on those messages being sent right away. | 838 // depend on those messages being sent right away. |
838 // | 839 // |
839 // |channel_| must always be non-null here: either it was initialized in | 840 // |channel_| must always be non-null here: either it was initialized in |
840 // the constructor, or in the most recent call to ProcessDied(). | 841 // the constructor, or in the most recent call to ProcessDied(). |
841 channel_->Unpause(false /* flush */); | 842 channel_->Unpause(false /* flush */); |
842 | 843 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 base::MakeUnique<base::CommandLine>(renderer_path); | 904 base::MakeUnique<base::CommandLine>(renderer_path); |
904 if (!renderer_prefix.empty()) | 905 if (!renderer_prefix.empty()) |
905 cmd_line->PrependWrapper(renderer_prefix); | 906 cmd_line->PrependWrapper(renderer_prefix); |
906 AppendRendererCommandLine(cmd_line.get()); | 907 AppendRendererCommandLine(cmd_line.get()); |
907 | 908 |
908 // Spawn the child process asynchronously to avoid blocking the UI thread. | 909 // Spawn the child process asynchronously to avoid blocking the UI thread. |
909 // As long as there's no renderer prefix, we can use the zygote process | 910 // As long as there's no renderer prefix, we can use the zygote process |
910 // at this stage. | 911 // at this stage. |
911 child_process_launcher_.reset(new ChildProcessLauncher( | 912 child_process_launcher_.reset(new ChildProcessLauncher( |
912 base::MakeUnique<RendererSandboxedProcessLauncherDelegate>(), | 913 base::MakeUnique<RendererSandboxedProcessLauncherDelegate>(), |
913 std::move(cmd_line), GetID(), this, child_token_, | 914 std::move(cmd_line), GetID(), this, std::move(pending_connection_), |
914 base::Bind(&RenderProcessHostImpl::OnMojoError, id_))); | 915 base::Bind(&RenderProcessHostImpl::OnMojoError, id_))); |
915 channel_->Pause(); | 916 channel_->Pause(); |
916 | 917 |
917 fast_shutdown_started_ = false; | 918 fast_shutdown_started_ = false; |
918 } | 919 } |
919 | 920 |
920 if (!gpu_observer_registered_) { | 921 if (!gpu_observer_registered_) { |
921 gpu_observer_registered_ = true; | 922 gpu_observer_registered_ = true; |
922 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); | 923 ui::GpuSwitchingManager::GetInstance()->AddObserver(this); |
923 } | 924 } |
924 | 925 |
925 is_initialized_ = true; | 926 is_initialized_ = true; |
926 init_time_ = base::TimeTicks::Now(); | 927 init_time_ = base::TimeTicks::Now(); |
927 return true; | 928 return true; |
928 } | 929 } |
929 | 930 |
930 void RenderProcessHostImpl::EnableSendQueue() { | 931 void RenderProcessHostImpl::EnableSendQueue() { |
931 if (!channel_) | 932 if (!channel_) |
932 InitializeChannelProxy(); | 933 InitializeChannelProxy(); |
933 } | 934 } |
934 | 935 |
935 void RenderProcessHostImpl::InitializeChannelProxy() { | 936 void RenderProcessHostImpl::InitializeChannelProxy() { |
936 // Generate a token used to identify the new child process. | |
937 child_token_ = mojo::edk::GenerateRandomToken(); | |
938 | |
939 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = | 937 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = |
940 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); | 938 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); |
941 | 939 |
942 // Acquire a Connector which will route connections to a new instance of the | 940 // Acquire a Connector which will route connections to a new instance of the |
943 // renderer service. | 941 // renderer service. |
944 service_manager::Connector* connector = | 942 service_manager::Connector* connector = |
945 BrowserContext::GetConnectorFor(browser_context_); | 943 BrowserContext::GetConnectorFor(browser_context_); |
946 if (!connector) { | 944 if (!connector) { |
947 // Note that some embedders (e.g. Android WebView) may not initialize a | 945 // Note that some embedders (e.g. Android WebView) may not initialize a |
948 // Connector per BrowserContext. In those cases we fall back to the | 946 // Connector per BrowserContext. In those cases we fall back to the |
949 // browser-wide Connector. | 947 // browser-wide Connector. |
950 if (!ServiceManagerConnection::GetForProcess()) { | 948 if (!ServiceManagerConnection::GetForProcess()) { |
951 // Additionally, some test code may not initialize the process-wide | 949 // Additionally, some test code may not initialize the process-wide |
952 // ServiceManagerConnection prior to this point. This class of test code | 950 // ServiceManagerConnection prior to this point. This class of test code |
953 // doesn't care about render processes, so we can initialize a dummy | 951 // doesn't care about render processes, so we can initialize a dummy |
954 // connection. | 952 // connection. |
955 service_manager::mojom::ServiceRequest request(&test_service_); | 953 service_manager::mojom::ServiceRequest request(&test_service_); |
956 ServiceManagerConnection::SetForProcess(ServiceManagerConnection::Create( | 954 ServiceManagerConnection::SetForProcess(ServiceManagerConnection::Create( |
957 std::move(request), io_task_runner)); | 955 std::move(request), io_task_runner)); |
958 } | 956 } |
959 connector = ServiceManagerConnection::GetForProcess()->GetConnector(); | 957 connector = ServiceManagerConnection::GetForProcess()->GetConnector(); |
960 } | 958 } |
961 | 959 |
962 // Establish a ServiceManager connection for the new render service instance. | 960 // Establish a ServiceManager connection for the new render service instance. |
| 961 pending_connection_.reset(new mojo::edk::PendingProcessConnection); |
963 child_connection_.reset(new ChildConnection( | 962 child_connection_.reset(new ChildConnection( |
964 mojom::kRendererServiceName, | 963 mojom::kRendererServiceName, |
965 base::StringPrintf("%d_%d", id_, instance_id_++), child_token_, connector, | 964 base::StringPrintf("%d_%d", id_, instance_id_++), |
966 io_task_runner)); | 965 pending_connection_.get(), connector, io_task_runner)); |
967 | 966 |
968 // Send an interface request to bootstrap the IPC::Channel. Note that this | 967 // Send an interface request to bootstrap the IPC::Channel. Note that this |
969 // request will happily sit on the pipe until the process is launched and | 968 // request will happily sit on the pipe until the process is launched and |
970 // connected to the ServiceManager. We take the other end immediately and | 969 // connected to the ServiceManager. We take the other end immediately and |
971 // plug it into a new ChannelProxy. | 970 // plug it into a new ChannelProxy. |
972 IPC::mojom::ChannelBootstrapPtr bootstrap; | 971 IPC::mojom::ChannelBootstrapPtr bootstrap; |
973 GetRemoteInterfaces()->GetInterface(&bootstrap); | 972 GetRemoteInterfaces()->GetInterface(&bootstrap); |
974 std::unique_ptr<IPC::ChannelFactory> channel_factory = | 973 std::unique_ptr<IPC::ChannelFactory> channel_factory = |
975 IPC::ChannelMojo::CreateServerFactory( | 974 IPC::ChannelMojo::CreateServerFactory( |
976 bootstrap.PassInterface().PassHandle(), io_task_runner); | 975 bootstrap.PassInterface().PassHandle(), io_task_runner); |
(...skipping 2099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3076 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 3075 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
3077 | 3076 |
3078 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. | 3077 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. |
3079 // Capture the error message in a crash key value. | 3078 // Capture the error message in a crash key value. |
3080 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); | 3079 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); |
3081 bad_message::ReceivedBadMessage(render_process_id, | 3080 bad_message::ReceivedBadMessage(render_process_id, |
3082 bad_message::RPH_MOJO_PROCESS_ERROR); | 3081 bad_message::RPH_MOJO_PROCESS_ERROR); |
3083 } | 3082 } |
3084 | 3083 |
3085 } // namespace content | 3084 } // namespace content |
OLD | NEW |