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

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

Issue 368133002: Fixes for re-enabling more MSVC level 4 warnings: base/ edition (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix build, attempt 2 Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « base/metrics/stats_table.cc ('k') | base/strings/safe_sprintf.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 if (!::GetExitCodeProcess(handle, &temp_code)) 193 if (!::GetExitCodeProcess(handle, &temp_code))
194 return false; 194 return false;
195 195
196 *exit_code = temp_code; 196 *exit_code = temp_code;
197 return true; 197 return true;
198 } 198 }
199 199
200 bool WaitForProcessesToExit(const FilePath::StringType& executable_name, 200 bool WaitForProcessesToExit(const FilePath::StringType& executable_name,
201 base::TimeDelta wait, 201 base::TimeDelta wait,
202 const ProcessFilter* filter) { 202 const ProcessFilter* filter) {
203 const ProcessEntry* entry;
204 bool result = true; 203 bool result = true;
205 DWORD start_time = GetTickCount(); 204 DWORD start_time = GetTickCount();
206 205
207 NamedProcessIterator iter(executable_name, filter); 206 NamedProcessIterator iter(executable_name, filter);
208 while ((entry = iter.NextProcessEntry())) { 207 for (const ProcessEntry* entry = iter.NextProcessEntry(); entry;
208 entry = iter.NextProcessEntry()) {
209 DWORD remaining_wait = std::max<int64>( 209 DWORD remaining_wait = std::max<int64>(
210 0, wait.InMilliseconds() - (GetTickCount() - start_time)); 210 0, wait.InMilliseconds() - (GetTickCount() - start_time));
211 HANDLE process = OpenProcess(SYNCHRONIZE, 211 HANDLE process = OpenProcess(SYNCHRONIZE,
212 FALSE, 212 FALSE,
213 entry->th32ProcessID); 213 entry->th32ProcessID);
214 DWORD wait_result = WaitForSingleObject(process, remaining_wait); 214 DWORD wait_result = WaitForSingleObject(process, remaining_wait);
215 CloseHandle(process); 215 CloseHandle(process);
216 result = result && (wait_result == WAIT_OBJECT_0); 216 result &= (wait_result == WAIT_OBJECT_0);
217 } 217 }
218 218
219 return result; 219 return result;
220 } 220 }
221 221
222 bool WaitForSingleProcess(ProcessHandle handle, base::TimeDelta wait) { 222 bool WaitForSingleProcess(ProcessHandle handle, base::TimeDelta wait) {
223 int exit_code; 223 int exit_code;
224 if (!WaitForExitCodeWithTimeout(handle, &exit_code, wait)) 224 return WaitForExitCodeWithTimeout(handle, &exit_code, wait) && exit_code == 0;
225 return false;
226 return exit_code == 0;
227 } 225 }
228 226
229 bool CleanupProcesses(const FilePath::StringType& executable_name, 227 bool CleanupProcesses(const FilePath::StringType& executable_name,
230 base::TimeDelta wait, 228 base::TimeDelta wait,
231 int exit_code, 229 int exit_code,
232 const ProcessFilter* filter) { 230 const ProcessFilter* filter) {
233 bool exited_cleanly = WaitForProcessesToExit(executable_name, wait, filter); 231 if (WaitForProcessesToExit(executable_name, wait, filter))
234 if (!exited_cleanly) 232 return true;
235 KillProcesses(executable_name, exit_code, filter); 233 KillProcesses(executable_name, exit_code, filter);
236 return exited_cleanly; 234 return false;
237 } 235 }
238 236
239 void EnsureProcessTerminated(ProcessHandle process) { 237 void EnsureProcessTerminated(ProcessHandle process) {
240 DCHECK(process != GetCurrentProcess()); 238 DCHECK(process != GetCurrentProcess());
241 239
242 // If already signaled, then we are done! 240 // If already signaled, then we are done!
243 if (WaitForSingleObject(process, 0) == WAIT_OBJECT_0) { 241 if (WaitForSingleObject(process, 0) == WAIT_OBJECT_0) {
244 CloseHandle(process); 242 CloseHandle(process);
245 return; 243 return;
246 } 244 }
247 245
248 MessageLoop::current()->PostDelayedTask( 246 MessageLoop::current()->PostDelayedTask(
249 FROM_HERE, 247 FROM_HERE,
250 base::Bind(&TimerExpiredTask::TimedOut, 248 base::Bind(&TimerExpiredTask::TimedOut,
251 base::Owned(new TimerExpiredTask(process))), 249 base::Owned(new TimerExpiredTask(process))),
252 base::TimeDelta::FromMilliseconds(kWaitInterval)); 250 base::TimeDelta::FromMilliseconds(kWaitInterval));
253 } 251 }
254 252
255 } // namespace base 253 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/stats_table.cc ('k') | base/strings/safe_sprintf.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698