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/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/process/kill.h" | 15 #include "base/process/kill.h" |
16 #include "base/process/launch.h" | 16 #include "base/process/launch.h" |
17 #include "base/task_runner.h" | 17 #include "base/task_runner.h" |
18 #include "base/task_runner_util.h" | 18 #include "base/task_runner_util.h" |
| 19 #include "build/build_config.h" |
19 #include "mojo/edk/embedder/embedder.h" | 20 #include "mojo/edk/embedder/embedder.h" |
20 #include "mojo/edk/embedder/platform_channel_pair.h" | 21 #include "mojo/edk/embedder/platform_channel_pair.h" |
21 #include "mojo/public/cpp/system/message_pipe.h" | 22 #include "mojo/public/cpp/system/message_pipe.h" |
| 23 #include "shell/application_manager/native_application_options.h" |
22 #include "shell/child_switches.h" | 24 #include "shell/child_switches.h" |
23 #include "shell/context.h" | 25 #include "shell/context.h" |
24 #include "shell/task_runners.h" | 26 #include "shell/task_runners.h" |
25 | 27 |
26 namespace shell { | 28 namespace shell { |
27 | 29 |
28 struct ChildProcessHost::LaunchData { | 30 struct ChildProcessHost::LaunchData { |
29 LaunchData() {} | 31 LaunchData() {} |
30 ~LaunchData() {} | 32 ~LaunchData() {} |
31 | 33 |
| 34 NativeApplicationOptions options; |
32 base::FilePath child_path; | 35 base::FilePath child_path; |
33 mojo::embedder::PlatformChannelPair platform_channel_pair; | 36 mojo::embedder::PlatformChannelPair platform_channel_pair; |
34 std::string child_connection_id; | 37 std::string child_connection_id; |
35 }; | 38 }; |
36 | 39 |
37 ChildProcessHost::ChildProcessHost(Context* context) | 40 ChildProcessHost::ChildProcessHost(Context* context) |
38 : context_(context), channel_info_(nullptr) { | 41 : context_(context), channel_info_(nullptr) { |
39 } | 42 } |
40 | 43 |
41 ChildProcessHost::~ChildProcessHost() { | 44 ChildProcessHost::~ChildProcessHost() { |
42 DCHECK(!child_process_.IsValid()); | 45 DCHECK(!child_process_.IsValid()); |
43 } | 46 } |
44 | 47 |
45 void ChildProcessHost::Start(bool require_32_bit) { | 48 void ChildProcessHost::Start(const NativeApplicationOptions& options) { |
46 DCHECK(!child_process_.IsValid()); | 49 DCHECK(!child_process_.IsValid()); |
47 | 50 |
48 scoped_ptr<LaunchData> launch_data(new LaunchData()); | 51 scoped_ptr<LaunchData> launch_data(new LaunchData()); |
| 52 launch_data->options = options; |
49 launch_data->child_path = context_->mojo_shell_child_path(); | 53 launch_data->child_path = context_->mojo_shell_child_path(); |
50 #if defined(ARCH_CPU_64_BITS) | 54 #if defined(ARCH_CPU_64_BITS) |
51 if (require_32_bit) | 55 if (options.require_32_bit) { |
52 launch_data->child_path = | 56 launch_data->child_path = |
53 context_->mojo_shell_child_path().InsertBeforeExtensionASCII("_32"); | 57 context_->mojo_shell_child_path().InsertBeforeExtensionASCII("_32"); |
| 58 } |
54 #endif | 59 #endif |
55 // TODO(vtl): Add something for |slave_info|. | 60 // TODO(vtl): Add something for |slave_info|. |
56 // TODO(vtl): The "unretained this" is wrong (see also below). | 61 // TODO(vtl): The "unretained this" is wrong (see also below). |
57 mojo::ScopedMessagePipeHandle handle(mojo::embedder::ConnectToSlave( | 62 mojo::ScopedMessagePipeHandle handle(mojo::embedder::ConnectToSlave( |
58 nullptr, launch_data->platform_channel_pair.PassServerHandle(), | 63 nullptr, launch_data->platform_channel_pair.PassServerHandle(), |
59 base::Bind(&ChildProcessHost::DidConnectToSlave, base::Unretained(this)), | 64 base::Bind(&ChildProcessHost::DidConnectToSlave, base::Unretained(this)), |
60 base::MessageLoop::current()->message_loop_proxy(), | 65 base::MessageLoop::current()->message_loop_proxy(), |
61 &launch_data->child_connection_id, &channel_info_)); | 66 &launch_data->child_connection_id, &channel_info_)); |
62 // TODO(vtl): We should destroy the channel on destruction (using | 67 // TODO(vtl): We should destroy the channel on destruction (using |
63 // |channel_info_|, but only after the callback has been called. | 68 // |channel_info_|, but only after the callback has been called. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 arraysize(kForwardSwitches)); | 134 arraysize(kForwardSwitches)); |
130 child_command_line.AppendSwitchASCII(switches::kChildConnectionId, | 135 child_command_line.AppendSwitchASCII(switches::kChildConnectionId, |
131 launch_data->child_connection_id); | 136 launch_data->child_connection_id); |
132 | 137 |
133 mojo::embedder::HandlePassingInformation handle_passing_info; | 138 mojo::embedder::HandlePassingInformation handle_passing_info; |
134 launch_data->platform_channel_pair.PrepareToPassClientHandleToChildProcess( | 139 launch_data->platform_channel_pair.PrepareToPassClientHandleToChildProcess( |
135 &child_command_line, &handle_passing_info); | 140 &child_command_line, &handle_passing_info); |
136 | 141 |
137 base::LaunchOptions options; | 142 base::LaunchOptions options; |
138 options.fds_to_remap = &handle_passing_info; | 143 options.fds_to_remap = &handle_passing_info; |
| 144 #if defined(OS_LINUX) |
| 145 options.allow_new_privs = launch_data->options.allow_new_privs; |
| 146 #endif |
139 DVLOG(2) << "Launching child with command line: " | 147 DVLOG(2) << "Launching child with command line: " |
140 << child_command_line.GetCommandLineString(); | 148 << child_command_line.GetCommandLineString(); |
141 base::Process child_process = | 149 base::Process child_process = |
142 base::LaunchProcess(child_command_line, options); | 150 base::LaunchProcess(child_command_line, options); |
143 if (child_process.IsValid()) | 151 if (child_process.IsValid()) |
144 launch_data->platform_channel_pair.ChildProcessLaunched(); | 152 launch_data->platform_channel_pair.ChildProcessLaunched(); |
145 return child_process.Pass(); | 153 return child_process.Pass(); |
146 } | 154 } |
147 | 155 |
148 void ChildProcessHost::AppCompleted(int32_t result) { | 156 void ChildProcessHost::AppCompleted(int32_t result) { |
149 if (!on_app_complete_.is_null()) { | 157 if (!on_app_complete_.is_null()) { |
150 auto on_app_complete = on_app_complete_; | 158 auto on_app_complete = on_app_complete_; |
151 on_app_complete_.reset(); | 159 on_app_complete_.reset(); |
152 on_app_complete.Run(result); | 160 on_app_complete.Run(result); |
153 } | 161 } |
154 } | 162 } |
155 | 163 |
156 void ChildProcessHost::OnConnectionError() { | 164 void ChildProcessHost::OnConnectionError() { |
157 AppCompleted(MOJO_RESULT_UNKNOWN); | 165 AppCompleted(MOJO_RESULT_UNKNOWN); |
158 } | 166 } |
159 | 167 |
160 } // namespace shell | 168 } // namespace shell |
OLD | NEW |