OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // This file contains functions for launching subprocesses. | 5 // This file contains functions for launching subprocesses. |
6 | 6 |
7 #ifndef BASE_PROCESS_LAUNCH_H_ | 7 #ifndef BASE_PROCESS_LAUNCH_H_ |
8 #define BASE_PROCESS_LAUNCH_H_ | 8 #define BASE_PROCESS_LAUNCH_H_ |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/base_export.h" | 14 #include "base/base_export.h" |
15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
16 #include "base/environment.h" | 16 #include "base/environment.h" |
| 17 #include "base/process/process.h" |
17 #include "base/process/process_handle.h" | 18 #include "base/process/process_handle.h" |
18 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
19 | 20 |
20 #if defined(OS_POSIX) | 21 #if defined(OS_POSIX) |
21 #include "base/posix/file_descriptor_shuffle.h" | 22 #include "base/posix/file_descriptor_shuffle.h" |
22 #elif defined(OS_WIN) | 23 #elif defined(OS_WIN) |
23 #include <windows.h> | 24 #include <windows.h> |
24 #include "base/win/scoped_handle.h" | 25 #include "base/win/scoped_handle.h" |
25 #endif | 26 #endif |
26 | 27 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 // bootstrap port will not be transferred to the new process. | 137 // bootstrap port will not be transferred to the new process. |
137 std::string replacement_bootstrap_name; | 138 std::string replacement_bootstrap_name; |
138 #endif | 139 #endif |
139 | 140 |
140 #endif // !defined(OS_WIN) | 141 #endif // !defined(OS_WIN) |
141 }; | 142 }; |
142 | 143 |
143 // Launch a process via the command line |cmdline|. | 144 // Launch a process via the command line |cmdline|. |
144 // See the documentation of LaunchOptions for details on |options|. | 145 // See the documentation of LaunchOptions for details on |options|. |
145 // | 146 // |
146 // Returns true upon success. | 147 // Returns a valid Process upon success. |
147 // | |
148 // Upon success, if |process_handle| is non-null, it will be filled in with the | |
149 // handle of the launched process. NOTE: In this case, the caller is | |
150 // responsible for closing the handle so that it doesn't leak! | |
151 // Otherwise, the process handle will be implicitly closed. | |
152 // | 148 // |
153 // Unix-specific notes: | 149 // Unix-specific notes: |
154 // - All file descriptors open in the parent process will be closed in the | 150 // - All file descriptors open in the parent process will be closed in the |
155 // child process except for any preserved by options::fds_to_remap, and | 151 // child process except for any preserved by options::fds_to_remap, and |
156 // stdin, stdout, and stderr. If not remapped by options::fds_to_remap, | 152 // stdin, stdout, and stderr. If not remapped by options::fds_to_remap, |
157 // stdin is reopened as /dev/null, and the child is allowed to inherit its | 153 // stdin is reopened as /dev/null, and the child is allowed to inherit its |
158 // parent's stdout and stderr. | 154 // parent's stdout and stderr. |
159 // - If the first argument on the command line does not contain a slash, | 155 // - If the first argument on the command line does not contain a slash, |
160 // PATH will be searched. (See man execvp.) | 156 // PATH will be searched. (See man execvp.) |
| 157 BASE_EXPORT Process LaunchProcess(const CommandLine& cmdline, |
| 158 const LaunchOptions& options); |
| 159 |
| 160 // Deprecated version. |
| 161 // TODO(rvargas) crbug.com/417532: Remove this after migrating all consumers. |
161 BASE_EXPORT bool LaunchProcess(const CommandLine& cmdline, | 162 BASE_EXPORT bool LaunchProcess(const CommandLine& cmdline, |
162 const LaunchOptions& options, | 163 const LaunchOptions& options, |
163 ProcessHandle* process_handle); | 164 ProcessHandle* process_handle); |
164 | 165 |
165 #if defined(OS_WIN) | 166 #if defined(OS_WIN) |
166 // Windows-specific LaunchProcess that takes the command line as a | 167 // Windows-specific LaunchProcess that takes the command line as a |
167 // string. Useful for situations where you need to control the | 168 // string. Useful for situations where you need to control the |
168 // command line arguments directly, but prefer the CommandLine version | 169 // command line arguments directly, but prefer the CommandLine version |
169 // if launching Chrome itself. | 170 // if launching Chrome itself. |
170 // | 171 // |
171 // The first command line argument should be the path to the process, | 172 // The first command line argument should be the path to the process, |
172 // and don't forget to quote it. | 173 // and don't forget to quote it. |
173 // | 174 // |
174 // Example (including literal quotes) | 175 // Example (including literal quotes) |
175 // cmdline = "c:\windows\explorer.exe" -foo "c:\bar\" | 176 // cmdline = "c:\windows\explorer.exe" -foo "c:\bar\" |
176 BASE_EXPORT bool LaunchProcess(const string16& cmdline, | 177 BASE_EXPORT bool LaunchProcess(const string16& cmdline, |
177 const LaunchOptions& options, | 178 const LaunchOptions& options, |
178 win::ScopedHandle* process_handle); | 179 win::ScopedHandle* process_handle); |
179 | 180 |
180 // Launches a process with elevated privileges. This does not behave exactly | 181 // Launches a process with elevated privileges. This does not behave exactly |
181 // like LaunchProcess as it uses ShellExecuteEx instead of CreateProcess to | 182 // like LaunchProcess as it uses ShellExecuteEx instead of CreateProcess to |
182 // create the process. This means the process will have elevated privileges | 183 // create the process. This means the process will have elevated privileges |
183 // and thus some common operations like OpenProcess will fail. The process will | 184 // and thus some common operations like OpenProcess will fail. Currently the |
184 // be available through the |process_handle| argument. Currently the only | 185 // only supported LaunchOptions are |start_hidden| and |wait|. |
185 // supported LaunchOptions are |start_hidden| and |wait|. | 186 BASE_EXPORT Process LaunchElevatedProcess(const CommandLine& cmdline, |
186 BASE_EXPORT bool LaunchElevatedProcess(const CommandLine& cmdline, | 187 const LaunchOptions& options); |
187 const LaunchOptions& options, | |
188 ProcessHandle* process_handle); | |
189 | 188 |
190 #elif defined(OS_POSIX) | 189 #elif defined(OS_POSIX) |
191 // A POSIX-specific version of LaunchProcess that takes an argv array | 190 // A POSIX-specific version of LaunchProcess that takes an argv array |
192 // instead of a CommandLine. Useful for situations where you need to | 191 // instead of a CommandLine. Useful for situations where you need to |
193 // control the command line arguments directly, but prefer the | 192 // control the command line arguments directly, but prefer the |
194 // CommandLine version if launching Chrome itself. | 193 // CommandLine version if launching Chrome itself. |
195 BASE_EXPORT bool LaunchProcess(const std::vector<std::string>& argv, | 194 BASE_EXPORT bool LaunchProcess(const std::vector<std::string>& argv, |
196 const LaunchOptions& options, | 195 const LaunchOptions& options, |
197 ProcessHandle* process_handle); | 196 ProcessHandle* process_handle); |
198 | 197 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 void ReplaceBootstrapPort(const std::string& replacement_bootstrap_name); | 265 void ReplaceBootstrapPort(const std::string& replacement_bootstrap_name); |
267 #endif // defined(OS_MACOSX) | 266 #endif // defined(OS_MACOSX) |
268 | 267 |
269 // Creates a LaunchOptions object suitable for launching processes in a test | 268 // Creates a LaunchOptions object suitable for launching processes in a test |
270 // binary. This should not be called in production/released code. | 269 // binary. This should not be called in production/released code. |
271 BASE_EXPORT LaunchOptions LaunchOptionsForTest(); | 270 BASE_EXPORT LaunchOptions LaunchOptionsForTest(); |
272 | 271 |
273 } // namespace base | 272 } // namespace base |
274 | 273 |
275 #endif // BASE_PROCESS_LAUNCH_H_ | 274 #endif // BASE_PROCESS_LAUNCH_H_ |
OLD | NEW |