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

Side by Side Diff: base/process_util.cc

Issue 1689012: Move common code into process_util.cc (Closed)
Patch Set: More fixes Created 10 years, 7 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.h ('k') | base/process_util_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « base/process_util.h ('k') | base/process_util_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698