| 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 "chrome/test/base/mojo_test_connector.h" | 5 #include "chrome/test/base/mojo_test_connector.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 base::TestLauncher::LaunchOptions* test_launch_options, | 49 base::TestLauncher::LaunchOptions* test_launch_options, |
| 50 const std::string& mus_config_switch) | 50 const std::string& mus_config_switch) |
| 51 : connector_(connector), | 51 : connector_(connector), |
| 52 background_service_manager_(nullptr), | 52 background_service_manager_(nullptr), |
| 53 platform_channel_(base::MakeUnique<mojo::edk::PlatformChannelPair>()), | 53 platform_channel_(base::MakeUnique<mojo::edk::PlatformChannelPair>()), |
| 54 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 54 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 55 weak_factory_(this) { | 55 weak_factory_(this) { |
| 56 command_line->AppendSwitch(MojoTestConnector::kTestSwitch); | 56 command_line->AppendSwitch(MojoTestConnector::kTestSwitch); |
| 57 command_line->AppendSwitchASCII(switches::kMusConfig, mus_config_switch); | 57 command_line->AppendSwitchASCII(switches::kMusConfig, mus_config_switch); |
| 58 | 58 |
| 59 #if defined(OS_WIN) |
| 59 platform_channel_->PrepareToPassClientHandleToChildProcess( | 60 platform_channel_->PrepareToPassClientHandleToChildProcess( |
| 60 command_line, &handle_passing_info_); | 61 command_line, &test_launch_options->handles_to_inherit); |
| 61 #if defined(OS_WIN) | |
| 62 test_launch_options->inherit_handles = true; | |
| 63 test_launch_options->handles_to_inherit = &handle_passing_info_; | |
| 64 #if defined(OFFICIAL_BUILD) | |
| 65 CHECK(false) << "Launching mojo process with inherit_handles is insecure!"; | |
| 66 #endif | |
| 67 #elif defined(OS_POSIX) | 62 #elif defined(OS_POSIX) |
| 68 test_launch_options->fds_to_remap = &handle_passing_info_; | 63 platform_channel_->PrepareToPassClientHandleToChildProcess( |
| 64 command_line, &test_launch_options->fds_to_remap); |
| 69 #else | 65 #else |
| 70 #error "Unsupported" | 66 #error "Unsupported" |
| 71 #endif | 67 #endif |
| 72 | 68 |
| 73 // Create the pipe token, as it must be passed to children processes via the | 69 // Create the pipe token, as it must be passed to children processes via the |
| 74 // command line. | 70 // command line. |
| 75 service_ = service_manager::PassServiceRequestOnCommandLine( | 71 service_ = service_manager::PassServiceRequestOnCommandLine( |
| 76 &broker_client_invitation_, command_line); | 72 &broker_client_invitation_, command_line); |
| 77 } | 73 } |
| 78 | 74 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 mojo::edk::OutgoingBrokerClientInvitation broker_client_invitation_; | 119 mojo::edk::OutgoingBrokerClientInvitation broker_client_invitation_; |
| 124 MojoTestConnector* connector_; | 120 MojoTestConnector* connector_; |
| 125 std::unique_ptr<service_manager::BackgroundServiceManager> | 121 std::unique_ptr<service_manager::BackgroundServiceManager> |
| 126 background_service_manager_; | 122 background_service_manager_; |
| 127 | 123 |
| 128 // The ServicePtr must be created before child process launch so that the pipe | 124 // The ServicePtr must be created before child process launch so that the pipe |
| 129 // can be set on the command line. It is held until SetupService is called at | 125 // can be set on the command line. It is held until SetupService is called at |
| 130 // which point |background_service_manager_| takes over ownership. | 126 // which point |background_service_manager_| takes over ownership. |
| 131 service_manager::mojom::ServicePtr service_; | 127 service_manager::mojom::ServicePtr service_; |
| 132 | 128 |
| 133 // NOTE: HandlePassingInformation must remain valid through process launch, | |
| 134 // hence it lives here instead of within Init()'s stack. | |
| 135 mojo::edk::HandlePassingInformation handle_passing_info_; | |
| 136 | |
| 137 std::unique_ptr<mojo::edk::PlatformChannelPair> platform_channel_; | 129 std::unique_ptr<mojo::edk::PlatformChannelPair> platform_channel_; |
| 138 service_manager::mojom::PIDReceiverPtr pid_receiver_; | 130 service_manager::mojom::PIDReceiverPtr pid_receiver_; |
| 139 const scoped_refptr<base::TaskRunner> main_task_runner_; | 131 const scoped_refptr<base::TaskRunner> main_task_runner_; |
| 140 | 132 |
| 141 base::WeakPtrFactory<MojoTestState> weak_factory_; | 133 base::WeakPtrFactory<MojoTestState> weak_factory_; |
| 142 | 134 |
| 143 DISALLOW_COPY_AND_ASSIGN(MojoTestState); | 135 DISALLOW_COPY_AND_ASSIGN(MojoTestState); |
| 144 }; | 136 }; |
| 145 | 137 |
| 146 // The name in the manifest results in getting exe:mash_browser_tests used, | 138 // The name in the manifest results in getting exe:mash_browser_tests used, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 return base::MakeUnique<MojoTestState>( | 255 return base::MakeUnique<MojoTestState>( |
| 264 this, command_line, test_launch_options, | 256 this, command_line, test_launch_options, |
| 265 config_ == MojoTestConnector::Config::MASH ? switches::kMash | 257 config_ == MojoTestConnector::Config::MASH ? switches::kMash |
| 266 : switches::kMus); | 258 : switches::kMus); |
| 267 } | 259 } |
| 268 | 260 |
| 269 void MojoTestConnector::StartService(const std::string& service_name) { | 261 void MojoTestConnector::StartService(const std::string& service_name) { |
| 270 background_service_manager_->StartService(service_manager::Identity( | 262 background_service_manager_->StartService(service_manager::Identity( |
| 271 service_name, service_manager::mojom::kRootUserID)); | 263 service_name, service_manager::mojom::kRootUserID)); |
| 272 } | 264 } |
| OLD | NEW |