OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/process_util.h" | 5 #include "base/process_util.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <io.h> | 8 #include <io.h> |
9 #include <windows.h> | 9 #include <windows.h> |
10 #include <userenv.h> | 10 #include <userenv.h> |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 bool LaunchProcess(const string16& cmdline, | 299 bool LaunchProcess(const string16& cmdline, |
300 const LaunchOptions& options, | 300 const LaunchOptions& options, |
301 ProcessHandle* process_handle) { | 301 ProcessHandle* process_handle) { |
302 STARTUPINFO startup_info = {}; | 302 STARTUPINFO startup_info = {}; |
303 startup_info.cb = sizeof(startup_info); | 303 startup_info.cb = sizeof(startup_info); |
304 if (options.empty_desktop_name) | 304 if (options.empty_desktop_name) |
305 startup_info.lpDesktop = L""; | 305 startup_info.lpDesktop = L""; |
306 startup_info.dwFlags = STARTF_USESHOWWINDOW; | 306 startup_info.dwFlags = STARTF_USESHOWWINDOW; |
307 startup_info.wShowWindow = options.start_hidden ? SW_HIDE : SW_SHOW; | 307 startup_info.wShowWindow = options.start_hidden ? SW_HIDE : SW_SHOW; |
308 | 308 |
309 if (options.stdin_handle != kNullProcessHandle) { | |
310 startup_info.dwFlags |= STARTF_USESTDHANDLES; | |
311 startup_info.hStdInput = options.stdin_handle; | |
312 } | |
313 if (options.stdout_handle != kNullProcessHandle) { | |
314 startup_info.dwFlags |= STARTF_USESTDHANDLES; | |
315 startup_info.hStdOutput = options.stdout_handle; | |
316 } | |
317 | |
309 DWORD flags = 0; | 318 DWORD flags = 0; |
310 | 319 |
311 if (options.job_handle) { | 320 if (options.job_handle) { |
312 flags |= CREATE_SUSPENDED; | 321 flags |= CREATE_SUSPENDED; |
313 | 322 |
314 // If this code is run under a debugger, the launched process is | 323 // If this code is run under a debugger, the launched process is |
315 // automatically associated with a job object created by the debugger. | 324 // automatically associated with a job object created by the debugger. |
316 // The CREATE_BREAKAWAY_FROM_JOB flag is used to prevent this. | 325 // The CREATE_BREAKAWAY_FROM_JOB flag is used to prevent this. |
317 flags |= CREATE_BREAKAWAY_FROM_JOB; | 326 flags |= CREATE_BREAKAWAY_FROM_JOB; |
318 } | 327 } |
(...skipping 13 matching lines...) Expand all Loading... | |
332 BOOL launched = | 341 BOOL launched = |
333 CreateProcessAsUser(options.as_user, NULL, | 342 CreateProcessAsUser(options.as_user, NULL, |
334 const_cast<wchar_t*>(cmdline.c_str()), | 343 const_cast<wchar_t*>(cmdline.c_str()), |
335 NULL, NULL, options.inherit_handles, flags, | 344 NULL, NULL, options.inherit_handles, flags, |
336 enviroment_block, NULL, &startup_info, | 345 enviroment_block, NULL, &startup_info, |
337 process_info.Receive()); | 346 process_info.Receive()); |
338 DestroyEnvironmentBlock(enviroment_block); | 347 DestroyEnvironmentBlock(enviroment_block); |
339 if (!launched) | 348 if (!launched) |
340 return false; | 349 return false; |
341 } else { | 350 } else { |
351 ::SetLastError(0); | |
Matt Perry
2012/10/24 23:40:31
Is this needed?
eaugusti
2012/10/30 22:03:12
Stray edit.
| |
342 if (!CreateProcess(NULL, | 352 if (!CreateProcess(NULL, |
343 const_cast<wchar_t*>(cmdline.c_str()), NULL, NULL, | 353 const_cast<wchar_t*>(cmdline.c_str()), NULL, NULL, |
344 options.inherit_handles, flags, NULL, NULL, | 354 options.inherit_handles, flags, NULL, NULL, |
345 &startup_info, process_info.Receive())) { | 355 &startup_info, process_info.Receive())) { |
346 return false; | 356 return false; |
347 } | 357 } |
348 } | 358 } |
349 | 359 |
350 if (options.job_handle) { | 360 if (options.job_handle) { |
351 if (0 == AssignProcessToJobObject(options.job_handle, | 361 if (0 == AssignProcessToJobObject(options.job_handle, |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
994 | 1004 |
995 PERFORMANCE_INFORMATION info; | 1005 PERFORMANCE_INFORMATION info; |
996 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { | 1006 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { |
997 DLOG(ERROR) << "Failed to fetch internal performance info."; | 1007 DLOG(ERROR) << "Failed to fetch internal performance info."; |
998 return 0; | 1008 return 0; |
999 } | 1009 } |
1000 return (info.CommitTotal * system_info.dwPageSize) / 1024; | 1010 return (info.CommitTotal * system_info.dwPageSize) / 1024; |
1001 } | 1011 } |
1002 | 1012 |
1003 } // namespace base | 1013 } // namespace base |
OLD | NEW |