Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/kill.h" | 5 #include "base/process/kill.h" |
| 6 | 6 |
| 7 #include <io.h> | 7 #include <io.h> |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 if (result && wait) { | 96 if (result && wait) { |
| 97 // The process may not end immediately due to pending I/O | 97 // The process may not end immediately due to pending I/O |
| 98 if (WAIT_OBJECT_0 != WaitForSingleObject(process, 60 * 1000)) | 98 if (WAIT_OBJECT_0 != WaitForSingleObject(process, 60 * 1000)) |
| 99 DLOG_GETLASTERROR(ERROR) << "Error waiting for process exit"; | 99 DLOG_GETLASTERROR(ERROR) << "Error waiting for process exit"; |
| 100 } else if (!result) { | 100 } else if (!result) { |
| 101 DLOG_GETLASTERROR(ERROR) << "Unable to terminate process"; | 101 DLOG_GETLASTERROR(ERROR) << "Unable to terminate process"; |
| 102 } | 102 } |
| 103 return result; | 103 return result; |
| 104 } | 104 } |
| 105 | 105 |
| 106 bool KillJob(HANDLE job, int exit_code, bool wait) { | |
| 107 bool result = (TerminateJobObject(job, exit_code) != FALSE); | |
| 108 if (result && wait) { | |
| 109 // The processes may not end immediately due to pending I/O | |
|
Paweł Hajdan Jr.
2014/04/23 10:49:22
nit: Please end all comments with a dot.
| |
| 110 if (WAIT_OBJECT_0 != WaitForSingleObject(job, 60 * 1000)) | |
| 111 DLOG_GETLASTERROR(ERROR) << "Error waiting for job exit"; | |
|
Paweł Hajdan Jr.
2014/04/23 10:49:22
With this wait=true is effectively a no-op in case
| |
| 112 } else if (!result) { | |
| 113 DLOG_GETLASTERROR(ERROR) << "Unable to terminate job"; | |
| 114 } | |
| 115 return result; | |
| 116 } | |
| 117 | |
| 106 // Attempts to kill the process identified by the given process | 118 // Attempts to kill the process identified by the given process |
| 107 // entry structure, giving it the specified exit code. | 119 // entry structure, giving it the specified exit code. |
| 108 // Returns true if this is successful, false otherwise. | 120 // Returns true if this is successful, false otherwise. |
| 109 bool KillProcessById(ProcessId process_id, int exit_code, bool wait) { | 121 bool KillProcessById(ProcessId process_id, int exit_code, bool wait) { |
| 110 HANDLE process = OpenProcess(PROCESS_TERMINATE | SYNCHRONIZE, | 122 HANDLE process = OpenProcess(PROCESS_TERMINATE | SYNCHRONIZE, |
| 111 FALSE, // Don't inherit handle | 123 FALSE, // Don't inherit handle |
| 112 process_id); | 124 process_id); |
| 113 if (!process) { | 125 if (!process) { |
| 114 DLOG_GETLASTERROR(ERROR) << "Unable to open process " << process_id; | 126 DLOG_GETLASTERROR(ERROR) << "Unable to open process " << process_id; |
| 115 return false; | 127 return false; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 } | 258 } |
| 247 | 259 |
| 248 MessageLoop::current()->PostDelayedTask( | 260 MessageLoop::current()->PostDelayedTask( |
| 249 FROM_HERE, | 261 FROM_HERE, |
| 250 base::Bind(&TimerExpiredTask::TimedOut, | 262 base::Bind(&TimerExpiredTask::TimedOut, |
| 251 base::Owned(new TimerExpiredTask(process))), | 263 base::Owned(new TimerExpiredTask(process))), |
| 252 base::TimeDelta::FromMilliseconds(kWaitInterval)); | 264 base::TimeDelta::FromMilliseconds(kWaitInterval)); |
| 253 } | 265 } |
| 254 | 266 |
| 255 } // namespace base | 267 } // namespace base |
| OLD | NEW |