Refactor GetUniqueIdForProcess to be used in logs

Logs in renderer process currently return 1 on linux due to the PID
namespaces. Instead we should get the pid outside of the sandboxed
namespace.

There is a API to support getting this pid, but it's not used in
base/logging, partially because the pid was mangled to protect it from
being misused and sent to POSIX apis. Thus, this CL refactors the
GetUniqueIdForProcess to return a more typesafe value while still
allowing the real pid to be logged via the << operator.

BUG=501069

Change-Id: I9726780047e039af582dfabeb3067f9f7e75e085
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1730256
Reviewed-by: Daniel Cheng <[email protected]>
Reviewed-by: Ricky Zhou <[email protected]>
Reviewed-by: Sean Topping <[email protected]>
Reviewed-by: Wez <[email protected]>
Commit-Queue: Chris Findeisen <[email protected]>
Cr-Commit-Position: refs/heads/master@{#687385}
diff --git a/base/logging.cc b/base/logging.cc
index 17969f40..2f5c897 100644
--- a/base/logging.cc
+++ b/base/logging.cc
@@ -75,7 +75,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
-#include <unistd.h>
+#include "base/process/process_handle.h"
 #define MAX_PATH PATH_MAX
 typedef FILE* FileHandle;
 typedef pthread_mutex_t* MutexHandle;
@@ -175,21 +175,6 @@
 // A log message handler that gets notified of every log message we process.
 LogMessageHandlerFunction log_message_handler = nullptr;
 
-// Helper functions to wrap platform differences.
-
-int32_t CurrentProcessId() {
-#if defined(OS_WIN)
-  return GetCurrentProcessId();
-#elif defined(OS_FUCHSIA)
-  zx_info_handle_basic_t basic = {};
-  zx_object_get_info(zx_process_self(), ZX_INFO_HANDLE_BASIC, &basic,
-                     sizeof(basic), nullptr, nullptr);
-  return basic.koid;
-#elif defined(OS_POSIX)
-  return getpid();
-#endif
-}
-
 uint64_t TickCount() {
 #if defined(OS_WIN)
   return GetTickCount();
@@ -965,7 +950,7 @@
   if (g_log_prefix)
     stream_ << g_log_prefix << ':';
   if (g_log_process_id)
-    stream_ << CurrentProcessId() << ':';
+    stream_ << base::GetUniqueIdForProcess() << ':';
   if (g_log_thread_id)
     stream_ << base::PlatformThread::CurrentId() << ':';
   if (g_log_timestamp) {