1 // Copyright (c) 2013 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.
5 #include "base/process/process_iterator.h"
10 ProcessEntry::ProcessEntry() : pid_(0), ppid_(0), gid_(0) {}
11 ProcessEntry::~ProcessEntry() {}
14 const ProcessEntry
* ProcessIterator::NextProcessEntry() {
17 result
= CheckForNextProcess();
18 } while (result
&& !IncludeEntry());
24 ProcessIterator::ProcessEntries
ProcessIterator::Snapshot() {
26 while (const ProcessEntry
* process_entry
= NextProcessEntry()) {
27 found
.push_back(*process_entry
);
32 bool ProcessIterator::IncludeEntry() {
33 return !filter_
|| filter_
->Includes(entry_
);
36 NamedProcessIterator::NamedProcessIterator(
37 const FilePath::StringType
& executable_name
,
38 const ProcessFilter
* filter
) : ProcessIterator(filter
),
39 executable_name_(executable_name
) {
40 #if defined(OS_ANDROID)
41 // On Android, the process name contains only the last 15 characters, which
42 // is in file /proc/<pid>/stat, the string between open parenthesis and close
43 // parenthesis. Please See ProcessIterator::CheckForNextProcess for details.
44 // Now if the length of input process name is greater than 15, only save the
45 // last 15 characters.
46 if (executable_name_
.size() > 15) {
47 executable_name_
= FilePath::StringType(executable_name_
,
48 executable_name_
.size() - 15, 15);
53 NamedProcessIterator::~NamedProcessIterator() {
56 int GetProcessCount(const FilePath::StringType
& executable_name
,
57 const ProcessFilter
* filter
) {
59 NamedProcessIterator
iter(executable_name
, filter
);
60 while (iter
.NextProcessEntry())