Thanks to visit codestin.com
Credit goes to chromium.googlesource.com

blob: f3951fdb81e793544b75d522218285093023eef8 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2013 The Chromium Authors
[email protected]d3acb672013-05-31 15:38:012// 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
Tom Sepez978847c2025-03-22 03:43:597#include "base/compiler_specific.h"
jdoerrie5c4dc4e2019-02-01 18:02:338#include "base/strings/string_util.h"
9
[email protected]d3acb672013-05-31 15:38:0110namespace base {
11
12ProcessIterator::ProcessIterator(const ProcessFilter* filter)
Lei Zhang6f418e02023-02-08 21:55:4313 : snapshot_(CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)),
14 filter_(filter) {}
[email protected]d3acb672013-05-31 15:38:0115
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) {
Tom Sepez978847c2025-03-22 03:43:5932 UNSAFE_TODO(memset(entry, 0, sizeof(*entry)));
[email protected]d3acb672013-05-31 15:38:0133 entry->dwSize = sizeof(*entry);
34}
35
36bool NamedProcessIterator::IncludeEntry() {
37 // Case insensitive.
Tom Sepez978847c2025-03-22 03:43:5938 return UNSAFE_TODO(!_wcsicmp(executable_name_.c_str(), entry().exe_file())) &&
[email protected]d3acb672013-05-31 15:38:0139 ProcessIterator::IncludeEntry();
40}
41
42} // namespace base