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: Created March 27, 2014, 3:29 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 insert( exe_name( exe_name_list[ j ] ) ) ; 114 insert( exe_name( exe_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.
123 */ 123 */
124 class process_by_any_exe_name_CI 124 class process_by_any_exe_name_CI
Eric 2014/03/27 16:56:51 Since this filter isn't being used any more, it ca
Wladimir Palant 2014/03/28 07:34:55 I strongly prefer to remove any unused code that's
125 : public std::unary_function< PROCESSENTRY32W, bool > 125 : public std::unary_function< PROCESSENTRY32W, bool >
126 { 126 {
127 const exe_name_set & names ; 127 const exe_name_set & names ;
128 public: 128 public:
129 bool operator()( const PROCESSENTRY32W & ) ; 129 bool operator()( const PROCESSENTRY32W & ) ;
130 process_by_any_exe_name_CI( const exe_name_set & names ) 130 process_by_any_exe_name_CI( const exe_name_set & names )
131 : names( names ) 131 : names( names )
132 {} 132 {}
133 } ; 133 } ;
134 134
135 //------------------------------------------------------- 135 //-------------------------------------------------------
136 //-------------------------------------------------------
137 /**
138 * Filter by process name. Comparison is case-insensitive. With ABP module loade d
139 */
140 class process_by_any_exe_name_CI_w_ABP
Eric 2014/03/27 16:52:44 This is not ABP-specific until after we pass it AB
141 : public std::binary_function< PROCESSENTRY32W, exe_name_set, bool >
142 {
143 const exe_name_set & names ;
Eric 2014/03/27 16:52:44 This should be renamed to process_names (or the li
144 const exe_name_set & moduleNames;
145 public:
146 bool operator()( const PROCESSENTRY32W & ) ;
147 process_by_any_exe_name_CI_w_ABP( const exe_name_set & names, const exe_name_s et & moduleNames )
148 : names( names ), moduleNames( moduleNames )
149 {}
150 } ;
151
152
153 //-------------------------------------------------------
136 // Process utility functions. 154 // Process utility functions.
137 //------------------------------------------------------- 155 //-------------------------------------------------------
138 /** 156 /**
139 * A promiscuous filter admits everything. 157 * A promiscuous filter admits everything.
140 */ 158 */
141 struct every_process 159 struct every_process
142 : public std::unary_function< PROCESSENTRY32W, bool > 160 : public std::unary_function< PROCESSENTRY32W, bool >
143 { 161 {
144 bool operator()( const PROCESSENTRY32W & ) { return true ; } ; 162 bool operator()( const PROCESSENTRY32W & ) { return true ; } ;
145 } ; 163 } ;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 * Return a pointer to the next process in the snapshot. 293 * Return a pointer to the next process in the snapshot.
276 * begin() must have been called first. 294 * begin() must have been called first.
277 */ 295 */
278 PROCESSENTRY32W * next() ; 296 PROCESSENTRY32W * next() ;
279 297
280 /** 298 /**
281 * Type definition for pointer to underlying structure. 299 * Type definition for pointer to underlying structure.
282 */ 300 */
283 typedef PROCESSENTRY32W * Pointer ; 301 typedef PROCESSENTRY32W * Pointer ;
284 } ; 302 } ;
285 303
Eric 2014/03/27 16:52:44 We need some documentation here about CreateToolhe
304 class ModulesSnapshot
305 {
306 /**
307 * Handle to the process snapshot.
308 */
309 Windows_Handle handle ;
310
311 /**
312 * Buffer for reading a single module entry out of the snapshot.
313 */
314 MODULEENTRY32W module;
315
316 /**
317 * process ID of the process to retrieve modules for.
318 */
319 DWORD processId;
Eric 2014/03/27 16:52:44 Only needed for refresh(), which we don't need.
320
321 /**
322 * Copy constructor declared private and not defined.
323 *
324 * \par Implementation
325 * Add "= delete" for C++11.
326 */
327 ModulesSnapshot( const ModulesSnapshot & ) ;
328
329 /**
330 * Copy assignment declared private and not defined.
331 *
332 * \par Implementation
333 * Add "= delete" for C++11.
334 */
335 ModulesSnapshot operator=( const ModulesSnapshot & ) ;
336
337
338 public:
339 /**
340 * Default constructor takes the snapshot.
341 */
342 ModulesSnapshot(DWORD processId) ;
343
344 /**
345 * Reconstruct the current instance with a new system snapshot.
346 */
347 void refresh(DWORD processId) ;
Eric 2014/03/27 16:52:44 The way this is being used, I don't believe we nee
348
349 /**
350 * Return a pointer to the first process in the snapshot.
351 */
352 MODULEENTRY32W * begin() ;
353
354 /**
355 * The end pointer is an alias for the null pointer.
356 */
357 inline MODULEENTRY32W * end() const { return 0 ; }
358
359 /**
360 * Return a pointer to the next process in the snapshot.
361 * begin() must have been called first.
362 */
363 MODULEENTRY32W * next() ;
364
365 /**
366 * Type definition for pointer to underlying structure.
367 */
368 typedef MODULEENTRY32W * Pointer ;
369 } ;
370
371
286 //------------------------------------------------------- 372 //-------------------------------------------------------
287 // initialize_process_list 373 // initialize_process_list
288 //------------------------------------------------------- 374 //-------------------------------------------------------
289 /** 375 /**
290 * \tparam T The type into which a PROCESSENTRY32W struture is extracted. 376 * \tparam T The type into which a PROCESSENTRY32W struture is extracted.
291 * \tparam Admittance Function type for argument 'admit' 377 * \tparam Admittance Function type for argument 'admit'
292 * \tparam Extractor Function type for argument 'extract' 378 * \tparam Extractor Function type for argument 'extract'
293 * \param admit A unary predicate function class that determines what's included 379 * \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. 380 * 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. 381 * The use of this predicate is analogous to that in std::copy_if.
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 */ 545 */
460 std::set< DWORD > pid_set ; 546 std::set< DWORD > pid_set ;
461 547
462 /** 548 /**
463 * Set of executable names by which to filter. 549 * Set of executable names by which to filter.
464 * 550 *
465 * The argument of the filter constructor is a set by reference. 551 * 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. 552 * Since it does not make a copy for itself, we define it as a class member to provide its allocation.
467 */ 553 */
468 exe_name_set exe_names ; 554 exe_name_set exe_names ;
555 exe_name_set module_names ;
Eric 2014/03/27 16:52:44 I'd use dll_names. We configure these with .EXE an
Oleksandr 2014/03/27 23:28:46 I actually think module_names is more consistent,
469 556
470 /** 557 /**
471 * Filter function object matches on any of the exe names specified in the con structor. 558 * Filter function object matches on any of the exe names specified in the con structor.
472 */ 559 */
473 process_by_any_exe_name_CI filter ; 560 // process_by_any_exe_name_CI filter ;
561
562 process_by_any_exe_name_CI_w_ABP filter ;
474 563
475 /** 564 /**
476 * Copy function object copies just the process ID. 565 * Copy function object copies just the process ID.
477 */ 566 */
478 copy_PID copy ; 567 copy_PID copy ;
479 568
480 /** 569 /**
481 * Snapshot of running processes. 570 * Snapshot of running processes.
482 */ 571 */
483 Snapshot & snapshot ; 572 Snapshot & snapshot ;
(...skipping 30 matching lines...) Expand all
514 if ( ! b ) 603 if ( ! b )
515 { 604 {
516 // Assert the process that created the window is not in our pid_set 605 // Assert the process that created the window is not in our pid_set
517 return true ; 606 return true ;
518 } 607 }
519 return f( window ) ; 608 return f( window ) ;
520 } 609 }
521 } ; 610 } ;
522 611
523 public: 612 public:
524 Process_Closer( Snapshot & snapshot, const wchar_t * exe_name_list[], size_t n _exe_names ) 613 Process_Closer( Snapshot & snapshot, const wchar_t * exe_name_list[], size_t n _exe_names, const wchar_t * module_name_list[], size_t n_module_names )
Eric 2014/03/27 16:52:44 Likewise dll_name_list etc. here.
525 : snapshot( snapshot ), exe_names( exe_name_list, n_exe_names ), filter( exe _names ) 614 : snapshot( snapshot ), exe_names( exe_name_list, n_exe_names ), module_name s(module_name_list, n_module_names), filter( exe_names, module_names )
526 { 615 {
527 update() ; 616 update() ;
528 } 617 }
529 618
530 /** 619 /**
531 * Refresh our state to match the snapshot state. 620 * Refresh our state to match the snapshot state.
532 */ 621 */
533 void refresh() 622 void refresh()
534 { 623 {
535 pid_set.clear() ; 624 pid_set.clear() ;
(...skipping 12 matching lines...) Expand all
548 } 637 }
549 638
550 /* 639 /*
551 * Shut down every process in the pid_set. 640 * Shut down every process in the pid_set.
552 */ 641 */
553 bool shut_down() ; 642 bool shut_down() ;
554 643
555 } ; 644 } ;
556 645
557 #endif 646 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld