Make the shmem-specific functions in file_util.h POSIX-only.

They're only used on POSIX. (This is an initial move/removal; more to
come.)

R=brettw@chromium.org

Review URL: https://codereview.chromium.org/204683002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258242 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 6f5418ba7f128c0e1d0c89f8b647bb68400e9b22
diff --git a/base/file_util.h b/base/file_util.h
index b86d8cb..9646c76 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -211,15 +211,6 @@
 // they're open (which can lead to security issues).
 BASE_EXPORT bool GetTempDir(FilePath* path);
 
-// Get a temporary directory for shared memory files. The directory may depend
-// on whether the destination is intended for executable files, which in turn
-// depends on how /dev/shmem was mounted. As a result, you must supply whether
-// you intend to create executable shmem segments so this function can find
-// an appropriate location.
-//
-// Only useful on POSIX; redirects to GetTempDir() on Windows.
-BASE_EXPORT bool GetShmemTempDir(bool executable, FilePath* path);
-
 // Get the home directory. This is more complicated than just getenv("HOME")
 // as it knows to fall back on getpwent() etc.
 //
@@ -241,12 +232,6 @@
 // Returns a handle to the opened file or NULL if an error occurred.
 BASE_EXPORT FILE* CreateAndOpenTemporaryFile(FilePath* path);
 
-// Like above but for shmem files.  Only useful for POSIX.
-// The executable flag says the file needs to support using
-// mprotect with PROT_EXEC after mapping.
-BASE_EXPORT FILE* CreateAndOpenTemporaryShmemFile(FilePath* path,
-                                                  bool executable);
-
 // Similar to CreateAndOpenTemporaryFile, but the file is created in |dir|.
 BASE_EXPORT FILE* CreateAndOpenTemporaryFileInDir(const FilePath& dir,
                                                   FilePath* path);
@@ -409,6 +394,21 @@
 BASE_EXPORT bool GetFileSystemType(const FilePath& path, FileSystemType* type);
 #endif
 
+#if defined(OS_POSIX)
+// Get a temporary directory for shared memory files. The directory may depend
+// on whether the destination is intended for executable files, which in turn
+// depends on how /dev/shmem was mounted. As a result, you must supply whether
+// you intend to create executable shmem segments so this function can find
+// an appropriate location.
+BASE_EXPORT bool GetShmemTempDir(bool executable, FilePath* path);
+
+// Like above but for shmem files.  Only useful for POSIX.
+// The executable flag says the file needs to support using
+// mprotect with PROT_EXEC after mapping.
+BASE_EXPORT FILE* CreateAndOpenTemporaryShmemFile(FilePath* path,
+                                                  bool executable);
+#endif
+
 }  // namespace base
 
 // -----------------------------------------------------------------------------
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index fb4ebcf..0879510 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -463,25 +463,6 @@
 }
 #endif  // !defined(OS_MACOSX)
 
-#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
-// This is implemented in file_util_mac.mm and file_util_android.cc for those
-// platforms.
-bool GetShmemTempDir(bool executable, FilePath* path) {
-#if defined(OS_LINUX)
-  bool use_dev_shm = true;
-  if (executable) {
-    static const bool s_dev_shm_executable = DetermineDevShmExecutable();
-    use_dev_shm = s_dev_shm_executable;
-  }
-  if (use_dev_shm) {
-    *path = FilePath("/dev/shm");
-    return true;
-  }
-#endif
-  return GetTempDir(path);
-}
-#endif  // !defined(OS_MACOSX) && !defined(OS_ANDROID)
-
 #if !defined(OS_MACOSX)  // Mac implementation is in file_util_mac.mm.
 FilePath GetHomeDir() {
 #if defined(OS_CHROMEOS)
@@ -528,14 +509,6 @@
   return true;
 }
 
-FILE* CreateAndOpenTemporaryShmemFile(FilePath* path, bool executable) {
-  FilePath directory;
-  if (!GetShmemTempDir(executable, &directory))
-    return NULL;
-
-  return CreateAndOpenTemporaryFileInDir(directory, path);
-}
-
 FILE* CreateAndOpenTemporaryFileInDir(const FilePath& dir, FilePath* path) {
   int fd = CreateAndOpenFdForTemporaryFile(dir, path);
   if (fd < 0)
@@ -847,6 +820,33 @@
   return pathconf(path.value().c_str(), _PC_NAME_MAX);
 }
 
+#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
+// This is implemented in file_util_mac.mm and file_util_android.cc for those
+// platforms.
+bool GetShmemTempDir(bool executable, FilePath* path) {
+#if defined(OS_LINUX)
+  bool use_dev_shm = true;
+  if (executable) {
+    static const bool s_dev_shm_executable = DetermineDevShmExecutable();
+    use_dev_shm = s_dev_shm_executable;
+  }
+  if (use_dev_shm) {
+    *path = FilePath("/dev/shm");
+    return true;
+  }
+#endif
+  return GetTempDir(path);
+}
+#endif  // !defined(OS_MACOSX) && !defined(OS_ANDROID)
+
+FILE* CreateAndOpenTemporaryShmemFile(FilePath* path, bool executable) {
+  FilePath directory;
+  if (!GetShmemTempDir(executable, &directory))
+    return NULL;
+
+  return CreateAndOpenTemporaryFileInDir(directory, path);
+}
+
 // -----------------------------------------------------------------------------
 
 namespace internal {
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc
index 8ee55ff..4bdd90f 100644
--- a/base/file_util_unittest.cc
+++ b/base/file_util_unittest.cc
@@ -1691,11 +1691,13 @@
   EXPECT_TRUE(DeleteFile(new_dir, false));
 }
 
+#if defined(OS_POSIX)
 TEST_F(FileUtilTest, GetShmemTempDirTest) {
   FilePath dir;
   EXPECT_TRUE(GetShmemTempDir(false, &dir));
   EXPECT_TRUE(DirectoryExists(dir));
 }
+#endif
 
 TEST_F(FileUtilTest, GetHomeDirTest) {
 #if !defined(OS_ANDROID)  // Not implemented on Android.