1 // Copyright 2013 The Chromium Authors 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 7 #include "base/strings/string_util.h" 8 9 namespace base { 10 ProcessIterator(const ProcessFilter * filter)11ProcessIterator::ProcessIterator(const ProcessFilter* filter) 12 : snapshot_(CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)), 13 filter_(filter) {} 14 ~ProcessIterator()15ProcessIterator::~ProcessIterator() { 16 CloseHandle(snapshot_); 17 } 18 CheckForNextProcess()19bool ProcessIterator::CheckForNextProcess() { 20 InitProcessEntry(&entry_); 21 22 if (!started_iteration_) { 23 started_iteration_ = true; 24 return !!Process32First(snapshot_, &entry_); 25 } 26 27 return !!Process32Next(snapshot_, &entry_); 28 } 29 InitProcessEntry(ProcessEntry * entry)30void ProcessIterator::InitProcessEntry(ProcessEntry* entry) { 31 memset(entry, 0, sizeof(*entry)); 32 entry->dwSize = sizeof(*entry); 33 } 34 IncludeEntry()35bool NamedProcessIterator::IncludeEntry() { 36 // Case insensitive. 37 return !_wcsicmp(executable_name_.c_str(), entry().exe_file()) && 38 ProcessIterator::IncludeEntry(); 39 } 40 41 } // namespace base 42