| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "shell/child_process_host.h" | 5 #include "shell/child_process_host.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/posix/global_descriptors.h" |
| 14 #include "base/process/kill.h" | 15 #include "base/process/kill.h" |
| 15 #include "base/process/launch.h" | 16 #include "base/process/launch.h" |
| 16 #include "base/task_runner.h" | 17 #include "base/task_runner.h" |
| 17 #include "base/task_runner_util.h" | 18 #include "base/task_runner_util.h" |
| 18 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
| 19 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 20 #include "mojo/edk/base_edk/platform_task_runner_impl.h" | 21 #include "mojo/edk/base_edk/platform_task_runner_impl.h" |
| 21 #include "mojo/edk/embedder/multiprocess_embedder.h" | 22 #include "mojo/edk/embedder/multiprocess_embedder.h" |
| 22 #include "mojo/edk/embedder/platform_channel_pair.h" | 23 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 23 #include "mojo/edk/util/ref_ptr.h" | 24 #include "mojo/edk/util/ref_ptr.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 launch_data->child_path = | 61 launch_data->child_path = |
| 61 context_->mojo_shell_child_path().InsertBeforeExtensionASCII("_32"); | 62 context_->mojo_shell_child_path().InsertBeforeExtensionASCII("_32"); |
| 62 } | 63 } |
| 63 #endif | 64 #endif |
| 64 // TODO(vtl): Add something for |slave_info|. | 65 // TODO(vtl): Add something for |slave_info|. |
| 65 // TODO(vtl): The "unretained this" is wrong (see also below). | 66 // TODO(vtl): The "unretained this" is wrong (see also below). |
| 66 // TODO(vtl): We shouldn't have to make a new | 67 // TODO(vtl): We shouldn't have to make a new |
| 67 // |base_edk::PlatformTaskRunnerImpl| for each instance. Instead, there should | 68 // |base_edk::PlatformTaskRunnerImpl| for each instance. Instead, there should |
| 68 // be one per thread. | 69 // be one per thread. |
| 69 mojo::ScopedMessagePipeHandle handle(mojo::embedder::ConnectToSlave( | 70 mojo::ScopedMessagePipeHandle handle(mojo::embedder::ConnectToSlave( |
| 70 nullptr, launch_data->platform_channel_pair.PassServerHandle(), | 71 nullptr, launch_data->platform_channel_pair.handle0.Pass(), |
| 71 [this]() { DidConnectToSlave(); }, | 72 [this]() { DidConnectToSlave(); }, |
| 72 MakeRefCounted<base_edk::PlatformTaskRunnerImpl>( | 73 MakeRefCounted<base_edk::PlatformTaskRunnerImpl>( |
| 73 base::ThreadTaskRunnerHandle::Get()), | 74 base::ThreadTaskRunnerHandle::Get()), |
| 74 &launch_data->child_connection_id, &channel_info_)); | 75 &launch_data->child_connection_id, &channel_info_)); |
| 75 // TODO(vtl): We should destroy the channel on destruction (using | 76 // TODO(vtl): We should destroy the channel on destruction (using |
| 76 // |channel_info_|, but only after the callback has been called. | 77 // |channel_info_|, but only after the callback has been called. |
| 77 CHECK(channel_info_); | 78 CHECK(channel_info_); |
| 78 | 79 |
| 79 controller_.Bind(mojo::InterfacePtrInfo<ChildController>(handle.Pass(), 0u)); | 80 controller_.Bind(mojo::InterfacePtrInfo<ChildController>(handle.Pass(), 0u)); |
| 80 controller_.set_connection_error_handler([this]() { OnConnectionError(); }); | 81 controller_.set_connection_error_handler([this]() { OnConnectionError(); }); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 switches::kTraceToConsole, switches::kV, switches::kVModule, | 137 switches::kTraceToConsole, switches::kV, switches::kVModule, |
| 137 }; | 138 }; |
| 138 | 139 |
| 139 base::CommandLine child_command_line(launch_data->child_path); | 140 base::CommandLine child_command_line(launch_data->child_path); |
| 140 child_command_line.CopySwitchesFrom(*base::CommandLine::ForCurrentProcess(), | 141 child_command_line.CopySwitchesFrom(*base::CommandLine::ForCurrentProcess(), |
| 141 kForwardSwitches, | 142 kForwardSwitches, |
| 142 arraysize(kForwardSwitches)); | 143 arraysize(kForwardSwitches)); |
| 143 child_command_line.AppendSwitchASCII(switches::kChildConnectionId, | 144 child_command_line.AppendSwitchASCII(switches::kChildConnectionId, |
| 144 launch_data->child_connection_id); | 145 launch_data->child_connection_id); |
| 145 | 146 |
| 146 mojo::embedder::HandlePassingInformation handle_passing_info; | 147 base::FileHandleMappingVector fds_to_remap; |
| 147 std::string platform_channel_info; | 148 fds_to_remap.push_back( |
| 148 launch_data->platform_channel_pair.PrepareToPassClientHandleToChildProcess( | 149 std::pair<int, int>(launch_data->platform_channel_pair.handle1.get().fd, |
| 149 &platform_channel_info, &handle_passing_info); | 150 base::GlobalDescriptors::kBaseDescriptor)); |
| 150 child_command_line.AppendSwitchASCII(switches::kPlatformChannelHandleInfo, | |
| 151 platform_channel_info); | |
| 152 | |
| 153 base::LaunchOptions options; | 151 base::LaunchOptions options; |
| 154 options.fds_to_remap = &handle_passing_info; | 152 options.fds_to_remap = &fds_to_remap; |
| 155 #if defined(OS_LINUX) | 153 #if defined(OS_LINUX) |
| 156 options.allow_new_privs = launch_data->options.allow_new_privs; | 154 options.allow_new_privs = launch_data->options.allow_new_privs; |
| 157 #endif | 155 #endif |
| 158 DVLOG(2) << "Launching child with command line: " | 156 DVLOG(2) << "Launching child with command line: " |
| 159 << child_command_line.GetCommandLineString(); | 157 << child_command_line.GetCommandLineString(); |
| 160 base::Process child_process = | 158 base::Process child_process = |
| 161 base::LaunchProcess(child_command_line, options); | 159 base::LaunchProcess(child_command_line, options); |
| 162 if (child_process.IsValid()) | 160 if (child_process.IsValid()) |
| 163 launch_data->platform_channel_pair.ChildProcessLaunched(); | 161 launch_data->platform_channel_pair.handle1.reset(); |
| 164 return child_process.Pass(); | 162 return child_process.Pass(); |
| 165 } | 163 } |
| 166 | 164 |
| 167 void ChildProcessHost::AppCompleted(int32_t result) { | 165 void ChildProcessHost::AppCompleted(int32_t result) { |
| 168 if (!on_app_complete_.is_null()) { | 166 if (!on_app_complete_.is_null()) { |
| 169 auto on_app_complete = on_app_complete_; | 167 auto on_app_complete = on_app_complete_; |
| 170 on_app_complete_.reset(); | 168 on_app_complete_.reset(); |
| 171 on_app_complete.Run(result); | 169 on_app_complete.Run(result); |
| 172 } | 170 } |
| 173 } | 171 } |
| 174 | 172 |
| 175 void ChildProcessHost::OnConnectionError() { | 173 void ChildProcessHost::OnConnectionError() { |
| 176 AppCompleted(MOJO_RESULT_UNKNOWN); | 174 AppCompleted(MOJO_RESULT_UNKNOWN); |
| 177 } | 175 } |
| 178 | 176 |
| 179 } // namespace shell | 177 } // namespace shell |
| OLD | NEW |