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 "content/public/common/mojo_shell_connection.h" | 10 #include "content/public/common/mojo_shell_connection.h" |
11 #include "mojo/edk/embedder/embedder.h" | 11 #include "mojo/edk/embedder/embedder.h" |
12 #include "mojo/public/cpp/system/message_pipe.h" | 12 #include "mojo/public/cpp/system/message_pipe.h" |
13 #include "services/shell/public/cpp/connector.h" | 13 #include "services/shell/public/cpp/connector.h" |
14 #include "services/shell/public/cpp/identity.h" | 14 #include "services/shell/public/cpp/identity.h" |
15 #include "services/shell/public/interfaces/shell_client.mojom.h" | 15 #include "services/shell/public/interfaces/shell_client.mojom.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 MojoChildConnection::MojoChildConnection(const std::string& application_name, | 19 MojoChildConnection::MojoChildConnection(const std::string& application_name, |
20 const std::string& instance_id, | 20 const std::string& instance_id, |
21 const std::string& child_token, | 21 const std::string& child_token, |
22 shell::Connector* connector) | 22 shell::Connector* connector) |
23 : shell_client_token_(mojo::edk::GenerateRandomToken()) { | 23 : shell_client_token_(mojo::edk::GenerateRandomToken()) { |
24 mojo::ScopedMessagePipeHandle shell_client_pipe = | 24 mojo::ScopedMessagePipeHandle shell_client_pipe = |
25 mojo::edk::CreateParentMessagePipe(shell_client_token_, child_token); | 25 mojo::edk::CreateParentMessagePipe(shell_client_token_, child_token); |
26 | 26 |
| 27 // Some process types get created before the main message loop. In this case |
| 28 // the shell request pipe will simply be closed, and the child can detect |
| 29 // this. |
| 30 if (!MojoShellConnection::GetForProcess()) |
| 31 return; |
| 32 |
27 shell::mojom::ShellClientPtr client; | 33 shell::mojom::ShellClientPtr client; |
28 client.Bind(mojo::InterfacePtrInfo<shell::mojom::ShellClient>( | 34 client.Bind(mojo::InterfacePtrInfo<shell::mojom::ShellClient>( |
29 std::move(shell_client_pipe), 0u)); | 35 std::move(shell_client_pipe), 0u)); |
30 shell::mojom::PIDReceiverRequest pid_receiver_request = | 36 shell::mojom::PIDReceiverRequest pid_receiver_request = |
31 GetProxy(&pid_receiver_); | 37 GetProxy(&pid_receiver_); |
32 | 38 |
33 shell::Identity target(application_name, shell::mojom::kInheritUserID, | 39 shell::Identity target(application_name, shell::mojom::kInheritUserID, |
34 instance_id); | 40 instance_id); |
35 shell::Connector::ConnectParams params(target); | 41 shell::Connector::ConnectParams params(target); |
36 params.set_client_process_connection(std::move(client), | 42 params.set_client_process_connection(std::move(client), |
37 std::move(pid_receiver_request)); | 43 std::move(pid_receiver_request)); |
38 connection_ = connector->Connect(¶ms); | 44 connection_ = connector->Connect(¶ms); |
39 #if defined(OS_ANDROID) | |
40 service_registry_android_ = ServiceRegistryAndroid::Create( | |
41 connection_->GetInterfaceRegistry(), connection_->GetRemoteInterfaces()); | |
42 #endif | |
43 } | 45 } |
44 | 46 |
45 MojoChildConnection::~MojoChildConnection() {} | 47 MojoChildConnection::~MojoChildConnection() {} |
46 | 48 |
47 void MojoChildConnection::SetProcessHandle(base::ProcessHandle handle) { | 49 void MojoChildConnection::SetProcessHandle(base::ProcessHandle handle) { |
48 DCHECK(pid_receiver_.is_bound()); | 50 DCHECK(pid_receiver_.is_bound()); |
49 pid_receiver_->SetPID(base::GetProcId(handle)); | 51 pid_receiver_->SetPID(base::GetProcId(handle)); |
50 pid_receiver_.reset(); | 52 pid_receiver_.reset(); |
51 } | 53 } |
52 | 54 |
53 } // namespace content | 55 } // namespace content |
OLD | NEW |