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

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

Issue 5665210325008384: Combine snapshot classes into a template class (Closed)
Patch Set: Created April 3, 2014, 4:51 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/installer-lib/process.h ('k') | installer/src/installer-lib/run-tests.cmd » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: installer/src/installer-lib/process.cpp
===================================================================
--- a/installer/src/installer-lib/process.cpp
+++ b/installer/src/installer-lib/process.cpp
@@ -16,9 +16,9 @@
if (moduleNames.empty())
return true;
- ModulesSnapshot ms(process.th32ProcessID);
- MODULEENTRY32W* me = ms.first();
- while (me != NULL)
+ Module_Snapshot ms(process.th32ProcessID);
+ const MODULEENTRY32W* me = ms.first();
+ while (me != 0)
{
if (moduleNames.find(me->szModule) != moduleNames.end())
{
@@ -47,49 +47,6 @@
}
//-------------------------------------------------------
-// Snapshot
-//-------------------------------------------------------
-Snapshot::Snapshot()
- : handle( ::CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ) )
-{
- process.dwSize = sizeof( PROCESSENTRY32W ) ;
-}
-
-PROCESSENTRY32W * Snapshot::first()
-{
- return ::Process32FirstW(handle, &process) ? (&process) : 0;
-}
-
-PROCESSENTRY32W * Snapshot::next()
-{
- return ::Process32NextW(handle, &process) ? (&process) : 0;
-}
-
-void Snapshot::refresh()
-{
- handle = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
-}
-
-//-------------------------------------------------------
-// ModulesSnapshot
-//-------------------------------------------------------
-ModulesSnapshot::ModulesSnapshot(DWORD processId)
- : handle(::CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, processId))
-{
- module.dwSize = sizeof(MODULEENTRY32);
-}
-
-MODULEENTRY32W * ModulesSnapshot::first()
-{
- return ::Module32FirstW(handle, &module) ? (&module) : 0;
-}
-
-MODULEENTRY32W * ModulesSnapshot::next()
-{
- return ::Module32NextW(handle, &module) ? (&module) : 0;
-}
-
-//-------------------------------------------------------
// send_message, send_endsession_messages
//-------------------------------------------------------
/**
@@ -108,7 +65,7 @@
* This class provides the base for any variation from the default behavior.
*/
struct message_accumulator
- : public std::binary_function< DWORD_PTR, BOOL, bool >
+ : public std::binary_function< DWORD_PTR, bool, bool >
{
virtual result_type operator()( first_argument_type result, second_argument_type return_value ) = 0 ;
virtual ~message_accumulator() {} ;
@@ -150,7 +107,7 @@
bool operator()( HWND window )
{
DWORD_PTR result ;
- BOOL rv = SendMessageTimeoutW( window, message, p1, p2, SMTO_BLOCK, timeout, & result ) ;
+ LRESULT rv = SendMessageTimeoutW( window, message, p1, p2, SMTO_BLOCK, timeout, & result ) ;
/*
* If we have no message accumulator, the default behavior is to iterate everything.
* If we do have one, we delegate to it the decision whether to break or to continue.
@@ -159,7 +116,7 @@
{
return true ;
}
- return ( * f )( result, rv ) ;
+ return ( * f )( result, (rv != 0) ) ;
}
} ;
@@ -214,7 +171,7 @@
/**
* Enumeration function applied to each window.
*/
- bool operator()( DWORD_PTR result, BOOL return_value )
+ bool operator()( DWORD_PTR result, bool return_value )
{
if ( ( ! return_value ) || result )
{
« no previous file with comments | « installer/src/installer-lib/process.h ('k') | installer/src/installer-lib/run-tests.cmd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld