Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(444)

Side by Side Diff: base/process/kill_win.cc

Issue 938453002: Remove base::WaitForSingleProcess (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 182 }
183 183
184 bool WaitForExitCode(ProcessHandle handle, int* exit_code) { 184 bool WaitForExitCode(ProcessHandle handle, int* exit_code) {
185 // TODO(rvargas) crbug.com/417532: Remove this function. 185 // TODO(rvargas) crbug.com/417532: Remove this function.
186 Process process(handle); 186 Process process(handle);
187 return process.WaitForExit(exit_code); 187 return process.WaitForExit(exit_code);
188 } 188 }
189 189
190 bool WaitForExitCodeWithTimeout(ProcessHandle handle, 190 bool WaitForExitCodeWithTimeout(ProcessHandle handle,
191 int* exit_code, 191 int* exit_code,
192 base::TimeDelta timeout) { 192 TimeDelta timeout) {
193 if (::WaitForSingleObject( 193 if (::WaitForSingleObject(
194 handle, static_cast<DWORD>(timeout.InMilliseconds())) != WAIT_OBJECT_0) 194 handle, static_cast<DWORD>(timeout.InMilliseconds())) != WAIT_OBJECT_0)
195 return false; 195 return false;
196 DWORD temp_code; // Don't clobber out-parameters in case of failure. 196 DWORD temp_code; // Don't clobber out-parameters in case of failure.
197 if (!::GetExitCodeProcess(handle, &temp_code)) 197 if (!::GetExitCodeProcess(handle, &temp_code))
198 return false; 198 return false;
199 199
200 *exit_code = temp_code; 200 *exit_code = temp_code;
201 return true; 201 return true;
202 } 202 }
203 203
204 bool WaitForProcessesToExit(const FilePath::StringType& executable_name, 204 bool WaitForProcessesToExit(const FilePath::StringType& executable_name,
205 base::TimeDelta wait, 205 TimeDelta wait,
206 const ProcessFilter* filter) { 206 const ProcessFilter* filter) {
207 bool result = true; 207 bool result = true;
208 DWORD start_time = GetTickCount(); 208 DWORD start_time = GetTickCount();
209 209
210 NamedProcessIterator iter(executable_name, filter); 210 NamedProcessIterator iter(executable_name, filter);
211 for (const ProcessEntry* entry = iter.NextProcessEntry(); entry; 211 for (const ProcessEntry* entry = iter.NextProcessEntry(); entry;
212 entry = iter.NextProcessEntry()) { 212 entry = iter.NextProcessEntry()) {
213 DWORD remaining_wait = static_cast<DWORD>(std::max( 213 DWORD remaining_wait = static_cast<DWORD>(std::max(
214 static_cast<int64>(0), 214 static_cast<int64>(0),
215 wait.InMilliseconds() - (GetTickCount() - start_time))); 215 wait.InMilliseconds() - (GetTickCount() - start_time)));
216 HANDLE process = OpenProcess(SYNCHRONIZE, 216 HANDLE process = OpenProcess(SYNCHRONIZE,
217 FALSE, 217 FALSE,
218 entry->th32ProcessID); 218 entry->th32ProcessID);
219 DWORD wait_result = WaitForSingleObject(process, remaining_wait); 219 DWORD wait_result = WaitForSingleObject(process, remaining_wait);
220 CloseHandle(process); 220 CloseHandle(process);
221 result &= (wait_result == WAIT_OBJECT_0); 221 result &= (wait_result == WAIT_OBJECT_0);
222 } 222 }
223 223
224 return result; 224 return result;
225 } 225 }
226 226
227 bool WaitForSingleProcess(ProcessHandle handle, base::TimeDelta wait) {
228 int exit_code;
229 return WaitForExitCodeWithTimeout(handle, &exit_code, wait) && exit_code == 0;
Lei Zhang 2015/02/18 02:49:45 On Windows, we used to check the exit code, but wi
rvargas (doing something else) 2015/02/18 23:17:58 I don't think it matters. I added EXPECT_EQ(0, exi
230 }
231
232 bool CleanupProcesses(const FilePath::StringType& executable_name, 227 bool CleanupProcesses(const FilePath::StringType& executable_name,
233 base::TimeDelta wait, 228 TimeDelta wait,
234 int exit_code, 229 int exit_code,
235 const ProcessFilter* filter) { 230 const ProcessFilter* filter) {
236 if (WaitForProcessesToExit(executable_name, wait, filter)) 231 if (WaitForProcessesToExit(executable_name, wait, filter))
237 return true; 232 return true;
238 KillProcesses(executable_name, exit_code, filter); 233 KillProcesses(executable_name, exit_code, filter);
239 return false; 234 return false;
240 } 235 }
241 236
242 void EnsureProcessTerminated(Process process) { 237 void EnsureProcessTerminated(Process process) {
243 DCHECK(!process.is_current()); 238 DCHECK(!process.is_current());
244 239
245 // If already signaled, then we are done! 240 // If already signaled, then we are done!
246 if (WaitForSingleObject(process.Handle(), 0) == WAIT_OBJECT_0) { 241 if (WaitForSingleObject(process.Handle(), 0) == WAIT_OBJECT_0) {
247 return; 242 return;
248 } 243 }
249 244
250 MessageLoop::current()->PostDelayedTask( 245 MessageLoop::current()->PostDelayedTask(
251 FROM_HERE, 246 FROM_HERE,
252 base::Bind(&TimerExpiredTask::TimedOut, 247 Bind(&TimerExpiredTask::TimedOut,
253 base::Owned(new TimerExpiredTask(process.Pass()))), 248 Owned(new TimerExpiredTask(process.Pass()))),
254 base::TimeDelta::FromMilliseconds(kWaitInterval)); 249 TimeDelta::FromMilliseconds(kWaitInterval));
255 } 250 }
256 251
257 } // namespace base 252 } // namespace base
OLDNEW
« no previous file with comments | « base/process/kill_posix.cc ('k') | base/process/process.h » ('j') | ipc/ipc_test_base.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698