| 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" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/process/process.h" | 15 #include "base/process/process.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "mojo/edk/embedder/embedder.h" | 17 #include "mojo/edk/embedder/embedder.h" |
| 18 #include "mojo/edk/embedder/platform_channel_pair.h" | 18 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 19 #include "mojo/edk/embedder/scoped_platform_handle.h" | 19 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 20 #include "services/service_manager/public/cpp/connection.h" | |
| 21 #include "services/service_manager/public/cpp/connector.h" | 20 #include "services/service_manager/public/cpp/connector.h" |
| 22 #include "services/service_manager/public/interfaces/connector.mojom.h" | 21 #include "services/service_manager/public/interfaces/connector.mojom.h" |
| 23 #include "services/service_manager/public/interfaces/service_factory.mojom.h" | 22 #include "services/service_manager/public/interfaces/service_factory.mojom.h" |
| 24 #include "services/service_manager/runner/common/switches.h" | 23 #include "services/service_manager/runner/common/switches.h" |
| 25 | 24 |
| 26 namespace service_manager { | 25 namespace service_manager { |
| 27 namespace test { | 26 namespace test { |
| 28 | 27 |
| 29 namespace { | 28 namespace { |
| 30 | 29 |
| 31 void QuitLoop(base::RunLoop* loop) { | 30 void GrabConnectResult(base::RunLoop* loop, |
| 31 mojom::ConnectResult* out_result, |
| 32 mojom::ConnectResult result, |
| 33 const Identity& resolved_identity) { |
| 32 loop->Quit(); | 34 loop->Quit(); |
| 35 *out_result = result; |
| 33 } | 36 } |
| 34 | 37 |
| 35 } // namespace | 38 } // namespace |
| 36 | 39 |
| 37 std::unique_ptr<Connection> LaunchAndConnectToProcess( | 40 mojom::ConnectResult LaunchAndConnectToProcess( |
| 38 const std::string& target_exe_name, | 41 const std::string& target_exe_name, |
| 39 const Identity& target, | 42 const Identity& target, |
| 40 service_manager::Connector* connector, | 43 service_manager::Connector* connector, |
| 41 base::Process* process) { | 44 base::Process* process) { |
| 42 base::FilePath target_path; | 45 base::FilePath target_path; |
| 43 CHECK(base::PathService::Get(base::DIR_EXE, &target_path)); | 46 CHECK(base::PathService::Get(base::DIR_EXE, &target_path)); |
| 44 target_path = target_path.AppendASCII(target_exe_name); | 47 target_path = target_path.AppendASCII(target_exe_name); |
| 45 | 48 |
| 46 base::CommandLine child_command_line(target_path); | 49 base::CommandLine child_command_line(target_path); |
| 47 // Forward the wait-for-debugger flag but nothing else - we don't want to | 50 // Forward the wait-for-debugger flag but nothing else - we don't want to |
| (...skipping 15 matching lines...) Expand all Loading... |
| 63 mojo::ScopedMessagePipeHandle pipe = | 66 mojo::ScopedMessagePipeHandle pipe = |
| 64 pending_process.CreateMessagePipe(&token); | 67 pending_process.CreateMessagePipe(&token); |
| 65 child_command_line.AppendSwitchASCII(switches::kPrimordialPipeToken, token); | 68 child_command_line.AppendSwitchASCII(switches::kPrimordialPipeToken, token); |
| 66 | 69 |
| 67 service_manager::mojom::ServicePtr client; | 70 service_manager::mojom::ServicePtr client; |
| 68 client.Bind(mojo::InterfacePtrInfo<service_manager::mojom::Service>( | 71 client.Bind(mojo::InterfacePtrInfo<service_manager::mojom::Service>( |
| 69 std::move(pipe), 0u)); | 72 std::move(pipe), 0u)); |
| 70 service_manager::mojom::PIDReceiverPtr receiver; | 73 service_manager::mojom::PIDReceiverPtr receiver; |
| 71 | 74 |
| 72 connector->StartService(target, std::move(client), MakeRequest(&receiver)); | 75 connector->StartService(target, std::move(client), MakeRequest(&receiver)); |
| 73 std::unique_ptr<service_manager::Connection> connection = | 76 mojom::ConnectResult result; |
| 74 connector->Connect(target); | |
| 75 { | 77 { |
| 76 base::RunLoop loop; | 78 base::RunLoop loop; |
| 77 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); | 79 Connector::TestApi test_api(connector); |
| 80 test_api.SetStartServiceCallback( |
| 81 base::Bind(&GrabConnectResult, &loop, &result)); |
| 78 base::MessageLoop::ScopedNestableTaskAllower allow( | 82 base::MessageLoop::ScopedNestableTaskAllower allow( |
| 79 base::MessageLoop::current()); | 83 base::MessageLoop::current()); |
| 80 loop.Run(); | 84 loop.Run(); |
| 81 } | 85 } |
| 82 | 86 |
| 83 base::LaunchOptions options; | 87 base::LaunchOptions options; |
| 84 #if defined(OS_WIN) | 88 #if defined(OS_WIN) |
| 85 options.handles_to_inherit = &handle_passing_info; | 89 options.handles_to_inherit = &handle_passing_info; |
| 86 #elif defined(OS_POSIX) | 90 #elif defined(OS_POSIX) |
| 87 options.fds_to_remap = &handle_passing_info; | 91 options.fds_to_remap = &handle_passing_info; |
| 88 #endif | 92 #endif |
| 89 *process = base::LaunchProcess(child_command_line, options); | 93 *process = base::LaunchProcess(child_command_line, options); |
| 90 DCHECK(process->IsValid()); | 94 DCHECK(process->IsValid()); |
| 91 receiver->SetPID(process->Pid()); | 95 receiver->SetPID(process->Pid()); |
| 92 pending_process.Connect( | 96 pending_process.Connect( |
| 93 process->Handle(), | 97 process->Handle(), |
| 94 mojo::edk::ConnectionParams(platform_channel_pair.PassServerHandle())); | 98 mojo::edk::ConnectionParams(platform_channel_pair.PassServerHandle())); |
| 95 return connection; | 99 return result; |
| 96 } | 100 } |
| 97 | 101 |
| 98 } // namespace test | 102 } // namespace test |
| 99 } // namespace service_manager | 103 } // namespace service_manager |
| OLD | NEW |