OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/service_manager/tests/util.h" | 5 #include "services/service_manager/tests/util.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 child_command_line.AppendSwitch(switches::kWaitForDebugger); | 51 child_command_line.AppendSwitch(switches::kWaitForDebugger); |
52 } | 52 } |
53 | 53 |
54 // Create the channel to be shared with the target process. Pass one end | 54 // Create the channel to be shared with the target process. Pass one end |
55 // on the command line. | 55 // on the command line. |
56 mojo::edk::PlatformChannelPair platform_channel_pair; | 56 mojo::edk::PlatformChannelPair platform_channel_pair; |
57 mojo::edk::HandlePassingInformation handle_passing_info; | 57 mojo::edk::HandlePassingInformation handle_passing_info; |
58 platform_channel_pair.PrepareToPassClientHandleToChildProcess( | 58 platform_channel_pair.PrepareToPassClientHandleToChildProcess( |
59 &child_command_line, &handle_passing_info); | 59 &child_command_line, &handle_passing_info); |
60 | 60 |
61 // Generate a token for the child to find and connect to a primordial pipe | 61 mojo::edk::PendingProcessConnection pending_process; |
62 // and pass that as well. | 62 std::string token; |
63 std::string primordial_pipe_token = mojo::edk::GenerateRandomToken(); | |
64 child_command_line.AppendSwitchASCII(switches::kPrimordialPipeToken, | |
65 primordial_pipe_token); | |
66 | |
67 // Allocate the pipe locally. | |
68 std::string child_token = mojo::edk::GenerateRandomToken(); | |
69 mojo::ScopedMessagePipeHandle pipe = | 63 mojo::ScopedMessagePipeHandle pipe = |
70 mojo::edk::CreateParentMessagePipe(primordial_pipe_token, child_token); | 64 pending_process.CreateMessagePipe(&token); |
| 65 child_command_line.AppendSwitchASCII(switches::kPrimordialPipeToken, token); |
71 | 66 |
72 service_manager::mojom::ServicePtr client; | 67 service_manager::mojom::ServicePtr client; |
73 client.Bind(mojo::InterfacePtrInfo<service_manager::mojom::Service>( | 68 client.Bind(mojo::InterfacePtrInfo<service_manager::mojom::Service>( |
74 std::move(pipe), 0u)); | 69 std::move(pipe), 0u)); |
75 service_manager::mojom::PIDReceiverPtr receiver; | 70 service_manager::mojom::PIDReceiverPtr receiver; |
76 | 71 |
77 connector->StartService(target, std::move(client), MakeRequest(&receiver)); | 72 connector->StartService(target, std::move(client), MakeRequest(&receiver)); |
78 std::unique_ptr<service_manager::Connection> connection = | 73 std::unique_ptr<service_manager::Connection> connection = |
79 connector->Connect(target); | 74 connector->Connect(target); |
80 { | 75 { |
81 base::RunLoop loop; | 76 base::RunLoop loop; |
82 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); | 77 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); |
83 base::MessageLoop::ScopedNestableTaskAllower allow( | 78 base::MessageLoop::ScopedNestableTaskAllower allow( |
84 base::MessageLoop::current()); | 79 base::MessageLoop::current()); |
85 loop.Run(); | 80 loop.Run(); |
86 } | 81 } |
87 | 82 |
88 base::LaunchOptions options; | 83 base::LaunchOptions options; |
89 #if defined(OS_WIN) | 84 #if defined(OS_WIN) |
90 options.handles_to_inherit = &handle_passing_info; | 85 options.handles_to_inherit = &handle_passing_info; |
91 #elif defined(OS_POSIX) | 86 #elif defined(OS_POSIX) |
92 options.fds_to_remap = &handle_passing_info; | 87 options.fds_to_remap = &handle_passing_info; |
93 #endif | 88 #endif |
94 *process = base::LaunchProcess(child_command_line, options); | 89 *process = base::LaunchProcess(child_command_line, options); |
95 DCHECK(process->IsValid()); | 90 DCHECK(process->IsValid()); |
96 receiver->SetPID(process->Pid()); | 91 receiver->SetPID(process->Pid()); |
97 mojo::edk::ChildProcessLaunched(process->Handle(), | 92 pending_process.Connect(process->Handle(), |
98 platform_channel_pair.PassServerHandle(), | 93 platform_channel_pair.PassServerHandle()); |
99 child_token); | |
100 return connection; | 94 return connection; |
101 } | 95 } |
102 | 96 |
103 } // namespace test | 97 } // namespace test |
104 } // namespace service_manager | 98 } // namespace service_manager |
OLD | NEW |