Use portable typedef for PIDs (process IDs).

This is a preparation to land http://codereview.chromium.org/54003,
which replaces chrome_process_filter with more portable chrome_process_util.

Review URL: http://codereview.chromium.org/57062

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12948 0039d316-1c4b-4281-b951-d872f2087c98
Esse commit está contido em:
phajdan.jr@chromium.org
2009-04-01 09:19:37 +00:00
commit b1f1f7f26e
8 arquivos alterados com 23 adições e 19 exclusões
+6 -2
Ver Arquivo
@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include <sys/types.h>
#ifdef OS_WIN
#include <windows.h>
#endif
@@ -15,11 +16,14 @@ namespace base {
// ProcessHandle is a platform specific type which represents the underlying OS
// handle to a process.
// ProcessId is a number which identifies the process in the OS.
#if defined(OS_WIN)
typedef HANDLE ProcessHandle;
typedef DWORD ProcessId;
#elif defined(OS_POSIX)
// On POSIX, our ProcessHandle will just be the PID.
typedef int ProcessHandle;
typedef pid_t ProcessHandle;
typedef pid_t ProcessId;
#endif
class Process {
@@ -37,7 +41,7 @@ class Process {
void set_handle(ProcessHandle handle) { process_ = handle; }
// Get the PID for this process.
int32 pid() const;
ProcessId pid() const;
// Is the this process the current process.
bool is_current() const;
+1 -1
Ver Arquivo
@@ -50,7 +50,7 @@ bool Process::EmptyWorkingSet() {
return false;
}
int32 Process::pid() const {
ProcessId Process::pid() const {
if (process_ == 0)
return 0;
+5 -5
Ver Arquivo
@@ -62,14 +62,14 @@ enum {
};
// Returns the id of the current process.
int GetCurrentProcId();
ProcessId GetCurrentProcId();
// Returns the ProcessHandle of the current process.
ProcessHandle GetCurrentProcessHandle();
// Converts a PID to a process handle. This handle must be closed by
// CloseProcessHandle when you are done with it.
ProcessHandle OpenProcessHandle(int pid);
ProcessHandle OpenProcessHandle(ProcessId pid);
// Closes the process handle opened by OpenProcessHandle.
void CloseProcessHandle(ProcessHandle process);
@@ -77,7 +77,7 @@ void CloseProcessHandle(ProcessHandle process);
// Returns the unique ID for the specified process. This is functionally the
// same as Windows' GetProcessId(), but works on versions of Windows before
// Win XP SP1 as well.
int GetProcId(ProcessHandle process);
ProcessId GetProcId(ProcessHandle process);
#if defined(OS_POSIX)
// Sets all file descriptors to close on exec except for stdin, stdout
@@ -129,7 +129,7 @@ class ProcessFilter {
public:
// Returns true to indicate set-inclusion and false otherwise. This method
// should not have side-effects and should be idempotent.
virtual bool Includes(uint32 pid, uint32 parent_pid) const = 0;
virtual bool Includes(ProcessId pid, ProcessId parent_pid) const = 0;
virtual ~ProcessFilter() { }
};
@@ -153,7 +153,7 @@ bool KillProcesses(const std::wstring& executable_name, int exit_code,
// Returns true if this is successful, false otherwise.
bool KillProcess(ProcessHandle process, int exit_code, bool wait);
#if defined(OS_WIN)
bool KillProcessById(DWORD process_id, int exit_code, bool wait);
bool KillProcessById(ProcessId process_id, int exit_code, bool wait);
#endif
// Get the termination status (exit code) of the process and return true if the
+3 -3
Ver Arquivo
@@ -27,7 +27,7 @@ const int kMicrosecondsPerSecond = 1000000;
namespace base {
int GetCurrentProcId() {
ProcessId GetCurrentProcId() {
return getpid();
}
@@ -35,7 +35,7 @@ ProcessHandle GetCurrentProcessHandle() {
return GetCurrentProcId();
}
ProcessHandle OpenProcessHandle(int pid) {
ProcessHandle OpenProcessHandle(ProcessId pid) {
// On Posix platforms, process handles are the same as PIDs, so we
// don't need to do anything.
return pid;
@@ -46,7 +46,7 @@ void CloseProcessHandle(ProcessHandle process) {
return;
}
int GetProcId(ProcessHandle process) {
ProcessId GetProcId(ProcessHandle process) {
return process;
}
+4 -4
Ver Arquivo
@@ -25,7 +25,7 @@ typedef BOOL (WINAPI* HeapSetFn)(HANDLE, HEAP_INFORMATION_CLASS, PVOID, SIZE_T);
namespace base {
int GetCurrentProcId() {
ProcessId GetCurrentProcId() {
return ::GetCurrentProcessId();
}
@@ -33,7 +33,7 @@ ProcessHandle GetCurrentProcessHandle() {
return ::GetCurrentProcess();
}
ProcessHandle OpenProcessHandle(int pid) {
ProcessHandle OpenProcessHandle(ProcessId pid) {
return OpenProcess(PROCESS_DUP_HANDLE | PROCESS_TERMINATE, FALSE, pid);
}
@@ -100,7 +100,7 @@ bool GetProcIdViaNtQueryInformationProcess(ProcessHandle process, DWORD* id) {
return true;
}
int GetProcId(ProcessHandle process) {
ProcessId GetProcId(ProcessHandle process) {
// Get a handle to |process| that has PROCESS_QUERY_INFORMATION rights.
HANDLE current_process = GetCurrentProcess();
HANDLE process_with_query_rights;
@@ -160,7 +160,7 @@ bool LaunchApp(const CommandLine& cl,
// Attempts to kill the process identified by the given process
// entry structure, giving it the specified exit code.
// Returns true if this is successful, false otherwise.
bool KillProcessById(DWORD process_id, int exit_code, bool wait) {
bool KillProcessById(ProcessId process_id, int exit_code, bool wait) {
HANDLE process = OpenProcess(PROCESS_TERMINATE | SYNCHRONIZE,
FALSE, // Don't inherit handle
process_id);
+1 -1
Ver Arquivo
@@ -107,7 +107,7 @@ bool Process::EmptyWorkingSet() {
return rv == TRUE;
}
int32 Process::pid() const {
ProcessId Process::pid() const {
if (process_ == 0)
return 0;
+2 -2
Ver Arquivo
@@ -28,8 +28,8 @@ BrowserProcessFilter::BrowserProcessFilter(const std::wstring user_data_dir)
GetWindowThreadProcessId(message_window, &browser_process_id_);
}
bool BrowserProcessFilter::Includes(uint32 pid,
uint32 parent_pid) const {
bool BrowserProcessFilter::Includes(base::ProcessId pid,
base::ProcessId parent_pid) const {
return browser_process_id_ && (browser_process_id_ == pid ||
browser_process_id_ == parent_pid);
}
+1 -1
Ver Arquivo
@@ -18,7 +18,7 @@ class BrowserProcessFilter : public base::ProcessFilter {
uint32 browser_process_id() const { return browser_process_id_; }
virtual bool Includes(uint32 pid, uint32 parent_pid) const;
virtual bool Includes(base::ProcessId pid, base::ProcessId parent_pid) const;
private:
std::wstring user_data_dir_;