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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /** 1 /**
2 * \file process.h 2 * \file process.h
3 */ 3 */
4 4
5 #ifndef PROCESS_H 5 #ifndef PROCESS_H
6 #define PROCESS_H 6 #define PROCESS_H
7 7
8 #include <vector> 8 #include <vector>
9 #include <set> 9 #include <set>
10 #include <algorithm> 10 #include <algorithm>
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 * Copy assignment declared private and not defined. 73 * Copy assignment declared private and not defined.
74 * 74 *
75 * \par Implementation 75 * \par Implementation
76 * Add "= delete" for C++11. 76 * Add "= delete" for C++11.
77 */ 77 */
78 Windows_Handle operator=( const Windows_Handle & ) ; 78 Windows_Handle operator=( const Windows_Handle & ) ;
79 79
80 }; 80 };
81 81
82 //------------------------------------------------------- 82 //-------------------------------------------------------
83 // exe_name_set: case-insensitive wide-string set 83 // file_name_set: case-insensitive wide-string set
84 //------------------------------------------------------- 84 //-------------------------------------------------------
85 int wcscmpi( const wchar_t * s1, const wchar_t * s2 ) ; 85 int wcscmpi( const wchar_t * s1, const wchar_t * s2 ) ;
86 86
87 struct exe_name 87 struct file_name
88 { 88 {
89 /** 89 /**
90 * Pointer to wide-character string, which is supposed to be null-terminated. 90 * Pointer to wide-character string, which is supposed to be null-terminated.
91 */ 91 */
92 const wchar_t * name ; 92 const wchar_t * name ;
93 93
94 exe_name( const wchar_t * name ) : name( name ) {} ; 94 file_name( const wchar_t * name ) : name( name ) {} ;
95 } ; 95 } ;
96 96
97 template <> 97 template <>
98 struct std::less< exe_name > 98 struct std::less< file_name >
99 : std::binary_function< exe_name, exe_name, bool > 99 : std::binary_function< file_name, file_name, bool >
100 { 100 {
101 bool operator()( const exe_name & a, const exe_name & b ) const 101 bool operator()( const file_name & a, const file_name & b ) const
102 { 102 {
103 return wcscmpi( a.name, b.name ) < 0 ; 103 return wcscmpi( a.name, b.name ) < 0 ;
104 } 104 }
105 } ; 105 } ;
106 106
107 struct exe_name_set 107 struct file_name_set
108 : public std::set< exe_name > 108 : public std::set< file_name >
109 { 109 {
110 exe_name_set( const wchar_t * exe_name_list[], size_t n_exe_names ) 110 file_name_set( const wchar_t * file_name_list[], size_t n_file_names )
111 { 111 {
112 for ( unsigned int j = 0 ; j < n_exe_names ; ++ j ) 112 for ( unsigned int j = 0 ; j < n_file_names ; ++ j )
113 { 113 {
114 insert( exe_name( exe_name_list[ j ] ) ) ; 114 insert( file_name( file_name_list[ j ] ) ) ;
115 } 115 }
116 } 116 }
117 } ; 117 } ;
118 118
119 //------------------------------------------------------- 119 //-------------------------------------------------------
120 //------------------------------------------------------- 120 //-------------------------------------------------------
121 /** 121 /**
122 * Filter by process name. Comparison is case-insensitive. 122 * Filter by process name. Comparison is case-insensitive. With ABP module loade d
123 */ 123 */
124 class process_by_any_exe_name_CI 124 class process_by_any_exe_with_any_module
125 : public std::unary_function< PROCESSENTRY32W, bool > 125 : public std::binary_function< PROCESSENTRY32W, file_name_set, bool >
126 { 126 {
127 const exe_name_set & names ; 127 const file_name_set & processNames ;
128 const file_name_set & moduleNames;
128 public: 129 public:
129 bool operator()( const PROCESSENTRY32W & ) ; 130 bool operator()( const PROCESSENTRY32W & ) ;
130 process_by_any_exe_name_CI( const exe_name_set & names ) 131 process_by_any_exe_with_any_module( const file_name_set & names, const file_na me_set & moduleNames )
131 : names( names ) 132 : processNames( names ), moduleNames( moduleNames )
132 {} 133 {}
133 } ; 134 } ;
134 135
136
135 //------------------------------------------------------- 137 //-------------------------------------------------------
136 // Process utility functions. 138 // Process utility functions.
137 //------------------------------------------------------- 139 //-------------------------------------------------------
138 /** 140 /**
139 * A promiscuous filter admits everything. 141 * A promiscuous filter admits everything.
140 */ 142 */
141 struct every_process 143 struct every_process
142 : public std::unary_function< PROCESSENTRY32W, bool > 144 : public std::unary_function< PROCESSENTRY32W, bool >
143 { 145 {
144 bool operator()( const PROCESSENTRY32W & ) { return true ; } ; 146 bool operator()( const PROCESSENTRY32W & ) { return true ; } ;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 * begin() must have been called first. 278 * begin() must have been called first.
277 */ 279 */
278 PROCESSENTRY32W * next() ; 280 PROCESSENTRY32W * next() ;
279 281
280 /** 282 /**
281 * Type definition for pointer to underlying structure. 283 * Type definition for pointer to underlying structure.
282 */ 284 */
283 typedef PROCESSENTRY32W * Pointer ; 285 typedef PROCESSENTRY32W * Pointer ;
284 } ; 286 } ;
285 287
288 class ModulesSnapshot
289 {
290 /**
291 * Handle to the process snapshot.
292 */
293 Windows_Handle handle;
294
295 /**
296 * Buffer for reading a single module entry out of the snapshot.
297 */
298 MODULEENTRY32W module;
299
300 /**
301 * Copy constructor declared private and not defined.
302 *
303 * \par Implementation
304 * Add "= delete" for C++11.
305 */
306 ModulesSnapshot(const ModulesSnapshot&);
307
308 /**
309 * Copy assignment declared private and not defined.
310 *
311 * \par Implementation
312 * Add "= delete" for C++11.
313 */
314 ModulesSnapshot operator=(const ModulesSnapshot&);
315
316
317 public:
318 /**
319 * Default constructor takes the snapshot.
320 */
321 ModulesSnapshot(DWORD processId);
322
323 /**
324 * Return a pointer to the first process in the snapshot.
325 */
326 MODULEENTRY32W* begin();
327
328 /**
329 * The end pointer is an alias for the null pointer.
330 */
331 inline MODULEENTRY32W* end() const { return 0; }
332
333 /**
334 * Return a pointer to the next process in the snapshot.
335 * begin() must have been called first.
336 */
337 MODULEENTRY32W* next();
338
339 /**
340 * Type definition for pointer to underlying structure.
341 */
342 typedef MODULEENTRY32W* Pointer;
343 };
344
345
286 //------------------------------------------------------- 346 //-------------------------------------------------------
287 // initialize_process_list 347 // initialize_process_list
288 //------------------------------------------------------- 348 //-------------------------------------------------------
289 /** 349 /**
290 * \tparam T The type into which a PROCESSENTRY32W struture is extracted. 350 * \tparam T The type into which a PROCESSENTRY32W struture is extracted.
291 * \tparam Admittance Function type for argument 'admit' 351 * \tparam Admittance Function type for argument 'admit'
292 * \tparam Extractor Function type for argument 'extract' 352 * \tparam Extractor Function type for argument 'extract'
293 * \param admit A unary predicate function class that determines what's included 353 * \param admit A unary predicate function class that determines what's included
294 * A process appears in the list only if the predicate returns true. 354 * A process appears in the list only if the predicate returns true.
295 * The use of this predicate is analogous to that in std::copy_if. 355 * The use of this predicate is analogous to that in std::copy_if.
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 * Set of process identifiers matching one of the executable names. 518 * Set of process identifiers matching one of the executable names.
459 */ 519 */
460 std::set< DWORD > pid_set ; 520 std::set< DWORD > pid_set ;
461 521
462 /** 522 /**
463 * Set of executable names by which to filter. 523 * Set of executable names by which to filter.
464 * 524 *
465 * The argument of the filter constructor is a set by reference. 525 * The argument of the filter constructor is a set by reference.
466 * Since it does not make a copy for itself, we define it as a class member to provide its allocation. 526 * Since it does not make a copy for itself, we define it as a class member to provide its allocation.
467 */ 527 */
468 exe_name_set exe_names ; 528 file_name_set file_names ;
529 /**
530 * Set of module (DLL) names by which to filter.
531 */
532 file_name_set module_names ;
469 533
470 /** 534 process_by_any_exe_with_any_module filter ;
471 * Filter function object matches on any of the exe names specified in the con structor.
472 */
473 process_by_any_exe_name_CI filter ;
474 535
475 /** 536 /**
476 * Copy function object copies just the process ID. 537 * Copy function object copies just the process ID.
477 */ 538 */
478 copy_PID copy ; 539 copy_PID copy ;
479 540
480 /** 541 /**
481 * Snapshot of running processes. 542 * Snapshot of running processes.
482 */ 543 */
483 Snapshot & snapshot ; 544 Snapshot & snapshot ;
(...skipping 30 matching lines...) Expand all
514 if ( ! b ) 575 if ( ! b )
515 { 576 {
516 // Assert the process that created the window is not in our pid_set 577 // Assert the process that created the window is not in our pid_set
517 return true ; 578 return true ;
518 } 579 }
519 return f( window ) ; 580 return f( window ) ;
520 } 581 }
521 } ; 582 } ;
522 583
523 public: 584 public:
524 Process_Closer( Snapshot & snapshot, const wchar_t * exe_name_list[], size_t n _exe_names ) 585 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 )
525 : snapshot( snapshot ), exe_names( exe_name_list, n_exe_names ), filter( exe _names ) 586 : snapshot( snapshot ), file_names( file_name_list, n_file_names ), module_n ames(module_name_list, n_module_names), filter( file_names, module_names )
526 { 587 {
527 update() ; 588 update() ;
528 } 589 }
529 590
530 /** 591 /**
531 * Refresh our state to match the snapshot state. 592 * Refresh our state to match the snapshot state.
532 */ 593 */
533 void refresh() 594 void refresh()
534 { 595 {
535 pid_set.clear() ; 596 pid_set.clear() ;
(...skipping 12 matching lines...) Expand all
548 } 609 }
549 610
550 /* 611 /*
551 * Shut down every process in the pid_set. 612 * Shut down every process in the pid_set.
552 */ 613 */
553 bool shut_down() ; 614 bool shut_down() ;
554 615
555 } ; 616 } ;
556 617
557 #endif 618 #endif
OLDNEW
« 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