| 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 "services/shell/runner/host/child_process_host.h" | 5 #include "services/shell/runner/host/child_process_host.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #endif | 31 #endif |
| 32 | 32 |
| 33 #if defined(OS_WIN) | 33 #if defined(OS_WIN) |
| 34 #include "base/win/windows_version.h" | 34 #include "base/win/windows_version.h" |
| 35 #endif | 35 #endif |
| 36 | 36 |
| 37 #if defined(OS_MACOSX) | 37 #if defined(OS_MACOSX) |
| 38 #include "services/shell/runner/host/mach_broker.h" | 38 #include "services/shell/runner/host/mach_broker.h" |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 namespace mojo { | |
| 42 namespace shell { | 41 namespace shell { |
| 43 | 42 |
| 44 ChildProcessHost::ChildProcessHost(base::TaskRunner* launch_process_runner, | 43 ChildProcessHost::ChildProcessHost(base::TaskRunner* launch_process_runner, |
| 45 NativeRunnerDelegate* delegate, | 44 NativeRunnerDelegate* delegate, |
| 46 bool start_sandboxed, | 45 bool start_sandboxed, |
| 47 const Identity& target, | 46 const Identity& target, |
| 48 const base::FilePath& app_path) | 47 const base::FilePath& app_path) |
| 49 : launch_process_runner_(launch_process_runner), | 48 : launch_process_runner_(launch_process_runner), |
| 50 delegate_(delegate), | 49 delegate_(delegate), |
| 51 start_sandboxed_(start_sandboxed), | 50 start_sandboxed_(start_sandboxed), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 70 | 69 |
| 71 const base::CommandLine* parent_command_line = | 70 const base::CommandLine* parent_command_line = |
| 72 base::CommandLine::ForCurrentProcess(); | 71 base::CommandLine::ForCurrentProcess(); |
| 73 base::FilePath target_path = parent_command_line->GetProgram(); | 72 base::FilePath target_path = parent_command_line->GetProgram(); |
| 74 // |app_path_| can be empty in tests. | 73 // |app_path_| can be empty in tests. |
| 75 if (!app_path_.MatchesExtension(FILE_PATH_LITERAL(".mojo")) && | 74 if (!app_path_.MatchesExtension(FILE_PATH_LITERAL(".mojo")) && |
| 76 !app_path_.empty()) { | 75 !app_path_.empty()) { |
| 77 target_path = app_path_; | 76 target_path = app_path_; |
| 78 } | 77 } |
| 79 | 78 |
| 80 scoped_ptr<base::CommandLine> child_command_line( | 79 std::unique_ptr<base::CommandLine> child_command_line( |
| 81 new base::CommandLine(target_path)); | 80 new base::CommandLine(target_path)); |
| 82 | 81 |
| 83 child_command_line->AppendArguments(*parent_command_line, false); | 82 child_command_line->AppendArguments(*parent_command_line, false); |
| 84 | 83 |
| 85 #ifndef NDEBUG | 84 #ifndef NDEBUG |
| 86 child_command_line->AppendSwitchASCII("n", target.name()); | 85 child_command_line->AppendSwitchASCII("n", target.name()); |
| 87 child_command_line->AppendSwitchASCII("u", target.user_id()); | 86 child_command_line->AppendSwitchASCII("u", target.user_id()); |
| 88 #endif | 87 #endif |
| 89 | 88 |
| 90 if (target_path != app_path_) | 89 if (target_path != app_path_) |
| 91 child_command_line->AppendSwitchPath(switches::kChildProcess, app_path_); | 90 child_command_line->AppendSwitchPath(switches::kChildProcess, app_path_); |
| 92 | 91 |
| 93 if (start_sandboxed_) | 92 if (start_sandboxed_) |
| 94 child_command_line->AppendSwitch(switches::kEnableSandbox); | 93 child_command_line->AppendSwitch(switches::kEnableSandbox); |
| 95 | 94 |
| 96 mojo_ipc_channel_.reset(new edk::PlatformChannelPair); | 95 mojo_ipc_channel_.reset(new mojo::edk::PlatformChannelPair); |
| 97 mojo_ipc_channel_->PrepareToPassClientHandleToChildProcess( | 96 mojo_ipc_channel_->PrepareToPassClientHandleToChildProcess( |
| 98 child_command_line.get(), &handle_passing_info_); | 97 child_command_line.get(), &handle_passing_info_); |
| 99 | 98 |
| 100 mojom::ShellClientPtr client = | 99 mojom::ShellClientPtr client = |
| 101 PassShellClientRequestOnCommandLine(child_command_line.get()); | 100 PassShellClientRequestOnCommandLine(child_command_line.get()); |
| 102 launch_process_runner_->PostTaskAndReply( | 101 launch_process_runner_->PostTaskAndReply( |
| 103 FROM_HERE, | 102 FROM_HERE, |
| 104 base::Bind(&ChildProcessHost::DoLaunch, base::Unretained(this), | 103 base::Bind(&ChildProcessHost::DoLaunch, base::Unretained(this), |
| 105 base::Passed(&child_command_line)), | 104 base::Passed(&child_command_line)), |
| 106 base::Bind(&ChildProcessHost::DidStart, | 105 base::Bind(&ChildProcessHost::DidStart, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 123 void ChildProcessHost::DidStart(const ProcessReadyCallback& callback) { | 122 void ChildProcessHost::DidStart(const ProcessReadyCallback& callback) { |
| 124 if (child_process_.IsValid()) { | 123 if (child_process_.IsValid()) { |
| 125 callback.Run(child_process_.Pid()); | 124 callback.Run(child_process_.Pid()); |
| 126 } else { | 125 } else { |
| 127 LOG(ERROR) << "Failed to start child process"; | 126 LOG(ERROR) << "Failed to start child process"; |
| 128 mojo_ipc_channel_.reset(); | 127 mojo_ipc_channel_.reset(); |
| 129 } | 128 } |
| 130 } | 129 } |
| 131 | 130 |
| 132 void ChildProcessHost::DoLaunch( | 131 void ChildProcessHost::DoLaunch( |
| 133 scoped_ptr<base::CommandLine> child_command_line) { | 132 std::unique_ptr<base::CommandLine> child_command_line) { |
| 134 if (delegate_) { | 133 if (delegate_) { |
| 135 delegate_->AdjustCommandLineArgumentsForTarget(target_, | 134 delegate_->AdjustCommandLineArgumentsForTarget(target_, |
| 136 child_command_line.get()); | 135 child_command_line.get()); |
| 137 } | 136 } |
| 138 | 137 |
| 139 base::LaunchOptions options; | 138 base::LaunchOptions options; |
| 140 #if defined(OS_WIN) | 139 #if defined(OS_WIN) |
| 141 options.handles_to_inherit = &handle_passing_info_; | 140 options.handles_to_inherit = &handle_passing_info_; |
| 142 #if defined(OFFICIAL_BUILD) | 141 #if defined(OFFICIAL_BUILD) |
| 143 CHECK(false) << "Launching mojo process with inherit_handles is insecure!"; | 142 CHECK(false) << "Launching mojo process with inherit_handles is insecure!"; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 mojo::edk::ChildProcessLaunched( | 201 mojo::edk::ChildProcessLaunched( |
| 203 child_process_.Handle(), | 202 child_process_.Handle(), |
| 204 mojo::edk::ScopedPlatformHandle(mojo::edk::PlatformHandle( | 203 mojo::edk::ScopedPlatformHandle(mojo::edk::PlatformHandle( |
| 205 mojo_ipc_channel_->PassServerHandle().release().handle))); | 204 mojo_ipc_channel_->PassServerHandle().release().handle))); |
| 206 } | 205 } |
| 207 } | 206 } |
| 208 start_child_process_event_.Signal(); | 207 start_child_process_event_.Signal(); |
| 209 } | 208 } |
| 210 | 209 |
| 211 } // namespace shell | 210 } // namespace shell |
| 212 } // namespace mojo | |
| OLD | NEW |