blob: 1937c5e683d10d27a3f47aea3acce6e60334c00e [file] [log] [blame]
Andrew Top0d1858f2019-05-15 22:01:47 -07001// 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.
4
5#include "base/process/process_iterator.h"
6#include "starboard/memory.h"
7
8namespace base {
9
10ProcessIterator::ProcessIterator(const ProcessFilter* filter)
11 : started_iteration_(false),
12 filter_(filter) {
13 snapshot_ = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
14}
15
16ProcessIterator::~ProcessIterator() {
17 CloseHandle(snapshot_);
18}
19
20bool ProcessIterator::CheckForNextProcess() {
21 InitProcessEntry(&entry_);
22
23 if (!started_iteration_) {
24 started_iteration_ = true;
25 return !!Process32First(snapshot_, &entry_);
26 }
27
28 return !!Process32Next(snapshot_, &entry_);
29}
30
31void ProcessIterator::InitProcessEntry(ProcessEntry* entry) {
32 SbMemorySet(entry, 0, sizeof(*entry));
33 entry->dwSize = sizeof(*entry);
34}
35
36bool NamedProcessIterator::IncludeEntry() {
37 // Case insensitive.
38 return _wcsicmp(executable_name_.c_str(), entry().exe_file()) == 0 &&
39 ProcessIterator::IncludeEntry();
40}
41
42} // namespace base