Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "content/browser/mojo/mojo_child_connection.h" | 5 #include "content/browser/mojo/mojo_child_connection.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/content_browser_client.h" | |
| 15 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
| 16 #include "content/public/browser/render_process_host_observer.h" | 17 #include "content/public/browser/render_process_host_observer.h" |
| 18 #include "content/public/common/content_client.h" | |
| 17 #include "content/public/common/mojo_shell_connection.h" | 19 #include "content/public/common/mojo_shell_connection.h" |
| 20 #include "content/public/common/process_type.h" | |
| 18 #include "ipc/ipc_sender.h" | 21 #include "ipc/ipc_sender.h" |
| 19 #include "mojo/converters/network/network_type_converters.h" | 22 #include "mojo/converters/network/network_type_converters.h" |
| 20 #include "mojo/edk/embedder/embedder.h" | 23 #include "mojo/edk/embedder/embedder.h" |
| 21 #include "mojo/public/cpp/system/message_pipe.h" | 24 #include "mojo/public/cpp/system/message_pipe.h" |
| 22 #include "mojo/shell/public/cpp/connector.h" | 25 #include "mojo/shell/public/cpp/connector.h" |
| 23 #include "mojo/shell/public/interfaces/shell.mojom.h" | 26 #include "mojo/shell/public/interfaces/shell.mojom.h" |
| 24 #include "mojo/shell/public/interfaces/shell_client.mojom.h" | 27 #include "mojo/shell/public/interfaces/shell_client.mojom.h" |
| 25 | 28 |
| 26 namespace content { | 29 namespace content { |
| 27 namespace { | 30 namespace { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 std::string pipe_token = mojo::edk::GenerateRandomToken(); | 97 std::string pipe_token = mojo::edk::GenerateRandomToken(); |
| 95 mojo::ScopedMessagePipeHandle shell_client_pipe = | 98 mojo::ScopedMessagePipeHandle shell_client_pipe = |
| 96 mojo::edk::CreateParentMessagePipe(pipe_token); | 99 mojo::edk::CreateParentMessagePipe(pipe_token); |
| 97 | 100 |
| 98 // Some process types get created before the main message loop. In this case | 101 // Some process types get created before the main message loop. In this case |
| 99 // the shell request pipe will simply be closed, and the child can detect | 102 // the shell request pipe will simply be closed, and the child can detect |
| 100 // this. | 103 // this. |
| 101 if (!MojoShellConnection::Get()) | 104 if (!MojoShellConnection::Get()) |
| 102 return pipe_token; | 105 return pipe_token; |
| 103 | 106 |
| 107 std::string child_name = | |
| 108 GetContentClient()->browser()->GetMojoApplicationNameForProcess( | |
|
Ben Goodger (Google)
2016/03/24 22:53:54
instead of doing this, I think we should probably
| |
| 109 PROCESS_TYPE_RENDERER); | |
| 110 if (child_name.empty()) | |
| 111 return pipe_token; | |
| 112 | |
| 104 mojo::shell::mojom::ShellClientPtr client; | 113 mojo::shell::mojom::ShellClientPtr client; |
| 105 client.Bind(mojo::InterfacePtrInfo<mojo::shell::mojom::ShellClient>( | 114 client.Bind(mojo::InterfacePtrInfo<mojo::shell::mojom::ShellClient>( |
| 106 std::move(shell_client_pipe), 0u)); | 115 std::move(shell_client_pipe), 0u)); |
| 107 mojo::shell::mojom::PIDReceiverPtr pid_receiver; | 116 mojo::shell::mojom::PIDReceiverPtr pid_receiver; |
| 108 mojo::shell::mojom::PIDReceiverRequest pid_receiver_request = | 117 mojo::shell::mojom::PIDReceiverRequest pid_receiver_request = |
| 109 GetProxy(&pid_receiver); | 118 GetProxy(&pid_receiver); |
| 110 // PIDSender manages its own lifetime. | 119 // PIDSender manages its own lifetime. |
| 111 new PIDSender(render_process_host, std::move(pid_receiver)); | 120 new PIDSender(render_process_host, std::move(pid_receiver)); |
| 112 | 121 |
| 113 | 122 mojo::Identity target(child_name, mojo::shell::mojom::kInheritUserID, |
| 114 mojo::Identity target("exe:chrome_renderer", | |
| 115 mojo::shell::mojom::kInheritUserID, | |
| 116 base::StringPrintf("%d_%d", child_process_id, | 123 base::StringPrintf("%d_%d", child_process_id, |
| 117 instance_id)); | 124 instance_id)); |
| 118 mojo::Connector::ConnectParams params(target); | 125 mojo::Connector::ConnectParams params(target); |
| 119 params.set_client_process_connection(std::move(client), | 126 params.set_client_process_connection(std::move(client), |
| 120 std::move(pid_receiver_request)); | 127 std::move(pid_receiver_request)); |
| 121 scoped_ptr<mojo::Connection> connection = | 128 scoped_ptr<mojo::Connection> connection = |
| 122 MojoShellConnection::Get()->GetConnector()->Connect(¶ms); | 129 MojoShellConnection::Get()->GetConnector()->Connect(¶ms); |
| 123 | 130 |
| 124 // Store the connection on the RPH so client code can access it later via | 131 // Store the connection on the RPH so client code can access it later via |
| 125 // GetMojoConnection(). | 132 // GetMojoConnection(). |
| 126 SetMojoConnection(render_process_host, std::move(connection)); | 133 SetMojoConnection(render_process_host, std::move(connection)); |
| 127 | 134 |
| 128 return pipe_token; | 135 return pipe_token; |
| 129 } | 136 } |
| 130 | 137 |
| 131 mojo::Connection* GetMojoConnection(RenderProcessHost* render_process_host) { | 138 mojo::Connection* GetMojoConnection(RenderProcessHost* render_process_host) { |
| 132 RenderProcessHostConnection* connection = | 139 RenderProcessHostConnection* connection = |
| 133 static_cast<RenderProcessHostConnection*>( | 140 static_cast<RenderProcessHostConnection*>( |
| 134 render_process_host->GetUserData(kMojoRenderProcessHostConnection)); | 141 render_process_host->GetUserData(kMojoRenderProcessHostConnection)); |
| 135 return connection ? connection->get() : nullptr; | 142 return connection ? connection->get() : nullptr; |
| 136 } | 143 } |
| 137 | 144 |
| 138 } // namespace content | 145 } // namespace content |
| OLD | NEW |