| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 bool WaitForExitCode(ProcessHandle handle, int* exit_code) { | 180 bool WaitForExitCode(ProcessHandle handle, int* exit_code) { |
| 181 bool success = WaitForExitCodeWithTimeout( | 181 bool success = WaitForExitCodeWithTimeout( |
| 182 handle, exit_code, base::TimeDelta::FromMilliseconds(INFINITE)); | 182 handle, exit_code, base::TimeDelta::FromMilliseconds(INFINITE)); |
| 183 CloseProcessHandle(handle); | 183 CloseProcessHandle(handle); |
| 184 return success; | 184 return success; |
| 185 } | 185 } |
| 186 | 186 |
| 187 bool WaitForExitCodeWithTimeout(ProcessHandle handle, | 187 bool WaitForExitCodeWithTimeout(ProcessHandle handle, |
| 188 int* exit_code, | 188 int* exit_code, |
| 189 base::TimeDelta timeout) { | 189 base::TimeDelta timeout) { |
| 190 if (::WaitForSingleObject(handle, timeout.InMilliseconds()) != WAIT_OBJECT_0) | 190 if (::WaitForSingleObject( |
| 191 handle, static_cast<DWORD>(timeout.InMilliseconds())) != WAIT_OBJECT_0) |
| 191 return false; | 192 return false; |
| 192 DWORD temp_code; // Don't clobber out-parameters in case of failure. | 193 DWORD temp_code; // Don't clobber out-parameters in case of failure. |
| 193 if (!::GetExitCodeProcess(handle, &temp_code)) | 194 if (!::GetExitCodeProcess(handle, &temp_code)) |
| 194 return false; | 195 return false; |
| 195 | 196 |
| 196 *exit_code = temp_code; | 197 *exit_code = temp_code; |
| 197 return true; | 198 return true; |
| 198 } | 199 } |
| 199 | 200 |
| 200 bool WaitForProcessesToExit(const FilePath::StringType& executable_name, | 201 bool WaitForProcessesToExit(const FilePath::StringType& executable_name, |
| 201 base::TimeDelta wait, | 202 base::TimeDelta wait, |
| 202 const ProcessFilter* filter) { | 203 const ProcessFilter* filter) { |
| 203 bool result = true; | 204 bool result = true; |
| 204 DWORD start_time = GetTickCount(); | 205 DWORD start_time = GetTickCount(); |
| 205 | 206 |
| 206 NamedProcessIterator iter(executable_name, filter); | 207 NamedProcessIterator iter(executable_name, filter); |
| 207 for (const ProcessEntry* entry = iter.NextProcessEntry(); entry; | 208 for (const ProcessEntry* entry = iter.NextProcessEntry(); entry; |
| 208 entry = iter.NextProcessEntry()) { | 209 entry = iter.NextProcessEntry()) { |
| 209 DWORD remaining_wait = std::max<int64>( | 210 DWORD remaining_wait = static_cast<DWORD>(std::max( |
| 210 0, wait.InMilliseconds() - (GetTickCount() - start_time)); | 211 static_cast<int64>(0), |
| 212 wait.InMilliseconds() - (GetTickCount() - start_time))); |
| 211 HANDLE process = OpenProcess(SYNCHRONIZE, | 213 HANDLE process = OpenProcess(SYNCHRONIZE, |
| 212 FALSE, | 214 FALSE, |
| 213 entry->th32ProcessID); | 215 entry->th32ProcessID); |
| 214 DWORD wait_result = WaitForSingleObject(process, remaining_wait); | 216 DWORD wait_result = WaitForSingleObject(process, remaining_wait); |
| 215 CloseHandle(process); | 217 CloseHandle(process); |
| 216 result &= (wait_result == WAIT_OBJECT_0); | 218 result &= (wait_result == WAIT_OBJECT_0); |
| 217 } | 219 } |
| 218 | 220 |
| 219 return result; | 221 return result; |
| 220 } | 222 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 244 } | 246 } |
| 245 | 247 |
| 246 MessageLoop::current()->PostDelayedTask( | 248 MessageLoop::current()->PostDelayedTask( |
| 247 FROM_HERE, | 249 FROM_HERE, |
| 248 base::Bind(&TimerExpiredTask::TimedOut, | 250 base::Bind(&TimerExpiredTask::TimedOut, |
| 249 base::Owned(new TimerExpiredTask(process))), | 251 base::Owned(new TimerExpiredTask(process))), |
| 250 base::TimeDelta::FromMilliseconds(kWaitInterval)); | 252 base::TimeDelta::FromMilliseconds(kWaitInterval)); |
| 251 } | 253 } |
| 252 | 254 |
| 253 } // namespace base | 255 } // namespace base |
| OLD | NEW |