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 | |
33 shell::mojom::ShellClientPtr client; | 27 shell::mojom::ShellClientPtr client; |
34 client.Bind(mojo::InterfacePtrInfo<shell::mojom::ShellClient>( | 28 client.Bind(mojo::InterfacePtrInfo<shell::mojom::ShellClient>( |
35 std::move(shell_client_pipe), 0u)); | 29 std::move(shell_client_pipe), 0u)); |
36 shell::mojom::PIDReceiverRequest pid_receiver_request = | 30 shell::mojom::PIDReceiverRequest pid_receiver_request = |
37 GetProxy(&pid_receiver_); | 31 GetProxy(&pid_receiver_); |
38 | 32 |
39 shell::Identity target(application_name, shell::mojom::kInheritUserID, | 33 shell::Identity target(application_name, shell::mojom::kInheritUserID, |
40 instance_id); | 34 instance_id); |
41 shell::Connector::ConnectParams params(target); | 35 shell::Connector::ConnectParams params(target); |
42 params.set_client_process_connection(std::move(client), | 36 params.set_client_process_connection(std::move(client), |
43 std::move(pid_receiver_request)); | 37 std::move(pid_receiver_request)); |
44 connection_ = connector->Connect(¶ms); | 38 connection_ = connector->Connect(¶ms); |
| 39 |
| 40 #if defined(OS_ANDROID) |
| 41 service_registry_android_ = ServiceRegistryAndroid::Create( |
| 42 connection_->GetInterfaceRegistry(), connection_->GetRemoteInterfaces()); |
| 43 #endif |
45 } | 44 } |
46 | 45 |
47 MojoChildConnection::~MojoChildConnection() {} | 46 MojoChildConnection::~MojoChildConnection() {} |
48 | 47 |
49 void MojoChildConnection::SetProcessHandle(base::ProcessHandle handle) { | 48 void MojoChildConnection::SetProcessHandle(base::ProcessHandle handle) { |
50 DCHECK(pid_receiver_.is_bound()); | 49 DCHECK(pid_receiver_.is_bound()); |
51 pid_receiver_->SetPID(base::GetProcId(handle)); | 50 pid_receiver_->SetPID(base::GetProcId(handle)); |
52 pid_receiver_.reset(); | 51 pid_receiver_.reset(); |
53 } | 52 } |
54 | 53 |
55 } // namespace content | 54 } // namespace content |
OLD | NEW |