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

Side by Side Diff: base/process_util_win.cc

Issue 6794056: Revert 80472 - GTTF: Detect browser crashes on shutdown in UI tests.Previously the automation fra... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 8 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/process_util_posix.cc ('k') | chrome/browser/process_singleton_linux_uitest.cc » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_util.h" 5 #include "base/process_util.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <io.h> 8 #include <io.h>
9 #include <windows.h> 9 #include <windows.h>
10 #include <userenv.h> 10 #include <userenv.h>
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 case kProcessKilledExitCode: // Task manager kill. 457 case kProcessKilledExitCode: // Task manager kill.
458 return TERMINATION_STATUS_PROCESS_WAS_KILLED; 458 return TERMINATION_STATUS_PROCESS_WAS_KILLED;
459 default: 459 default:
460 // All other exit codes indicate crashes. 460 // All other exit codes indicate crashes.
461 return TERMINATION_STATUS_PROCESS_CRASHED; 461 return TERMINATION_STATUS_PROCESS_CRASHED;
462 } 462 }
463 } 463 }
464 464
465 bool WaitForExitCode(ProcessHandle handle, int* exit_code) { 465 bool WaitForExitCode(ProcessHandle handle, int* exit_code) {
466 bool success = WaitForExitCodeWithTimeout(handle, exit_code, INFINITE); 466 bool success = WaitForExitCodeWithTimeout(handle, exit_code, INFINITE);
467 CloseProcessHandle(handle); 467 if (!success)
468 CloseProcessHandle(handle);
468 return success; 469 return success;
469 } 470 }
470 471
471 bool WaitForExitCodeWithTimeout(ProcessHandle handle, int* exit_code, 472 bool WaitForExitCodeWithTimeout(ProcessHandle handle, int* exit_code,
472 int64 timeout_milliseconds) { 473 int64 timeout_milliseconds) {
473 if (::WaitForSingleObject(handle, timeout_milliseconds) != WAIT_OBJECT_0) 474 if (::WaitForSingleObject(handle, timeout_milliseconds) != WAIT_OBJECT_0)
474 return false; 475 return false;
475 DWORD temp_code; // Don't clobber out-parameters in case of failure. 476 DWORD temp_code; // Don't clobber out-parameters in case of failure.
476 if (!::GetExitCodeProcess(handle, &temp_code)) 477 if (!::GetExitCodeProcess(handle, &temp_code))
477 return false; 478 return false;
478 479
480 // Only close the handle on success, to give the caller a chance to forcefully
481 // terminate the process if he wants to.
482 CloseProcessHandle(handle);
483
479 *exit_code = temp_code; 484 *exit_code = temp_code;
480 return true; 485 return true;
481 } 486 }
482 487
483 ProcessIterator::ProcessIterator(const ProcessFilter* filter) 488 ProcessIterator::ProcessIterator(const ProcessFilter* filter)
484 : started_iteration_(false), 489 : started_iteration_(false),
485 filter_(filter) { 490 filter_(filter) {
486 snapshot_ = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 491 snapshot_ = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
487 } 492 }
488 493
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 } 537 }
533 538
534 return result; 539 return result;
535 } 540 }
536 541
537 bool WaitForSingleProcess(ProcessHandle handle, int64 wait_milliseconds) { 542 bool WaitForSingleProcess(ProcessHandle handle, int64 wait_milliseconds) {
538 bool retval = WaitForSingleObject(handle, wait_milliseconds) == WAIT_OBJECT_0; 543 bool retval = WaitForSingleObject(handle, wait_milliseconds) == WAIT_OBJECT_0;
539 return retval; 544 return retval;
540 } 545 }
541 546
547 bool CrashAwareSleep(ProcessHandle handle, int64 wait_milliseconds) {
548 bool retval = WaitForSingleObject(handle, wait_milliseconds) == WAIT_TIMEOUT;
549 return retval;
550 }
551
542 bool CleanupProcesses(const std::wstring& executable_name, 552 bool CleanupProcesses(const std::wstring& executable_name,
543 int64 wait_milliseconds, 553 int64 wait_milliseconds,
544 int exit_code, 554 int exit_code,
545 const ProcessFilter* filter) { 555 const ProcessFilter* filter) {
546 bool exited_cleanly = WaitForProcessesToExit(executable_name, 556 bool exited_cleanly = WaitForProcessesToExit(executable_name,
547 wait_milliseconds, 557 wait_milliseconds,
548 filter); 558 filter);
549 if (!exited_cleanly) 559 if (!exited_cleanly)
550 KillProcesses(executable_name, exit_code, filter); 560 KillProcesses(executable_name, exit_code, filter);
551 return exited_cleanly; 561 return exited_cleanly;
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 909
900 PERFORMANCE_INFORMATION info; 910 PERFORMANCE_INFORMATION info;
901 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { 911 if (!InternalGetPerformanceInfo(&info, sizeof(info))) {
902 LOG(ERROR) << "Failed to fetch internal performance info."; 912 LOG(ERROR) << "Failed to fetch internal performance info.";
903 return 0; 913 return 0;
904 } 914 }
905 return (info.CommitTotal * system_info.dwPageSize) / 1024; 915 return (info.CommitTotal * system_info.dwPageSize) / 1024;
906 } 916 }
907 917
908 } // namespace base 918 } // namespace base
OLDNEW
« no previous file with comments | « base/process_util_posix.cc ('k') | chrome/browser/process_singleton_linux_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698