Home | History | Annotate | Download | only in process
      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 
      7 namespace base {
      8 
      9 ProcessIterator::ProcessIterator(const ProcessFilter* filter)
     10     : started_iteration_(false),
     11       filter_(filter) {
     12   snapshot_ = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
     13 }
     14 
     15 ProcessIterator::~ProcessIterator() {
     16   CloseHandle(snapshot_);
     17 }
     18 
     19 bool 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 
     30 void ProcessIterator::InitProcessEntry(ProcessEntry* entry) {
     31   memset(entry, 0, sizeof(*entry));
     32   entry->dwSize = sizeof(*entry);
     33 }
     34 
     35 bool NamedProcessIterator::IncludeEntry() {
     36   // Case insensitive.
     37   return _wcsicmp(executable_name_.c_str(), entry().exe_file()) == 0 &&
     38          ProcessIterator::IncludeEntry();
     39 }
     40 
     41 }  // namespace base
     42