diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-29 17:44:42 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-29 17:44:42 +0000 |
commit | b6128aaba9e7c148d1a71710b1d7de5d101f9967 (patch) | |
tree | dca19e0d51b91edcd5e2203de2f3158c64bcdb5c /base/process_util_win.cc | |
parent | a65b0ba084b3b197f817b88bd21b275e1790a629 (diff) | |
download | chromium_src-b6128aaba9e7c148d1a71710b1d7de5d101f9967.zip chromium_src-b6128aaba9e7c148d1a71710b1d7de5d101f9967.tar.gz chromium_src-b6128aaba9e7c148d1a71710b1d7de5d101f9967.tar.bz2 |
Move common code into process_util.cc.
Fix namespace usage.
Change ProcessEntry to have a common interface accross platforms and change ProcessFilter::Includes() to make use of it.
Split NamedProcessIterator in two.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/1689012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45953 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_win.cc')
-rw-r--r-- | base/process_util_win.cc | 64 |
1 files changed, 13 insertions, 51 deletions
diff --git a/base/process_util_win.cc b/base/process_util_win.cc index 3299f60..8df8de5 100644 --- a/base/process_util_win.cc +++ b/base/process_util_win.cc @@ -222,9 +222,11 @@ bool KillProcessById(ProcessId process_id, int exit_code, bool wait) { HANDLE process = OpenProcess(PROCESS_TERMINATE | SYNCHRONIZE, FALSE, // Don't inherit handle process_id); - if (!process) + if (!process) { + DLOG(ERROR) << "Unable to open process " << process_id << " : " + << GetLastError(); return false; - + } bool ret = KillProcess(process, exit_code, wait); CloseHandle(process); return ret; @@ -384,33 +386,17 @@ bool WaitForExitCodeWithTimeout(ProcessHandle handle, int* exit_code, return true; } -NamedProcessIterator::NamedProcessIterator(const std::wstring& executable_name, - const ProcessFilter* filter) +ProcessIterator::ProcessIterator(const ProcessFilter* filter) : started_iteration_(false), - executable_name_(executable_name), filter_(filter) { snapshot_ = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); } -NamedProcessIterator::~NamedProcessIterator() { +ProcessIterator::~ProcessIterator() { CloseHandle(snapshot_); } - -const ProcessEntry* NamedProcessIterator::NextProcessEntry() { - bool result = false; - do { - result = CheckForNextProcess(); - } while (result && !IncludeEntry()); - - if (result) { - return &entry_; - } - - return NULL; -} - -bool NamedProcessIterator::CheckForNextProcess() { +bool ProcessIterator::CheckForNextProcess() { InitProcessEntry(&entry_); if (!started_iteration_) { @@ -421,39 +407,15 @@ bool NamedProcessIterator::CheckForNextProcess() { return !!Process32Next(snapshot_, &entry_); } -bool NamedProcessIterator::IncludeEntry() { - return _wcsicmp(executable_name_.c_str(), entry_.szExeFile) == 0 && - (!filter_ || filter_->Includes(entry_.th32ProcessID, - entry_.th32ParentProcessID)); -} - -void NamedProcessIterator::InitProcessEntry(ProcessEntry* entry) { +void ProcessIterator::InitProcessEntry(ProcessEntry* entry) { memset(entry, 0, sizeof(*entry)); entry->dwSize = sizeof(*entry); } -int GetProcessCount(const std::wstring& executable_name, - const ProcessFilter* filter) { - int count = 0; - - NamedProcessIterator iter(executable_name, filter); - while (iter.NextProcessEntry()) - ++count; - return count; -} - -bool KillProcesses(const std::wstring& executable_name, int exit_code, - const ProcessFilter* filter) { - bool result = true; - const ProcessEntry* entry; - - NamedProcessIterator iter(executable_name, filter); - while (entry = iter.NextProcessEntry()) { - if (!KillProcessById((*entry).th32ProcessID, exit_code, true)) - result = false; - } - - return result; +bool NamedProcessIterator::IncludeEntry() { + // Case insensitive. + return _wcsicmp(executable_name_.c_str(), entry().exe_file()) == 0 && + ProcessIterator::IncludeEntry(); } bool WaitForProcessesToExit(const std::wstring& executable_name, @@ -722,7 +684,7 @@ double ProcessMetrics::GetCPUUsage() { return cpu; } -bool ProcessMetrics::GetIOCounters(base::IoCounters* io_counters) const { +bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const { return GetProcessIoCounters(process_, io_counters) != FALSE; } |