| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/process_util.h" |
| 6 |
| 7 namespace base { |
| 8 |
| 9 int GetProcessCount(const std::wstring& executable_name, |
| 10 const ProcessFilter* filter) { |
| 11 int count = 0; |
| 12 NamedProcessIterator iter(executable_name, filter); |
| 13 while (iter.NextProcessEntry()) |
| 14 ++count; |
| 15 return count; |
| 16 } |
| 17 |
| 18 bool KillProcesses(const std::wstring& executable_name, int exit_code, |
| 19 const ProcessFilter* filter) { |
| 20 bool result = true; |
| 21 NamedProcessIterator iter(executable_name, filter); |
| 22 while (const ProcessEntry* entry = iter.NextProcessEntry()) { |
| 23 #if defined(OS_WIN) |
| 24 result &= KillProcessById(entry->pid(), exit_code, true); |
| 25 #else |
| 26 result &= KillProcess(entry->pid(), exit_code, true); |
| 27 #endif |
| 28 } |
| 29 return result; |
| 30 } |
| 31 |
| 32 const ProcessEntry* ProcessIterator::NextProcessEntry() { |
| 33 bool result = false; |
| 34 do { |
| 35 result = CheckForNextProcess(); |
| 36 } while (result && !IncludeEntry()); |
| 37 if (result) |
| 38 return &entry_; |
| 39 return NULL; |
| 40 } |
| 41 |
| 42 bool ProcessIterator::IncludeEntry() { |
| 43 return !filter_ || filter_->Includes(entry_); |
| 44 } |
| 45 |
| 46 std::list<ProcessEntry> ProcessIterator::Snapshot() { |
| 47 std::list<ProcessEntry> found; |
| 48 while (const ProcessEntry* process_entry = NextProcessEntry()) { |
| 49 found.push_back(*process_entry); |
| 50 } |
| 51 return found; |
| 52 } |
| 53 |
| 54 NamedProcessIterator::NamedProcessIterator(const std::wstring& executable_name, |
| 55 const ProcessFilter* filter) |
| 56 : ProcessIterator(filter), |
| 57 executable_name_(executable_name) { |
| 58 } |
| 59 |
| 60 NamedProcessIterator::~NamedProcessIterator() { |
| 61 } |
| 62 |
| 63 } // namespace base |
| OLD | NEW |