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

Side by Side Diff: base/process_util_win.cc

Issue 10808069: Remove old test timeout and process waiting function interfaces. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove old test timeout and wait for process interfaces. Created 8 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
« no previous file with comments | « base/process_util_posix.cc ('k') | base/test/test_timeouts.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 } 539 }
540 540
541 bool WaitForExitCode(ProcessHandle handle, int* exit_code) { 541 bool WaitForExitCode(ProcessHandle handle, int* exit_code) {
542 bool success = WaitForExitCodeWithTimeout( 542 bool success = WaitForExitCodeWithTimeout(
543 handle, exit_code, base::TimeDelta::FromMilliseconds(INFINITE)); 543 handle, exit_code, base::TimeDelta::FromMilliseconds(INFINITE));
544 CloseProcessHandle(handle); 544 CloseProcessHandle(handle);
545 return success; 545 return success;
546 } 546 }
547 547
548 bool WaitForExitCodeWithTimeout(ProcessHandle handle, int* exit_code, 548 bool WaitForExitCodeWithTimeout(ProcessHandle handle, int* exit_code,
549 int64 timeout_milliseconds) { 549 base::TimeDelta timeout) {
550 if (::WaitForSingleObject(handle, timeout_milliseconds) != WAIT_OBJECT_0) 550 if (::WaitForSingleObject(handle, timeout.InMilliseconds()) != WAIT_OBJECT_0)
551 return false; 551 return false;
552 DWORD temp_code; // Don't clobber out-parameters in case of failure. 552 DWORD temp_code; // Don't clobber out-parameters in case of failure.
553 if (!::GetExitCodeProcess(handle, &temp_code)) 553 if (!::GetExitCodeProcess(handle, &temp_code))
554 return false; 554 return false;
555 555
556 *exit_code = temp_code; 556 *exit_code = temp_code;
557 return true; 557 return true;
558 } 558 }
559 559
560 bool WaitForExitCodeWithTimeout(ProcessHandle handle, int* exit_code,
561 base::TimeDelta timeout) {
562 return WaitForExitCodeWithTimeout(
563 handle, exit_code, timeout.InMilliseconds());
564 }
565
566 ProcessIterator::ProcessIterator(const ProcessFilter* filter) 560 ProcessIterator::ProcessIterator(const ProcessFilter* filter)
567 : started_iteration_(false), 561 : started_iteration_(false),
568 filter_(filter) { 562 filter_(filter) {
569 snapshot_ = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 563 snapshot_ = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
570 } 564 }
571 565
572 ProcessIterator::~ProcessIterator() { 566 ProcessIterator::~ProcessIterator() {
573 CloseHandle(snapshot_); 567 CloseHandle(snapshot_);
574 } 568 }
575 569
(...skipping 12 matching lines...) Expand all
588 memset(entry, 0, sizeof(*entry)); 582 memset(entry, 0, sizeof(*entry));
589 entry->dwSize = sizeof(*entry); 583 entry->dwSize = sizeof(*entry);
590 } 584 }
591 585
592 bool NamedProcessIterator::IncludeEntry() { 586 bool NamedProcessIterator::IncludeEntry() {
593 // Case insensitive. 587 // Case insensitive.
594 return _wcsicmp(executable_name_.c_str(), entry().exe_file()) == 0 && 588 return _wcsicmp(executable_name_.c_str(), entry().exe_file()) == 0 &&
595 ProcessIterator::IncludeEntry(); 589 ProcessIterator::IncludeEntry();
596 } 590 }
597 591
598 bool WaitForProcessesToExit(const FilePath::StringType& executable_name, 592 bool WaitForProcessesToExit(const FilePath::StringType& executable_name,
jar (doing other things) 2012/07/25 19:03:19 Who is calling this now? Should this be deleted?
599 int64 wait_milliseconds, 593 int64 wait_milliseconds,
600 const ProcessFilter* filter) { 594 const ProcessFilter* filter) {
601 const ProcessEntry* entry; 595 const ProcessEntry* entry;
602 bool result = true; 596 bool result = true;
603 DWORD start_time = GetTickCount(); 597 DWORD start_time = GetTickCount();
604 598
605 NamedProcessIterator iter(executable_name, filter); 599 NamedProcessIterator iter(executable_name, filter);
606 while ((entry = iter.NextProcessEntry())) { 600 while ((entry = iter.NextProcessEntry())) {
607 DWORD remaining_wait = 601 DWORD remaining_wait =
608 std::max<int64>(0, wait_milliseconds - (GetTickCount() - start_time)); 602 std::max<int64>(0, wait_milliseconds - (GetTickCount() - start_time));
609 HANDLE process = OpenProcess(SYNCHRONIZE, 603 HANDLE process = OpenProcess(SYNCHRONIZE,
610 FALSE, 604 FALSE,
611 entry->th32ProcessID); 605 entry->th32ProcessID);
612 DWORD wait_result = WaitForSingleObject(process, remaining_wait); 606 DWORD wait_result = WaitForSingleObject(process, remaining_wait);
613 CloseHandle(process); 607 CloseHandle(process);
614 result = result && (wait_result == WAIT_OBJECT_0); 608 result = result && (wait_result == WAIT_OBJECT_0);
615 } 609 }
616 610
617 return result; 611 return result;
618 } 612 }
619 613
620 bool WaitForProcessesToExit(const FilePath::StringType& executable_name, 614 bool WaitForProcessesToExit(const FilePath::StringType& executable_name,
621 base::TimeDelta wait, 615 base::TimeDelta wait,
622 const ProcessFilter* filter) { 616 const ProcessFilter* filter) {
623 return WaitForProcessesToExit(executable_name, wait.InMilliseconds(), filter); 617 const ProcessEntry* entry;
624 } 618 bool result = true;
619 DWORD start_time = GetTickCount();
625 620
626 bool WaitForSingleProcess(ProcessHandle handle, int64 wait_milliseconds) { 621 NamedProcessIterator iter(executable_name, filter);
627 return WaitForSingleProcess( 622 while ((entry = iter.NextProcessEntry())) {
628 handle, base::TimeDelta::FromMilliseconds(wait_milliseconds)); 623 DWORD remaining_wait =
624 std::max<int64>(0,
jar (doing other things) 2012/07/25 19:03:19 nit: Don't bother to wrap line 623 given that you'
625 wait.InMilliseconds() - (GetTickCount() - start_time));
626 HANDLE process = OpenProcess(SYNCHRONIZE,
627 FALSE,
628 entry->th32ProcessID);
629 DWORD wait_result = WaitForSingleObject(process, remaining_wait);
630 CloseHandle(process);
631 result = result && (wait_result == WAIT_OBJECT_0);
632 }
633
634 return result;
629 } 635 }
630 636
631 bool WaitForSingleProcess(ProcessHandle handle, base::TimeDelta wait) { 637 bool WaitForSingleProcess(ProcessHandle handle, base::TimeDelta wait) {
632 int exit_code; 638 int exit_code;
633 if (!WaitForExitCodeWithTimeout(handle, &exit_code, wait)) 639 if (!WaitForExitCodeWithTimeout(handle, &exit_code, wait))
634 return false; 640 return false;
635 return exit_code == 0; 641 return exit_code == 0;
636 } 642 }
637 643
638 bool CleanupProcesses(const FilePath::StringType& executable_name, 644 bool CleanupProcesses(const FilePath::StringType& executable_name,
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 1020
1015 PERFORMANCE_INFORMATION info; 1021 PERFORMANCE_INFORMATION info;
1016 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { 1022 if (!InternalGetPerformanceInfo(&info, sizeof(info))) {
1017 DLOG(ERROR) << "Failed to fetch internal performance info."; 1023 DLOG(ERROR) << "Failed to fetch internal performance info.";
1018 return 0; 1024 return 0;
1019 } 1025 }
1020 return (info.CommitTotal * system_info.dwPageSize) / 1024; 1026 return (info.CommitTotal * system_info.dwPageSize) / 1024;
1021 } 1027 }
1022 1028
1023 } // namespace base 1029 } // namespace base
OLDNEW
« no previous file with comments | « base/process_util_posix.cc ('k') | base/test/test_timeouts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698