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
CrOS-Libchrome-Original-Commit: 43cf325be09379594dd96e0b35146585cdfd6a34
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 @@
// 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 @@
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 @@
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 @@
};
// 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 @@
// 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 @@
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 @@
// 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 @@
namespace base {
-int GetCurrentProcId() {
+ProcessId GetCurrentProcId() {
return getpid();
}
@@ -35,7 +35,7 @@
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 @@
return;
}
-int GetProcId(ProcessHandle process) {
+ProcessId GetProcId(ProcessHandle process) {
return process;
}