Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1217)

Side by Side Diff: base/process/launch_win.cc

Issue 761903003: Update from https://crrev.com/306655 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/process/launch_posix.cc ('k') | base/process/process_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/launch.h" 5 #include "base/process/launch.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <io.h> 8 #include <io.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #include <windows.h> 10 #include <windows.h>
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 ProcessHandle* process_handle) { 237 ProcessHandle* process_handle) {
238 if (!process_handle) 238 if (!process_handle)
239 return LaunchProcess(cmdline.GetCommandLineString(), options, NULL); 239 return LaunchProcess(cmdline.GetCommandLineString(), options, NULL);
240 240
241 win::ScopedHandle process; 241 win::ScopedHandle process;
242 bool rv = LaunchProcess(cmdline.GetCommandLineString(), options, &process); 242 bool rv = LaunchProcess(cmdline.GetCommandLineString(), options, &process);
243 *process_handle = process.Take(); 243 *process_handle = process.Take();
244 return rv; 244 return rv;
245 } 245 }
246 246
247 bool LaunchElevatedProcess(const CommandLine& cmdline, 247 Process LaunchProcess(const CommandLine& cmdline,
248 const LaunchOptions& options, 248 const LaunchOptions& options) {
249 ProcessHandle* process_handle) { 249 ProcessHandle process_handle;
250 if (LaunchProcess(cmdline, options, &process_handle))
251 return Process(process_handle);
252
253 return Process();
254 }
255
256 Process LaunchElevatedProcess(const CommandLine& cmdline,
257 const LaunchOptions& options) {
250 const string16 file = cmdline.GetProgram().value(); 258 const string16 file = cmdline.GetProgram().value();
251 const string16 arguments = cmdline.GetArgumentsString(); 259 const string16 arguments = cmdline.GetArgumentsString();
252 260
253 SHELLEXECUTEINFO shex_info = {0}; 261 SHELLEXECUTEINFO shex_info = {0};
254 shex_info.cbSize = sizeof(shex_info); 262 shex_info.cbSize = sizeof(shex_info);
255 shex_info.fMask = SEE_MASK_NOCLOSEPROCESS; 263 shex_info.fMask = SEE_MASK_NOCLOSEPROCESS;
256 shex_info.hwnd = GetActiveWindow(); 264 shex_info.hwnd = GetActiveWindow();
257 shex_info.lpVerb = L"runas"; 265 shex_info.lpVerb = L"runas";
258 shex_info.lpFile = file.c_str(); 266 shex_info.lpFile = file.c_str();
259 shex_info.lpParameters = arguments.c_str(); 267 shex_info.lpParameters = arguments.c_str();
260 shex_info.lpDirectory = NULL; 268 shex_info.lpDirectory = NULL;
261 shex_info.nShow = options.start_hidden ? SW_HIDE : SW_SHOW; 269 shex_info.nShow = options.start_hidden ? SW_HIDE : SW_SHOW;
262 shex_info.hInstApp = NULL; 270 shex_info.hInstApp = NULL;
263 271
264 if (!ShellExecuteEx(&shex_info)) { 272 if (!ShellExecuteEx(&shex_info)) {
265 DPLOG(ERROR); 273 DPLOG(ERROR);
266 return false; 274 return Process();
267 } 275 }
268 276
269 if (options.wait) 277 if (options.wait)
270 WaitForSingleObject(shex_info.hProcess, INFINITE); 278 WaitForSingleObject(shex_info.hProcess, INFINITE);
271 279
272 // If the caller wants the process handle give it to them, otherwise just 280 return Process(shex_info.hProcess);
273 // close it. Closing it does not terminate the process.
274 if (process_handle)
275 *process_handle = shex_info.hProcess;
276 else
277 CloseHandle(shex_info.hProcess);
278
279 return true;
280 } 281 }
281 282
282 bool SetJobObjectLimitFlags(HANDLE job_object, DWORD limit_flags) { 283 bool SetJobObjectLimitFlags(HANDLE job_object, DWORD limit_flags) {
283 JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info = {0}; 284 JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info = {0};
284 limit_info.BasicLimitInformation.LimitFlags = limit_flags; 285 limit_info.BasicLimitInformation.LimitFlags = limit_flags;
285 return 0 != SetInformationJobObject( 286 return 0 != SetInformationJobObject(
286 job_object, 287 job_object,
287 JobObjectExtendedLimitInformation, 288 JobObjectExtendedLimitInformation,
288 &limit_info, 289 &limit_info,
289 sizeof(limit_info)); 290 sizeof(limit_info));
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 WaitForSingleObject(proc_info.process_handle(), INFINITE); 364 WaitForSingleObject(proc_info.process_handle(), INFINITE);
364 365
365 return true; 366 return true;
366 } 367 }
367 368
368 void RaiseProcessToHighPriority() { 369 void RaiseProcessToHighPriority() {
369 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); 370 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
370 } 371 }
371 372
372 } // namespace base 373 } // namespace base
OLDNEW
« no previous file with comments | « base/process/launch_posix.cc ('k') | base/process/process_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698