Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: installer/src/installer-lib/process.h

Issue 6003395731128320: Only take into account processes that have our plugin loaded (Closed)
Patch Set: Addressing comments Created March 28, 2014, 12:45 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « installer/src/custom-action/close_application.cpp ('k') | installer/src/installer-lib/process.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: installer/src/installer-lib/process.h
===================================================================
--- a/installer/src/installer-lib/process.h
+++ b/installer/src/installer-lib/process.h
@@ -2,8 +2,8 @@
* \file process.h
*/
-#ifndef PROCESS_H
-#define PROCESS_H
+#ifndef PROCESS_H
+#define PROCESS_H
#include <vector>
#include <set>
@@ -80,38 +80,38 @@
};
//-------------------------------------------------------
-// exe_name_set: case-insensitive wide-string set
+// file_name_set: case-insensitive wide-string set
//-------------------------------------------------------
int wcscmpi( const wchar_t * s1, const wchar_t * s2 ) ;
-struct exe_name
+struct file_name
{
/**
* Pointer to wide-character string, which is supposed to be null-terminated.
*/
const wchar_t * name ;
- exe_name( const wchar_t * name ) : name( name ) {} ;
+ file_name( const wchar_t * name ) : name( name ) {} ;
} ;
template <>
-struct std::less< exe_name >
- : std::binary_function< exe_name, exe_name, bool >
+struct std::less< file_name >
+ : std::binary_function< file_name, file_name, bool >
{
- bool operator()( const exe_name & a, const exe_name & b ) const
+ bool operator()( const file_name & a, const file_name & b ) const
{
return wcscmpi( a.name, b.name ) < 0 ;
}
} ;
-struct exe_name_set
- : public std::set< exe_name >
+struct file_name_set
+ : public std::set< file_name >
{
- exe_name_set( const wchar_t * exe_name_list[], size_t n_exe_names )
+ file_name_set( const wchar_t * file_name_list[], size_t n_file_names )
{
- for ( unsigned int j = 0 ; j < n_exe_names ; ++ j )
+ for ( unsigned int j = 0 ; j < n_file_names ; ++ j )
{
- insert( exe_name( exe_name_list[ j ] ) ) ;
+ insert( file_name( file_name_list[ j ] ) ) ;
}
}
} ;
@@ -119,19 +119,21 @@
//-------------------------------------------------------
//-------------------------------------------------------
/**
- * Filter by process name. Comparison is case-insensitive.
+ * Filter by process name. Comparison is case-insensitive. With ABP module loaded
*/
-class process_by_any_exe_name_CI
- : public std::unary_function< PROCESSENTRY32W, bool >
+class process_by_any_exe_with_any_module
+ : public std::binary_function< PROCESSENTRY32W, file_name_set, bool >
{
- const exe_name_set & names ;
+ const file_name_set & processNames ;
+ const file_name_set & moduleNames;
public:
bool operator()( const PROCESSENTRY32W & ) ;
- process_by_any_exe_name_CI( const exe_name_set & names )
- : names( names )
+ process_by_any_exe_with_any_module( const file_name_set & names, const file_name_set & moduleNames )
+ : processNames( names ), moduleNames( moduleNames )
{}
} ;
+
//-------------------------------------------------------
// Process utility functions.
//-------------------------------------------------------
@@ -283,6 +285,64 @@
typedef PROCESSENTRY32W * Pointer ;
} ;
+class ModulesSnapshot
+{
+ /**
+ * Handle to the process snapshot.
+ */
+ Windows_Handle handle;
+
+ /**
+ * Buffer for reading a single module entry out of the snapshot.
+ */
+ MODULEENTRY32W module;
+
+ /**
+ * Copy constructor declared private and not defined.
+ *
+ * \par Implementation
+ * Add "= delete" for C++11.
+ */
+ ModulesSnapshot(const ModulesSnapshot&);
+
+ /**
+ * Copy assignment declared private and not defined.
+ *
+ * \par Implementation
+ * Add "= delete" for C++11.
+ */
+ ModulesSnapshot operator=(const ModulesSnapshot&);
+
+
+public:
+ /**
+ * Default constructor takes the snapshot.
+ */
+ ModulesSnapshot(DWORD processId);
+
+ /**
+ * Return a pointer to the first process in the snapshot.
+ */
+ MODULEENTRY32W* begin();
+
+ /**
+ * The end pointer is an alias for the null pointer.
+ */
+ inline MODULEENTRY32W* end() const { return 0; }
+
+ /**
+ * Return a pointer to the next process in the snapshot.
+ * begin() must have been called first.
+ */
+ MODULEENTRY32W* next();
+
+ /**
+ * Type definition for pointer to underlying structure.
+ */
+ typedef MODULEENTRY32W* Pointer;
+};
+
+
//-------------------------------------------------------
// initialize_process_list
//-------------------------------------------------------
@@ -465,12 +525,13 @@
* The argument of the filter constructor is a set by reference.
* Since it does not make a copy for itself, we define it as a class member to provide its allocation.
*/
- exe_name_set exe_names ;
+ file_name_set file_names ;
+ /**
+ * Set of module (DLL) names by which to filter.
+ */
+ file_name_set module_names ;
- /**
- * Filter function object matches on any of the exe names specified in the constructor.
- */
- process_by_any_exe_name_CI filter ;
+ process_by_any_exe_with_any_module filter ;
/**
* Copy function object copies just the process ID.
@@ -521,8 +582,8 @@
} ;
public:
- Process_Closer( Snapshot & snapshot, const wchar_t * exe_name_list[], size_t n_exe_names )
- : snapshot( snapshot ), exe_names( exe_name_list, n_exe_names ), filter( exe_names )
+ Process_Closer( Snapshot & snapshot, const wchar_t * file_name_list[], size_t n_file_names, const wchar_t * module_name_list[], size_t n_module_names )
+ : snapshot( snapshot ), file_names( file_name_list, n_file_names ), module_names(module_name_list, n_module_names), filter( file_names, module_names )
{
update() ;
}
« no previous file with comments | « installer/src/custom-action/close_application.cpp ('k') | installer/src/installer-lib/process.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld