Fuchsia: Prepare for OS_POSIX removal in base/

This cleans up multi-platform code paths selection and prepares for
the removal of OS_POSIX for the Fuchsia build.

Bug: 836416
Change-Id: I3a8e6393d0a9981aa890fb6d8c302ed8d2bdd69d
Reviewed-on: https://chromium-review.googlesource.com/1031099
Commit-Queue: Fabrice de Gans-Riberi <[email protected]>
Reviewed-by: Kinuko Yasuda <[email protected]>
Reviewed-by: Nico Weber <[email protected]>
Cr-Commit-Position: refs/heads/master@{#559230}
diff --git a/base/process/launch.h b/base/process/launch.h
index 2afba23..0251f07 100644
--- a/base/process/launch.h
+++ b/base/process/launch.h
@@ -21,41 +21,38 @@
 #include "base/strings/string_piece.h"
 #include "build/build_config.h"
 
-#if defined(OS_POSIX)
-#include "base/posix/file_descriptor_shuffle.h"
-#elif defined(OS_WIN)
+#if defined(OS_WIN)
 #include <windows.h>
-#endif
-
-#if defined(OS_FUCHSIA)
+#elif defined(OS_FUCHSIA)
 #include <launchpad/launchpad.h>
 #include <zircon/types.h>
 #endif
 
+#if defined(OS_POSIX) || defined(OS_FUCHSIA)
+#include "base/posix/file_descriptor_shuffle.h"
+#endif
+
 namespace base {
 
 class CommandLine;
 
 #if defined(OS_WIN)
 typedef std::vector<HANDLE> HandlesToInheritVector;
-#endif
-
-#if defined(OS_FUCHSIA)
+#elif defined(OS_FUCHSIA)
 struct HandleToTransfer {
   uint32_t id;
   zx_handle_t handle;
 };
 typedef std::vector<HandleToTransfer> HandlesToTransferVector;
-#endif
-
-#if defined(OS_POSIX)
 typedef std::vector<std::pair<int, int>> FileHandleMappingVector;
-#endif
+#elif defined(OS_POSIX)
+typedef std::vector<std::pair<int, int>> FileHandleMappingVector;
+#endif  // defined(OS_WIN)
 
 // Options for launching a subprocess that are passed to LaunchProcess().
 // The default constructor constructs the object with default options.
 struct BASE_EXPORT LaunchOptions {
-#if defined(OS_POSIX)
+#if defined(OS_POSIX) || defined(OS_FUCHSIA)
   // Delegate to be run in between fork and exec in the subprocess (see
   // pre_exec_delegate below)
   class BASE_EXPORT PreExecDelegate {
@@ -151,7 +148,7 @@
   // CREATE_BREAKAWAY_FROM_JOB flag which allows it to breakout of the parent
   // job if any.
   bool force_breakaway_from_job_ = false;
-#else  // !defined(OS_WIN)
+#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
   // Set/unset environment variables. These are applied on top of the parent
   // process environment.  Empty (the default) means to inherit the same
   // environment. See AlterEnvironment().
@@ -164,6 +161,7 @@
   // Remap file descriptors according to the mapping of src_fd->dest_fd to
   // propagate FDs into the child process.
   FileHandleMappingVector fds_to_remap;
+#endif  // defined(OS_WIN)
 
 #if defined(OS_LINUX)
   // If non-zero, start the process using clone(), using flags as provided.
@@ -210,6 +208,7 @@
   std::vector<FilePath> paths_to_map;
 #endif  // defined(OS_FUCHSIA)
 
+// TODO(crbug/836416): Remove OS_FUCHSIA here.
 #if defined(OS_POSIX) && !defined(OS_FUCHSIA)
   // If not empty, launch the specified executable instead of
   // cmdline.GetProgram(). This is useful when it is necessary to pass a custom
@@ -240,7 +239,6 @@
   // process' controlling terminal.
   int ctrl_terminal_fd = -1;
 #endif  // defined(OS_CHROMEOS)
-#endif  // !defined(OS_WIN)
 };
 
 // Launch a process via the command line |cmdline|.
@@ -281,7 +279,7 @@
 BASE_EXPORT Process LaunchElevatedProcess(const CommandLine& cmdline,
                                           const LaunchOptions& options);
 
-#elif defined(OS_POSIX)
+#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
 // A POSIX-specific version of LaunchProcess that takes an argv array
 // instead of a CommandLine.  Useful for situations where you need to
 // control the command line arguments directly, but prefer the
@@ -293,7 +291,7 @@
 // given multimap. Only call this function in a child process where you know
 // that there aren't any other threads.
 BASE_EXPORT void CloseSuperfluousFds(const InjectiveMultimap& saved_map);
-#endif  // defined(OS_POSIX)
+#endif  // defined(OS_WIN)
 
 #if defined(OS_WIN)
 // Set |job_object|'s JOBOBJECT_EXTENDED_LIMIT_INFORMATION
@@ -327,9 +325,7 @@
 // instead of a CommandLine object. Useful for situations where you need to
 // control the command line arguments directly.
 BASE_EXPORT bool GetAppOutput(const StringPiece16& cl, std::string* output);
-#endif
-
-#if defined(OS_POSIX)
+#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
 // A POSIX-specific version of GetAppOutput that takes an argv array
 // instead of a CommandLine.  Useful for situations where you need to
 // control the command line arguments directly.
@@ -340,7 +336,7 @@
 // stderr.
 BASE_EXPORT bool GetAppOutputAndError(const std::vector<std::string>& argv,
                                       std::string* output);
-#endif  // defined(OS_POSIX)
+#endif  // defined(OS_WIN)
 
 // If supported on the platform, and the user has sufficent rights, increase
 // the current process's scheduling priority to a high priority.