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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 case kKeyboardInterruptExitCode: // Control-C/end session. | 174 case kKeyboardInterruptExitCode: // Control-C/end session. |
175 case kDebuggerTerminatedExitCode: // Debugger terminated process. | 175 case kDebuggerTerminatedExitCode: // Debugger terminated process. |
176 case kProcessKilledExitCode: // Task manager kill. | 176 case kProcessKilledExitCode: // Task manager kill. |
177 return TERMINATION_STATUS_PROCESS_WAS_KILLED; | 177 return TERMINATION_STATUS_PROCESS_WAS_KILLED; |
178 default: | 178 default: |
179 // All other exit codes indicate crashes. | 179 // All other exit codes indicate crashes. |
180 return TERMINATION_STATUS_PROCESS_CRASHED; | 180 return TERMINATION_STATUS_PROCESS_CRASHED; |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
184 bool WaitForExitCode(ProcessHandle handle, int* exit_code) { | |
185 // TODO(rvargas) crbug.com/417532: Remove this function. | |
186 Process process(handle); | |
187 return process.WaitForExit(exit_code); | |
188 } | |
189 | |
190 bool WaitForExitCodeWithTimeout(ProcessHandle handle, | |
191 int* exit_code, | |
192 TimeDelta timeout) { | |
193 if (::WaitForSingleObject( | |
194 handle, static_cast<DWORD>(timeout.InMilliseconds())) != WAIT_OBJECT_0) | |
195 return false; | |
196 DWORD temp_code; // Don't clobber out-parameters in case of failure. | |
197 if (!::GetExitCodeProcess(handle, &temp_code)) | |
198 return false; | |
199 | |
200 *exit_code = temp_code; | |
201 return true; | |
202 } | |
203 | |
204 bool WaitForProcessesToExit(const FilePath::StringType& executable_name, | 184 bool WaitForProcessesToExit(const FilePath::StringType& executable_name, |
205 TimeDelta wait, | 185 TimeDelta wait, |
206 const ProcessFilter* filter) { | 186 const ProcessFilter* filter) { |
207 bool result = true; | 187 bool result = true; |
208 DWORD start_time = GetTickCount(); | 188 DWORD start_time = GetTickCount(); |
209 | 189 |
210 NamedProcessIterator iter(executable_name, filter); | 190 NamedProcessIterator iter(executable_name, filter); |
211 for (const ProcessEntry* entry = iter.NextProcessEntry(); entry; | 191 for (const ProcessEntry* entry = iter.NextProcessEntry(); entry; |
212 entry = iter.NextProcessEntry()) { | 192 entry = iter.NextProcessEntry()) { |
213 DWORD remaining_wait = static_cast<DWORD>(std::max( | 193 DWORD remaining_wait = static_cast<DWORD>(std::max( |
(...skipping 29 matching lines...) Expand all Loading... |
243 } | 223 } |
244 | 224 |
245 MessageLoop::current()->PostDelayedTask( | 225 MessageLoop::current()->PostDelayedTask( |
246 FROM_HERE, | 226 FROM_HERE, |
247 Bind(&TimerExpiredTask::TimedOut, | 227 Bind(&TimerExpiredTask::TimedOut, |
248 Owned(new TimerExpiredTask(process.Pass()))), | 228 Owned(new TimerExpiredTask(process.Pass()))), |
249 TimeDelta::FromMilliseconds(kWaitInterval)); | 229 TimeDelta::FromMilliseconds(kWaitInterval)); |
250 } | 230 } |
251 | 231 |
252 } // namespace base | 232 } // namespace base |
OLD | NEW |