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

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

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

Powered by Google App Engine
This is Rietveld 408576698