Andrew Top | 0d1858f | 2019-05-15 22:01:47 -0700 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "base/process/process_iterator.h" |
| 6 | #include "starboard/memory.h" |
| 7 | |
| 8 | namespace base { |
| 9 | |
| 10 | ProcessIterator::ProcessIterator(const ProcessFilter* filter) |
| 11 | : started_iteration_(false), |
| 12 | filter_(filter) { |
| 13 | snapshot_ = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
| 14 | } |
| 15 | |
| 16 | ProcessIterator::~ProcessIterator() { |
| 17 | CloseHandle(snapshot_); |
| 18 | } |
| 19 | |
| 20 | bool 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 | |
| 31 | void ProcessIterator::InitProcessEntry(ProcessEntry* entry) { |
| 32 | SbMemorySet(entry, 0, sizeof(*entry)); |
| 33 | entry->dwSize = sizeof(*entry); |
| 34 | } |
| 35 | |
| 36 | bool NamedProcessIterator::IncludeEntry() { |
| 37 | // Case insensitive. |
| 38 | return _wcsicmp(executable_name_.c_str(), entry().exe_file()) == 0 && |
| 39 | ProcessIterator::IncludeEntry(); |
| 40 | } |
| 41 | |
| 42 | } // namespace base |