OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <windows.h> | 7 #include <windows.h> |
8 #include <winternl.h> | 8 #include <winternl.h> |
9 #include <psapi.h> | 9 #include <psapi.h> |
10 | 10 |
11 #include "base/histogram.h" | 11 #include "base/histogram.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 // System pagesize. This value remains constant on x86/64 architectures. | 17 // System pagesize. This value remains constant on x86/64 architectures. |
18 const int PAGESIZE_KB = 4; | 18 const int PAGESIZE_KB = 4; |
19 | 19 |
20 // HeapSetInformation function pointer. | 20 // HeapSetInformation function pointer. |
21 typedef BOOL (WINAPI* HeapSetFn)(HANDLE, HEAP_INFORMATION_CLASS, PVOID, SIZE_T); | 21 typedef BOOL (WINAPI* HeapSetFn)(HANDLE, HEAP_INFORMATION_CLASS, PVOID, SIZE_T); |
22 | 22 |
23 } // namespace | 23 } // namespace |
24 | 24 |
25 namespace process_util { | 25 namespace base { |
26 | 26 |
27 int GetCurrentProcId() { | 27 int GetCurrentProcId() { |
28 return ::GetCurrentProcessId(); | 28 return ::GetCurrentProcessId(); |
29 } | 29 } |
30 | 30 |
31 ProcessHandle GetCurrentProcessHandle() { | 31 ProcessHandle GetCurrentProcessHandle() { |
32 return ::GetCurrentProcess(); | 32 return ::GetCurrentProcess(); |
33 } | 33 } |
34 | 34 |
35 // Helper for GetProcId() | 35 // Helper for GetProcId() |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 bool WaitForSingleProcess(ProcessHandle handle, int wait_milliseconds) { | 324 bool WaitForSingleProcess(ProcessHandle handle, int wait_milliseconds) { |
325 bool retval = WaitForSingleObject(handle, wait_milliseconds) == WAIT_OBJECT_0; | 325 bool retval = WaitForSingleObject(handle, wait_milliseconds) == WAIT_OBJECT_0; |
326 CloseHandle(handle); | 326 CloseHandle(handle); |
327 return retval; | 327 return retval; |
328 } | 328 } |
329 | 329 |
330 bool CleanupProcesses(const std::wstring& executable_name, | 330 bool CleanupProcesses(const std::wstring& executable_name, |
331 int wait_milliseconds, | 331 int wait_milliseconds, |
332 int exit_code, | 332 int exit_code, |
333 const ProcessFilter* filter) { | 333 const ProcessFilter* filter) { |
334 bool exited_cleanly = | 334 bool exited_cleanly = WaitForProcessesToExit(executable_name, |
335 process_util::WaitForProcessesToExit(executable_name, wait_milliseconds, | 335 wait_milliseconds, |
336 filter); | 336 filter); |
337 if (!exited_cleanly) | 337 if (!exited_cleanly) |
338 process_util::KillProcesses(executable_name, exit_code, filter); | 338 KillProcesses(executable_name, exit_code, filter); |
339 return exited_cleanly; | 339 return exited_cleanly; |
340 } | 340 } |
341 | 341 |
342 /////////////////////////////////////////////////////////////////////////////// | 342 /////////////////////////////////////////////////////////////////////////////// |
343 // ProcesMetrics | 343 // ProcesMetrics |
344 | 344 |
345 ProcessMetrics::ProcessMetrics(ProcessHandle process) : process_(process), | 345 ProcessMetrics::ProcessMetrics(ProcessHandle process) : process_(process), |
346 last_time_(0), | 346 last_time_(0), |
347 last_system_time_(0) { | 347 last_system_time_(0) { |
348 SYSTEM_INFO system_info; | 348 SYSTEM_INFO system_info; |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 | 610 |
611 void EnableTerminationOnHeapCorruption() { | 611 void EnableTerminationOnHeapCorruption() { |
612 // Ignore the result code. Supported on XP SP3 and Vista. | 612 // Ignore the result code. Supported on XP SP3 and Vista. |
613 HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); | 613 HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); |
614 } | 614 } |
615 | 615 |
616 void RaiseProcessToHighPriority() { | 616 void RaiseProcessToHighPriority() { |
617 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); | 617 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); |
618 } | 618 } |
619 | 619 |
620 } // namespace process_util | 620 } // namespace base |
OLD | NEW |