diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-01 09:19:37 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-01 09:19:37 +0000 |
commit | 43cf325be09379594dd96e0b35146585cdfd6a34 (patch) | |
tree | 46401fd401988a049d3b12bea27132b7889b1986 /base | |
parent | 744121a2bf4ccf78a95cd816e696c0fc7f2551a5 (diff) | |
download | chromium_src-43cf325be09379594dd96e0b35146585cdfd6a34.zip chromium_src-43cf325be09379594dd96e0b35146585cdfd6a34.tar.gz chromium_src-43cf325be09379594dd96e0b35146585cdfd6a34.tar.bz2 |
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
Diffstat (limited to 'base')
-rw-r--r-- | base/process.h | 8 | ||||
-rw-r--r-- | base/process_posix.cc | 2 | ||||
-rw-r--r-- | base/process_util.h | 10 | ||||
-rw-r--r-- | base/process_util_posix.cc | 6 | ||||
-rw-r--r-- | base/process_util_win.cc | 8 | ||||
-rw-r--r-- | base/process_win.cc | 2 |
6 files changed, 20 insertions, 16 deletions
diff --git a/base/process.h b/base/process.h index de26939..312f84c 100644 --- a/base/process.h +++ b/base/process.h @@ -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; diff --git a/base/process_posix.cc b/base/process_posix.cc index f5a7821..ff8cf92 100644 --- a/base/process_posix.cc +++ b/base/process_posix.cc @@ -50,7 +50,7 @@ bool Process::EmptyWorkingSet() { return false; } -int32 Process::pid() const { +ProcessId Process::pid() const { if (process_ == 0) return 0; diff --git a/base/process_util.h b/base/process_util.h index 35a051a..286330b 100644 --- a/base/process_util.h +++ b/base/process_util.h @@ -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 diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc index 37888d5..439b806 100644 --- a/base/process_util_posix.cc +++ b/base/process_util_posix.cc @@ -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; } diff --git a/base/process_util_win.cc b/base/process_util_win.cc index beb4ea3..df3d7f20 100644 --- a/base/process_util_win.cc +++ b/base/process_util_win.cc @@ -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); diff --git a/base/process_win.cc b/base/process_win.cc index 697a020..98a7f46 100644 --- a/base/process_win.cc +++ b/base/process_win.cc @@ -107,7 +107,7 @@ bool Process::EmptyWorkingSet() { return rv == TRUE; } -int32 Process::pid() const { +ProcessId Process::pid() const { if (process_ == 0) return 0; |