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

Side by Side Diff: base/process_util_win.cc

Issue 7377012: Change base::LaunchProcess API slightly (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 5 months 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 | Annotate | Revision Log
« no previous file with comments | « base/process_util_unittest.cc ('k') | base/test/multiprocess_test.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 *level = HIGH_INTEGRITY; 211 *level = HIGH_INTEGRITY;
212 } else { 212 } else {
213 NOTREACHED(); 213 NOTREACHED();
214 return false; 214 return false;
215 } 215 }
216 216
217 return true; 217 return true;
218 } 218 }
219 219
220 bool LaunchProcess(const string16& cmdline, 220 bool LaunchProcess(const string16& cmdline,
221 const LaunchOptions& options) { 221 const LaunchOptions& options,
222 ProcessHandle* process_handle) {
222 STARTUPINFO startup_info = {}; 223 STARTUPINFO startup_info = {};
223 startup_info.cb = sizeof(startup_info); 224 startup_info.cb = sizeof(startup_info);
224 if (options.empty_desktop_name) 225 if (options.empty_desktop_name)
225 startup_info.lpDesktop = L""; 226 startup_info.lpDesktop = L"";
226 startup_info.dwFlags = STARTF_USESHOWWINDOW; 227 startup_info.dwFlags = STARTF_USESHOWWINDOW;
227 startup_info.wShowWindow = options.start_hidden ? SW_HIDE : SW_SHOW; 228 startup_info.wShowWindow = options.start_hidden ? SW_HIDE : SW_SHOW;
228 PROCESS_INFORMATION process_info; 229 PROCESS_INFORMATION process_info;
229 230
230 if (options.as_user) { 231 if (options.as_user) {
231 DWORD flags = CREATE_UNICODE_ENVIRONMENT; 232 DWORD flags = CREATE_UNICODE_ENVIRONMENT;
(...skipping 20 matching lines...) Expand all
252 } 253 }
253 } 254 }
254 255
255 // Handles must be closed or they will leak. 256 // Handles must be closed or they will leak.
256 CloseHandle(process_info.hThread); 257 CloseHandle(process_info.hThread);
257 258
258 if (options.wait) 259 if (options.wait)
259 WaitForSingleObject(process_info.hProcess, INFINITE); 260 WaitForSingleObject(process_info.hProcess, INFINITE);
260 261
261 // If the caller wants the process handle, we won't close it. 262 // If the caller wants the process handle, we won't close it.
262 if (options.process_handle) { 263 if (process_handle) {
263 *options.process_handle = process_info.hProcess; 264 *process_handle = process_info.hProcess;
264 } else { 265 } else {
265 CloseHandle(process_info.hProcess); 266 CloseHandle(process_info.hProcess);
266 } 267 }
267 return true; 268 return true;
268 } 269 }
269 270
270 bool LaunchProcess(const CommandLine& cmdline, 271 bool LaunchProcess(const CommandLine& cmdline,
271 const LaunchOptions& options) { 272 const LaunchOptions& options,
272 return LaunchProcess(cmdline.command_line_string(), options); 273 ProcessHandle* process_handle) {
274 return LaunchProcess(cmdline.command_line_string(), options, process_handle);
273 } 275 }
274 276
275 // Attempts to kill the process identified by the given process 277 // Attempts to kill the process identified by the given process
276 // entry structure, giving it the specified exit code. 278 // entry structure, giving it the specified exit code.
277 // Returns true if this is successful, false otherwise. 279 // Returns true if this is successful, false otherwise.
278 bool KillProcessById(ProcessId process_id, int exit_code, bool wait) { 280 bool KillProcessById(ProcessId process_id, int exit_code, bool wait) {
279 HANDLE process = OpenProcess(PROCESS_TERMINATE | SYNCHRONIZE, 281 HANDLE process = OpenProcess(PROCESS_TERMINATE | SYNCHRONIZE,
280 FALSE, // Don't inherit handle 282 FALSE, // Don't inherit handle
281 process_id); 283 process_id);
282 if (!process) { 284 if (!process) {
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 866
865 PERFORMANCE_INFORMATION info; 867 PERFORMANCE_INFORMATION info;
866 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { 868 if (!InternalGetPerformanceInfo(&info, sizeof(info))) {
867 LOG(ERROR) << "Failed to fetch internal performance info."; 869 LOG(ERROR) << "Failed to fetch internal performance info.";
868 return 0; 870 return 0;
869 } 871 }
870 return (info.CommitTotal * system_info.dwPageSize) / 1024; 872 return (info.CommitTotal * system_info.dwPageSize) / 1024;
871 } 873 }
872 874
873 } // namespace base 875 } // namespace base
OLDNEW
« no previous file with comments | « base/process_util_unittest.cc ('k') | base/test/multiprocess_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698