| 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 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 bool LaunchApp(const CommandLine& cl, | 146 bool LaunchApp(const CommandLine& cl, |
| 147 bool wait, bool start_hidden, ProcessHandle* process_handle) { | 147 bool wait, bool start_hidden, ProcessHandle* process_handle) { |
| 148 return LaunchApp(cl.command_line_string(), wait, | 148 return LaunchApp(cl.command_line_string(), wait, |
| 149 start_hidden, process_handle); | 149 start_hidden, process_handle); |
| 150 } | 150 } |
| 151 | 151 |
| 152 // Attempts to kill the process identified by the given process | 152 // Attempts to kill the process identified by the given process |
| 153 // entry structure, giving it the specified exit code. | 153 // entry structure, giving it the specified exit code. |
| 154 // Returns true if this is successful, false otherwise. | 154 // Returns true if this is successful, false otherwise. |
| 155 bool KillProcess(int process_id, int exit_code, bool wait) { | 155 bool KillProcess(int process_id, int exit_code, bool wait) { |
| 156 bool result = false; | |
| 157 HANDLE process = OpenProcess(PROCESS_TERMINATE | SYNCHRONIZE, | 156 HANDLE process = OpenProcess(PROCESS_TERMINATE | SYNCHRONIZE, |
| 158 FALSE, // Don't inherit handle | 157 FALSE, // Don't inherit handle |
| 159 process_id); | 158 process_id); |
| 160 if (process) { | 159 if (process) |
| 161 result = !!TerminateProcess(process, exit_code); | 160 return KillProcess(process, exit_code, wait); |
| 162 if (result && wait) { | 161 return false; |
| 163 // The process may not end immediately due to pending I/O | 162 } |
| 164 if (WAIT_OBJECT_0 != WaitForSingleObject(process, 60 * 1000)) | 163 |
| 165 DLOG(ERROR) << "Error waiting for process exit: " << GetLastError(); | 164 bool KillProcess(HANDLE process, int exit_code, bool wait) { |
| 166 } else { | 165 bool result = !!TerminateProcess(process, exit_code); |
| 167 DLOG(ERROR) << "Unable to terminate process: " << GetLastError(); | 166 if (result && wait) { |
| 168 } | 167 // The process may not end immediately due to pending I/O |
| 169 CloseHandle(process); | 168 if (WAIT_OBJECT_0 != WaitForSingleObject(process, 60 * 1000)) |
| 169 DLOG(ERROR) << "Error waiting for process exit: " << GetLastError(); |
| 170 } else { |
| 171 DLOG(ERROR) << "Unable to terminate process: " << GetLastError(); |
| 170 } | 172 } |
| 173 CloseHandle(process); |
| 171 return result; | 174 return result; |
| 172 } | 175 } |
| 173 | 176 |
| 174 bool DidProcessCrash(ProcessHandle handle) { | 177 bool DidProcessCrash(ProcessHandle handle) { |
| 175 DWORD exitcode = 0; | 178 DWORD exitcode = 0; |
| 176 if (!::GetExitCodeProcess(handle, &exitcode)) { | 179 if (!::GetExitCodeProcess(handle, &exitcode)) { |
| 177 NOTREACHED(); | 180 NOTREACHED(); |
| 178 return false; | 181 return false; |
| 179 } | 182 } |
| 180 if (exitcode == STILL_ACTIVE) { | 183 if (exitcode == STILL_ACTIVE) { |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 void EnableTerminationOnHeapCorruption() { | 626 void EnableTerminationOnHeapCorruption() { |
| 624 // Ignore the result code. Supported on XP SP3 and Vista. | 627 // Ignore the result code. Supported on XP SP3 and Vista. |
| 625 HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); | 628 HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); |
| 626 } | 629 } |
| 627 | 630 |
| 628 void RaiseProcessToHighPriority() { | 631 void RaiseProcessToHighPriority() { |
| 629 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); | 632 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); |
| 630 } | 633 } |
| 631 | 634 |
| 632 } // namespace base | 635 } // namespace base |
| OLD | NEW |