| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 NamedProcessIterator iter(executable_name, filter); | 422 NamedProcessIterator iter(executable_name, filter); |
| 423 while (entry = iter.NextProcessEntry()) { | 423 while (entry = iter.NextProcessEntry()) { |
| 424 if (!KillProcessById((*entry).th32ProcessID, exit_code, true)) | 424 if (!KillProcessById((*entry).th32ProcessID, exit_code, true)) |
| 425 result = false; | 425 result = false; |
| 426 } | 426 } |
| 427 | 427 |
| 428 return result; | 428 return result; |
| 429 } | 429 } |
| 430 | 430 |
| 431 bool WaitForProcessesToExit(const std::wstring& executable_name, | 431 bool WaitForProcessesToExit(const std::wstring& executable_name, |
| 432 int wait_milliseconds, | 432 int64 wait_milliseconds, |
| 433 const ProcessFilter* filter) { | 433 const ProcessFilter* filter) { |
| 434 const ProcessEntry* entry; | 434 const ProcessEntry* entry; |
| 435 bool result = true; | 435 bool result = true; |
| 436 DWORD start_time = GetTickCount(); | 436 DWORD start_time = GetTickCount(); |
| 437 | 437 |
| 438 NamedProcessIterator iter(executable_name, filter); | 438 NamedProcessIterator iter(executable_name, filter); |
| 439 while (entry = iter.NextProcessEntry()) { | 439 while (entry = iter.NextProcessEntry()) { |
| 440 DWORD remaining_wait = | 440 DWORD remaining_wait = |
| 441 std::max(0, wait_milliseconds - | 441 std::max<int64>(0, wait_milliseconds - (GetTickCount() - start_time)); |
| 442 static_cast<int>(GetTickCount() - start_time)); | |
| 443 HANDLE process = OpenProcess(SYNCHRONIZE, | 442 HANDLE process = OpenProcess(SYNCHRONIZE, |
| 444 FALSE, | 443 FALSE, |
| 445 entry->th32ProcessID); | 444 entry->th32ProcessID); |
| 446 DWORD wait_result = WaitForSingleObject(process, remaining_wait); | 445 DWORD wait_result = WaitForSingleObject(process, remaining_wait); |
| 447 CloseHandle(process); | 446 CloseHandle(process); |
| 448 result = result && (wait_result == WAIT_OBJECT_0); | 447 result = result && (wait_result == WAIT_OBJECT_0); |
| 449 } | 448 } |
| 450 | 449 |
| 451 return result; | 450 return result; |
| 452 } | 451 } |
| 453 | 452 |
| 454 bool WaitForSingleProcess(ProcessHandle handle, int wait_milliseconds) { | 453 bool WaitForSingleProcess(ProcessHandle handle, int64 wait_milliseconds) { |
| 455 bool retval = WaitForSingleObject(handle, wait_milliseconds) == WAIT_OBJECT_0; | 454 bool retval = WaitForSingleObject(handle, wait_milliseconds) == WAIT_OBJECT_0; |
| 456 return retval; | 455 return retval; |
| 457 } | 456 } |
| 458 | 457 |
| 459 bool CrashAwareSleep(ProcessHandle handle, int wait_milliseconds) { | 458 bool CrashAwareSleep(ProcessHandle handle, int64 wait_milliseconds) { |
| 460 bool retval = WaitForSingleObject(handle, wait_milliseconds) == WAIT_TIMEOUT; | 459 bool retval = WaitForSingleObject(handle, wait_milliseconds) == WAIT_TIMEOUT; |
| 461 return retval; | 460 return retval; |
| 462 } | 461 } |
| 463 | 462 |
| 464 bool CleanupProcesses(const std::wstring& executable_name, | 463 bool CleanupProcesses(const std::wstring& executable_name, |
| 465 int wait_milliseconds, | 464 int64 wait_milliseconds, |
| 466 int exit_code, | 465 int exit_code, |
| 467 const ProcessFilter* filter) { | 466 const ProcessFilter* filter) { |
| 468 bool exited_cleanly = WaitForProcessesToExit(executable_name, | 467 bool exited_cleanly = WaitForProcessesToExit(executable_name, |
| 469 wait_milliseconds, | 468 wait_milliseconds, |
| 470 filter); | 469 filter); |
| 471 if (!exited_cleanly) | 470 if (!exited_cleanly) |
| 472 KillProcesses(executable_name, exit_code, filter); | 471 KillProcesses(executable_name, exit_code, filter); |
| 473 return exited_cleanly; | 472 return exited_cleanly; |
| 474 } | 473 } |
| 475 | 474 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 void EnableTerminationOnHeapCorruption() { | 762 void EnableTerminationOnHeapCorruption() { |
| 764 // Ignore the result code. Supported on XP SP3 and Vista. | 763 // Ignore the result code. Supported on XP SP3 and Vista. |
| 765 HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); | 764 HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); |
| 766 } | 765 } |
| 767 | 766 |
| 768 void RaiseProcessToHighPriority() { | 767 void RaiseProcessToHighPriority() { |
| 769 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); | 768 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); |
| 770 } | 769 } |
| 771 | 770 |
| 772 } // namespace base | 771 } // namespace base |
| OLD | NEW |