[go: nahoru, domu]

Move some more file utils to the base namespace.

This also swaps the order of the parameters to GetShmemTempDir so the out
parameter is last, and enhances some documentation.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238144 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/base/base_paths.cc b/base/base_paths.cc
index 9f2b250..b4fc28b6 100644
--- a/base/base_paths.cc
+++ b/base/base_paths.cc
@@ -24,7 +24,7 @@
       cur = cur.DirName();
       break;
     case DIR_TEMP:
-      if (!file_util::GetTempDir(&cur))
+      if (!base::GetTempDir(&cur))
         return false;
       break;
     case DIR_TEST_DATA:
diff --git a/base/base_paths_android.cc b/base/base_paths_android.cc
index d0a709f..68cc5a72c 100644
--- a/base/base_paths_android.cc
+++ b/base/base_paths_android.cc
@@ -48,7 +48,7 @@
     case base::DIR_ANDROID_APP_DATA:
       return base::android::GetDataDirectory(result);
     case base::DIR_HOME:
-      *result = file_util::GetHomeDir();
+      *result = GetHomeDir();
       return true;
     case base::DIR_ANDROID_EXTERNAL_STORAGE:
       return base::android::GetExternalStorageDirectory(result);
diff --git a/base/base_paths_posix.cc b/base/base_paths_posix.cc
index 6b26ba8..b4147e9 100644
--- a/base/base_paths_posix.cc
+++ b/base/base_paths_posix.cc
@@ -110,7 +110,7 @@
       return true;
     }
     case base::DIR_HOME:
-      *result = file_util::GetHomeDir();
+      *result = GetHomeDir();
       return true;
   }
   return false;
diff --git a/base/file_util.cc b/base/file_util.cc
index 5e9790e..1f8ba81 100644
--- a/base/file_util.cc
+++ b/base/file_util.cc
@@ -145,6 +145,14 @@
   return true;
 }
 
+bool IsDirectoryEmpty(const FilePath& dir_path) {
+  FileEnumerator files(dir_path, false,
+      FileEnumerator::FILES | FileEnumerator::DIRECTORIES);
+  if (files.Next().empty())
+    return true;
+  return false;
+}
+
 }  // namespace base
 
 // -----------------------------------------------------------------------------
@@ -155,14 +163,6 @@
 using base::FilePath;
 using base::kMaxUniqueFiles;
 
-bool IsDirectoryEmpty(const FilePath& dir_path) {
-  FileEnumerator files(dir_path, false,
-      FileEnumerator::FILES | FileEnumerator::DIRECTORIES);
-  if (files.Next().empty())
-    return true;
-  return false;
-}
-
 FILE* CreateAndOpenTemporaryFile(FilePath* path) {
   FilePath directory;
   if (!GetTempDir(&directory))
diff --git a/base/file_util.h b/base/file_util.h
index ac9f67d4..35225c7 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -181,27 +181,43 @@
 
 #endif  // OS_POSIX
 
+// Returns true if the given directory is empty
+BASE_EXPORT bool IsDirectoryEmpty(const FilePath& dir_path);
+
+// Get the temporary directory provided by the system.
+//
+// WARNING: In general, you should use CreateTemporaryFile variants below
+// instead of this function. Those variants will ensure that the proper
+// permissions are set so that other users on the system can't edit them while
+// 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);
+
+#if defined(OS_POSIX)
+// Get the home directory.  This is more complicated than just getenv("HOME")
+// as it knows to fall back on getpwent() etc.
+//
+// This function is not currently implemented on Windows or Mac because we
+// don't use it. Generally you would use one of PathService's APP_DATA
+// directories on those platforms. If we need it, this could be implemented
+// there to return the appropriate directory.
+BASE_EXPORT FilePath GetHomeDir();
+#endif  // OS_POSIX
+
 }  // namespace base
 
 // -----------------------------------------------------------------------------
 
 namespace file_util {
 
-// Return true if the given directory is empty
-BASE_EXPORT bool IsDirectoryEmpty(const base::FilePath& dir_path);
-
-// Get the temporary directory provided by the system.
-// WARNING: DON'T USE THIS. If you want to create a temporary file, use one of
-// the functions below.
-BASE_EXPORT bool GetTempDir(base::FilePath* path);
-// Get a temporary directory for shared memory files.
-// Only useful on POSIX; redirects to GetTempDir() on Windows.
-BASE_EXPORT bool GetShmemTempDir(base::FilePath* path, bool executable);
-
-// Get the home directory.  This is more complicated than just getenv("HOME")
-// as it knows to fall back on getpwent() etc.
-BASE_EXPORT base::FilePath GetHomeDir();
-
 // Creates a temporary file. The full path is placed in |path|, and the
 // function returns true if was successful in creating the file. The file will
 // be empty and all handles closed after this function returns.
diff --git a/base/file_util_android.cc b/base/file_util_android.cc
index 6ac9def..def4d7c 100644
--- a/base/file_util_android.cc
+++ b/base/file_util_android.cc
@@ -7,10 +7,10 @@
 #include "base/files/file_path.h"
 #include "base/path_service.h"
 
-namespace file_util {
+namespace base {
 
-bool GetShmemTempDir(base::FilePath* path, bool executable) {
+bool GetShmemTempDir(bool executable, base::FilePath* path) {
   return PathService::Get(base::DIR_CACHE, path);
 }
 
-}  // namespace file_util
+}  // namespace base
diff --git a/base/file_util_mac.mm b/base/file_util_mac.mm
index 9d9ac3d9..f8a6b630 100644
--- a/base/file_util_mac.mm
+++ b/base/file_util_mac.mm
@@ -23,9 +23,6 @@
 }
 
 }  // namespace internal
-}  // namepsace base
-
-namespace file_util {
 
 bool GetTempDir(base::FilePath* path) {
   NSString* tmp = NSTemporaryDirectory();
@@ -35,8 +32,8 @@
   return true;
 }
 
-bool GetShmemTempDir(base::FilePath* path, bool executable) {
+bool GetShmemTempDir(bool executable, base::FilePath* path) {
   return GetTempDir(path);
 }
 
-}  // namespace
+}  // namespace base
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 027337f..b6a4945 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -150,6 +150,47 @@
 #endif
 }
 
+// Creates and opens a temporary file in |directory|, returning the
+// file descriptor. |path| is set to the temporary file path.
+// This function does NOT unlink() the file.
+int CreateAndOpenFdForTemporaryFile(FilePath directory, FilePath* path) {
+  ThreadRestrictions::AssertIOAllowed();  // For call to mkstemp().
+  *path = directory.Append(base::TempFileName());
+  const std::string& tmpdir_string = path->value();
+  // this should be OK since mkstemp just replaces characters in place
+  char* buffer = const_cast<char*>(tmpdir_string.c_str());
+
+  return HANDLE_EINTR(mkstemp(buffer));
+}
+
+#if defined(OS_LINUX)
+// Determine if /dev/shm files can be mapped and then mprotect'd PROT_EXEC.
+// This depends on the mount options used for /dev/shm, which vary among
+// different Linux distributions and possibly local configuration.  It also
+// depends on details of kernel--ChromeOS uses the noexec option for /dev/shm
+// but its kernel allows mprotect with PROT_EXEC anyway.
+bool DetermineDevShmExecutable() {
+  bool result = false;
+  FilePath path;
+  int fd = CreateAndOpenFdForTemporaryFile(FilePath("/dev/shm"), &path);
+  if (fd >= 0) {
+    file_util::ScopedFD shm_fd_closer(&fd);
+    DeleteFile(path, false);
+    long sysconf_result = sysconf(_SC_PAGESIZE);
+    CHECK_GE(sysconf_result, 0);
+    size_t pagesize = static_cast<size_t>(sysconf_result);
+    CHECK_GE(sizeof(pagesize), sizeof(sysconf_result));
+    void *mapping = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, 0);
+    if (mapping != MAP_FAILED) {
+      if (mprotect(mapping, pagesize, PROT_READ | PROT_EXEC) == 0)
+        result = true;
+      munmap(mapping, pagesize);
+    }
+  }
+  return result;
+}
+#endif  // defined(OS_LINUX)
+
 }  // namespace
 
 FilePath MakeAbsoluteFilePath(const FilePath& input) {
@@ -405,6 +446,73 @@
   return true;
 }
 
+#if !defined(OS_MACOSX)
+// This is implemented in file_util_mac.mm for Mac.
+bool GetTempDir(FilePath* path) {
+  const char* tmp = getenv("TMPDIR");
+  if (tmp) {
+    *path = FilePath(tmp);
+  } else {
+#if defined(OS_ANDROID)
+    return PathService::Get(base::DIR_CACHE, path);
+#else
+    *path = FilePath("/tmp");
+#endif
+  }
+  return true;
+}
+#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)
+FilePath GetHomeDir() {
+#if defined(OS_CHROMEOS)
+  if (SysInfo::IsRunningOnChromeOS())
+    return FilePath("/home/chronos/user");
+#endif
+
+  const char* home_dir = getenv("HOME");
+  if (home_dir && home_dir[0])
+    return FilePath(home_dir);
+
+#if defined(OS_ANDROID)
+  DLOG(WARNING) << "OS_ANDROID: Home directory lookup not yet implemented.";
+#elif defined(USE_GLIB) && !defined(OS_CHROMEOS)
+  // g_get_home_dir calls getpwent, which can fall through to LDAP calls.
+  ThreadRestrictions::AssertIOAllowed();
+
+  home_dir = g_get_home_dir();
+  if (home_dir && home_dir[0])
+    return FilePath(home_dir);
+#endif
+
+  FilePath rv;
+  if (GetTempDir(&rv))
+    return rv;
+
+  // Last resort.
+  return FilePath("/tmp");
+}
+#endif  // !defined(OS_MACOSX)
+
 }  // namespace base
 
 // -----------------------------------------------------------------------------
@@ -414,6 +522,7 @@
 using base::stat_wrapper_t;
 using base::CallStat;
 using base::CallLstat;
+using base::CreateAndOpenFdForTemporaryFile;
 using base::DirectoryExists;
 using base::FileEnumerator;
 using base::FilePath;
@@ -421,19 +530,6 @@
 using base::RealPath;
 using base::VerifySpecificPathControlledByUser;
 
-// Creates and opens a temporary file in |directory|, returning the
-// file descriptor. |path| is set to the temporary file path.
-// This function does NOT unlink() the file.
-int CreateAndOpenFdForTemporaryFile(FilePath directory, FilePath* path) {
-  base::ThreadRestrictions::AssertIOAllowed();  // For call to mkstemp().
-  *path = directory.Append(base::TempFileName());
-  const std::string& tmpdir_string = path->value();
-  // this should be OK since mkstemp just replaces characters in place
-  char* buffer = const_cast<char*>(tmpdir_string.c_str());
-
-  return HANDLE_EINTR(mkstemp(buffer));
-}
-
 bool CreateTemporaryFile(FilePath* path) {
   base::ThreadRestrictions::AssertIOAllowed();  // For call to close().
   FilePath directory;
@@ -448,7 +544,7 @@
 
 FILE* CreateAndOpenTemporaryShmemFile(FilePath* path, bool executable) {
   FilePath directory;
-  if (!GetShmemTempDir(&directory, executable))
+  if (!GetShmemTempDir(executable, &directory))
     return NULL;
 
   return CreateAndOpenTemporaryFileInDir(directory, path);
@@ -725,101 +821,6 @@
   return true;
 }
 
-#if !defined(OS_MACOSX)
-bool GetTempDir(FilePath* path) {
-  const char* tmp = getenv("TMPDIR");
-  if (tmp)
-    *path = FilePath(tmp);
-  else
-#if defined(OS_ANDROID)
-    return PathService::Get(base::DIR_CACHE, path);
-#else
-    *path = FilePath("/tmp");
-#endif
-  return true;
-}
-
-#if !defined(OS_ANDROID)
-
-#if defined(OS_LINUX)
-// Determine if /dev/shm files can be mapped and then mprotect'd PROT_EXEC.
-// This depends on the mount options used for /dev/shm, which vary among
-// different Linux distributions and possibly local configuration.  It also
-// depends on details of kernel--ChromeOS uses the noexec option for /dev/shm
-// but its kernel allows mprotect with PROT_EXEC anyway.
-
-namespace {
-
-bool DetermineDevShmExecutable() {
-  bool result = false;
-  FilePath path;
-  int fd = CreateAndOpenFdForTemporaryFile(FilePath("/dev/shm"), &path);
-  if (fd >= 0) {
-    ScopedFD shm_fd_closer(&fd);
-    DeleteFile(path, false);
-    long sysconf_result = sysconf(_SC_PAGESIZE);
-    CHECK_GE(sysconf_result, 0);
-    size_t pagesize = static_cast<size_t>(sysconf_result);
-    CHECK_GE(sizeof(pagesize), sizeof(sysconf_result));
-    void *mapping = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, 0);
-    if (mapping != MAP_FAILED) {
-      if (mprotect(mapping, pagesize, PROT_READ | PROT_EXEC) == 0)
-        result = true;
-      munmap(mapping, pagesize);
-    }
-  }
-  return result;
-}
-
-};  // namespace
-#endif  // defined(OS_LINUX)
-
-bool GetShmemTempDir(FilePath* path, bool executable) {
-#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_ANDROID)
-
-FilePath GetHomeDir() {
-#if defined(OS_CHROMEOS)
-  if (base::SysInfo::IsRunningOnChromeOS())
-    return FilePath("/home/chronos/user");
-#endif
-
-  const char* home_dir = getenv("HOME");
-  if (home_dir && home_dir[0])
-    return FilePath(home_dir);
-
-#if defined(OS_ANDROID)
-  DLOG(WARNING) << "OS_ANDROID: Home directory lookup not yet implemented.";
-#elif defined(USE_GLIB) && !defined(OS_CHROMEOS)
-  // g_get_home_dir calls getpwent, which can fall through to LDAP calls.
-  base::ThreadRestrictions::AssertIOAllowed();
-
-  home_dir = g_get_home_dir();
-  if (home_dir && home_dir[0])
-    return FilePath(home_dir);
-#endif
-
-  FilePath rv;
-  if (file_util::GetTempDir(&rv))
-    return rv;
-
-  // Last resort.
-  return FilePath("/tmp");
-}
-#endif  // !defined(OS_MACOSX)
-
 bool VerifyPathControlledByUser(const FilePath& base,
                                 const FilePath& path,
                                 uid_t owner_uid,
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc
index ebccfd4e..968da5b5 100644
--- a/base/file_util_unittest.cc
+++ b/base/file_util_unittest.cc
@@ -1564,7 +1564,7 @@
   for (unsigned int i = 0; i < arraysize(kTmpValues); ++i) {
     FilePath path;
     ::_tputenv_s(kTmpKey, kTmpValues[i]);
-    file_util::GetTempDir(&path);
+    base::GetTempDir(&path);
     EXPECT_TRUE(path.IsAbsolute()) << "$TMP=" << kTmpValues[i] <<
         " result=" << path.value();
   }
@@ -1637,7 +1637,7 @@
 
 TEST_F(FileUtilTest, GetShmemTempDirTest) {
   FilePath dir;
-  EXPECT_TRUE(file_util::GetShmemTempDir(&dir, false));
+  EXPECT_TRUE(GetShmemTempDir(false, &dir));
   EXPECT_TRUE(DirectoryExists(dir));
 }
 
@@ -1933,13 +1933,13 @@
 
   ASSERT_TRUE(file_util::CreateDirectory(empty_dir));
 
-  EXPECT_TRUE(file_util::IsDirectoryEmpty(empty_dir));
+  EXPECT_TRUE(base::IsDirectoryEmpty(empty_dir));
 
   FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt")));
   std::string bar("baz");
   ASSERT_TRUE(file_util::WriteFile(foo, bar.c_str(), bar.length()));
 
-  EXPECT_FALSE(file_util::IsDirectoryEmpty(empty_dir));
+  EXPECT_FALSE(base::IsDirectoryEmpty(empty_dir));
 }
 
 #if defined(OS_POSIX)
diff --git a/base/file_util_win.cc b/base/file_util_win.cc
index 86c5eea..b500b45 100644
--- a/base/file_util_win.cc
+++ b/base/file_util_win.cc
@@ -213,18 +213,8 @@
   return false;
 }
 
-}  // namespace base
-
-// -----------------------------------------------------------------------------
-
-namespace file_util {
-
-using base::DirectoryExists;
-using base::FilePath;
-using base::kFileShareAll;
-
 bool GetTempDir(FilePath* path) {
-  base::ThreadRestrictions::AssertIOAllowed();
+  ThreadRestrictions::AssertIOAllowed();
 
   wchar_t temp_path[MAX_PATH + 1];
   DWORD path_len = ::GetTempPath(MAX_PATH, temp_path);
@@ -237,10 +227,20 @@
   return true;
 }
 
-bool GetShmemTempDir(FilePath* path, bool executable) {
+bool GetShmemTempDir(bool executable, FilePath* path) {
   return GetTempDir(path);
 }
 
+}  // namespace base
+
+// -----------------------------------------------------------------------------
+
+namespace file_util {
+
+using base::DirectoryExists;
+using base::FilePath;
+using base::kFileShareAll;
+
 bool CreateTemporaryFile(FilePath* path) {
   base::ThreadRestrictions::AssertIOAllowed();
 
diff --git a/base/files/file_util_proxy.cc b/base/files/file_util_proxy.cc
index 5f6d405..965b489 100644
--- a/base/files/file_util_proxy.cc
+++ b/base/files/file_util_proxy.cc
@@ -213,7 +213,7 @@
     return PLATFORM_FILE_ERROR_NOT_FOUND;
   }
   if (!base::DeleteFile(file_path, recursive)) {
-    if (!recursive && !file_util::IsDirectoryEmpty(file_path)) {
+    if (!recursive && !base::IsDirectoryEmpty(file_path)) {
       return PLATFORM_FILE_ERROR_NOT_EMPTY;
     }
     return PLATFORM_FILE_ERROR_FAILED;
diff --git a/base/files/scoped_temp_dir_unittest.cc b/base/files/scoped_temp_dir_unittest.cc
index 0c9131c..02b910c 100644
--- a/base/files/scoped_temp_dir_unittest.cc
+++ b/base/files/scoped_temp_dir_unittest.cc
@@ -55,7 +55,7 @@
     test_path = dir.path();
     EXPECT_TRUE(DirectoryExists(test_path));
     FilePath tmp_dir;
-    EXPECT_TRUE(file_util::GetTempDir(&tmp_dir));
+    EXPECT_TRUE(base::GetTempDir(&tmp_dir));
     EXPECT_TRUE(test_path.value().find(tmp_dir.value()) != std::string::npos);
   }
   EXPECT_FALSE(DirectoryExists(test_path));
diff --git a/base/memory/shared_memory_posix.cc b/base/memory/shared_memory_posix.cc
index bb3c280..8bc7da85 100644
--- a/base/memory/shared_memory_posix.cc
+++ b/base/memory/shared_memory_posix.cc
@@ -399,7 +399,7 @@
   DCHECK_EQ(std::string::npos, mem_name.find('\0'));
 
   FilePath temp_dir;
-  if (!file_util::GetShmemTempDir(&temp_dir, false))
+  if (!GetShmemTempDir(false, &temp_dir))
     return false;
 
 #if !defined(OS_MACOSX)
diff --git a/base/nix/mime_util_xdg.cc b/base/nix/mime_util_xdg.cc
index 1a41394..a5a97f4 100644
--- a/base/nix/mime_util_xdg.cc
+++ b/base/nix/mime_util_xdg.cc
@@ -414,7 +414,7 @@
 
 // Add all the xdg icon directories.
 void InitIconDir() {
-  FilePath home = file_util::GetHomeDir();
+  FilePath home = GetHomeDir();
   if (!home.empty()) {
       FilePath legacy_data_dir(home);
       legacy_data_dir = legacy_data_dir.AppendASCII(".icons");
diff --git a/base/nix/xdg_util.cc b/base/nix/xdg_util.cc
index b3caf2a..4c1510f 100644
--- a/base/nix/xdg_util.cc
+++ b/base/nix/xdg_util.cc
@@ -31,7 +31,7 @@
   if (env->GetVar(env_name, &env_value) && !env_value.empty())
     path = FilePath(env_value);
   else
-    path = file_util::GetHomeDir().Append(fallback_dir);
+    path = GetHomeDir().Append(fallback_dir);
   return path.StripTrailingSeparators();
 }
 
@@ -42,7 +42,7 @@
     path = FilePath(xdg_dir);
     free(xdg_dir);
   } else {
-    path = file_util::GetHomeDir().Append(fallback_dir);
+    path = GetHomeDir().Append(fallback_dir);
   }
   return path.StripTrailingSeparators();
 }
diff --git a/base/os_compat_android_unittest.cc b/base/os_compat_android_unittest.cc
index c749b6a2..a1d1fb19c 100644
--- a/base/os_compat_android_unittest.cc
+++ b/base/os_compat_android_unittest.cc
@@ -17,7 +17,7 @@
 // passes.
 TEST_F(OsCompatAndroidTest, DISABLED_TestMkdTemp) {
   FilePath tmp_dir;
-  EXPECT_TRUE(file_util::GetTempDir(&tmp_dir));
+  EXPECT_TRUE(base::GetTempDir(&tmp_dir));
 
   // Not six XXXXXX at the suffix of the path.
   FilePath sub_dir = tmp_dir.Append("XX");
diff --git a/base/sys_info_unittest.cc b/base/sys_info_unittest.cc
index eacf76c..93eff77 100644
--- a/base/sys_info_unittest.cc
+++ b/base/sys_info_unittest.cc
@@ -34,7 +34,7 @@
 TEST_F(SysInfoTest, AmountOfFreeDiskSpace) {
   // We aren't actually testing that it's correct, just that it's sane.
   FilePath tmp_path;
-  ASSERT_TRUE(file_util::GetTempDir(&tmp_path));
+  ASSERT_TRUE(base::GetTempDir(&tmp_path));
   EXPECT_GT(base::SysInfo::AmountOfFreeDiskSpace(tmp_path), 0)
             << tmp_path.value();
 }
diff --git a/chrome/browser/chromeos/drive/file_cache_unittest.cc b/chrome/browser/chromeos/drive/file_cache_unittest.cc
index 23a6149..5d3e8b8 100644
--- a/chrome/browser/chromeos/drive/file_cache_unittest.cc
+++ b/chrome/browser/chromeos/drive/file_cache_unittest.cc
@@ -972,7 +972,7 @@
 
   // Verify that the cache is removed.
   EXPECT_FALSE(cache_->GetCacheEntry(id, &cache_entry));
-  EXPECT_TRUE(file_util::IsDirectoryEmpty(cache_files_dir_));
+  EXPECT_TRUE(base::IsDirectoryEmpty(cache_files_dir_));
 }
 
 }  // namespace internal
diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc
index 77d9f74..55013e4 100644
--- a/chrome/browser/chromeos/login/login_utils.cc
+++ b/chrome/browser/chromeos/login/login_utils.cc
@@ -92,7 +92,7 @@
     FILE_PATH_LITERAL(".rlz_disabled");
 
 base::FilePath GetRlzDisabledFlagPath() {
-  return file_util::GetHomeDir().Append(kRLZDisabledFlagName);
+  return base::GetHomeDir().Append(kRLZDisabledFlagName);
 }
 #endif
 
diff --git a/chrome/browser/diagnostics/sqlite_diagnostics.cc b/chrome/browser/diagnostics/sqlite_diagnostics.cc
index dcb3491..046dc29 100644
--- a/chrome/browser/diagnostics/sqlite_diagnostics.cc
+++ b/chrome/browser/diagnostics/sqlite_diagnostics.cc
@@ -240,14 +240,14 @@
 
 #if defined(OS_CHROMEOS)
 DiagnosticsTest* MakeSqliteNssCertDbTest() {
-  base::FilePath home_dir = file_util::GetHomeDir();
+  base::FilePath home_dir = base::GetHomeDir();
   return new SqliteIntegrityTest(SqliteIntegrityTest::REMOVE_IF_CORRUPT,
                                  DIAGNOSTICS_SQLITE_INTEGRITY_NSS_CERT_TEST,
                                  home_dir.Append(chromeos::kNssCertDbPath));
 }
 
 DiagnosticsTest* MakeSqliteNssKeyDbTest() {
-  base::FilePath home_dir = file_util::GetHomeDir();
+  base::FilePath home_dir = base::GetHomeDir();
   return new SqliteIntegrityTest(SqliteIntegrityTest::REMOVE_IF_CORRUPT,
                                  DIAGNOSTICS_SQLITE_INTEGRITY_NSS_KEY_TEST,
                                  home_dir.Append(chromeos::kNssKeyDbPath));
diff --git a/chrome/browser/download/download_prefs.cc b/chrome/browser/download/download_prefs.cc
index 220bfc5..2514d7e 100644
--- a/chrome/browser/download/download_prefs.cc
+++ b/chrome/browser/download/download_prefs.cc
@@ -46,7 +46,7 @@
 // to the desktop on any platform.
 bool DownloadPathIsDangerous(const base::FilePath& download_path) {
 #if defined(OS_LINUX)
-  base::FilePath home_dir = file_util::GetHomeDir();
+  base::FilePath home_dir = base::GetHomeDir();
   if (download_path == home_dir) {
     return true;
   }
diff --git a/chrome/browser/media_galleries/fileapi/picasa_data_provider.cc b/chrome/browser/media_galleries/fileapi/picasa_data_provider.cc
index 97c6b84d..0633362 100644
--- a/chrome/browser/media_galleries/fileapi/picasa_data_provider.cc
+++ b/chrome/browser/media_galleries/fileapi/picasa_data_provider.cc
@@ -135,7 +135,7 @@
 void PicasaDataProvider::OnTempDirChanged(const base::FilePath& temp_dir_path,
                                           bool error) {
   DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread());
-  if (file_util::IsDirectoryEmpty(temp_dir_path))
+  if (base::IsDirectoryEmpty(temp_dir_path))
     InvalidateData();
 }
 
diff --git a/chrome/browser/net/net_log_temp_file.cc b/chrome/browser/net/net_log_temp_file.cc
index 3b25083..f68528b 100644
--- a/chrome/browser/net/net_log_temp_file.cc
+++ b/chrome/browser/net/net_log_temp_file.cc
@@ -147,7 +147,7 @@
 
 bool NetLogTempFile::GetNetExportLogDirectory(base::FilePath* path) {
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE_USER_BLOCKING));
-  return file_util::GetTempDir(path);
+  return base::GetTempDir(path);
 }
 
 bool NetLogTempFile::NetExportLogExists() {
diff --git a/chrome/browser/net/net_log_temp_file.h b/chrome/browser/net/net_log_temp_file.h
index 4688526..0890cfe 100644
--- a/chrome/browser/net/net_log_temp_file.h
+++ b/chrome/browser/net/net_log_temp_file.h
@@ -23,7 +23,7 @@
 class ChromeNetLog;
 
 // NetLogTempFile logs all the NetLog entries into a temporary file
-// "chrome-net-export-log.json" created in file_util::GetTempDir() directory.
+// "chrome-net-export-log.json" created in base::GetTempDir() directory.
 //
 // NetLogTempFile maintains the current state (state_) of the logging into a
 // chrome-net-export-log.json file.
@@ -65,8 +65,8 @@
   // process.
   explicit NetLogTempFile(ChromeNetLog* chrome_net_log);
 
-  // Returns path name to file_util::GetTempDir() directory. Returns false if
-  // file_util::GetTempDir() fails.
+  // Returns path name to base::GetTempDir() directory. Returns false if
+  // base::GetTempDir() fails.
   virtual bool GetNetExportLogDirectory(base::FilePath* path);
 
   // Returns true if |log_path_| exists.
@@ -100,7 +100,7 @@
   bool EnsureInit();
 
   // Start collecting NetLog data into chrome-net-export-log.json file in
-  // file_util::GetTempDir() directory. It is a no-op if we are already
+  // base::GetTempDir() directory. It is a no-op if we are already
   // collecting data into a file.
   void StartNetLog();
 
@@ -109,7 +109,7 @@
   void StopNetLog();
 
   // Updates |log_path_| with base::FilePath to |log_filename_| in the
-  // file_util::GetTempDir() directory. Returns false if file_util::GetTempDir()
+  // base::GetTempDir() directory. Returns false if base::GetTempDir()
   // fails.
   bool GetNetExportLog();
 
diff --git a/chrome/browser/ui/ash/screenshot_taker.cc b/chrome/browser/ui/ash/screenshot_taker.cc
index f4b254f..99dcfa58 100644
--- a/chrome/browser/ui/ash/screenshot_taker.cc
+++ b/chrome/browser/ui/ash/screenshot_taker.cc
@@ -365,7 +365,7 @@
         ash::Shell::GetInstance()->delegate()->GetCurrentBrowserContext());
     *directory = download_prefs->DownloadPath();
   } else  {
-    if (!file_util::GetTempDir(directory)) {
+    if (!base::GetTempDir(directory)) {
       LOG(ERROR) << "Failed to find temporary directory.";
       return false;
     }
diff --git a/chrome/browser/web_applications/web_app_mac.mm b/chrome/browser/web_applications/web_app_mac.mm
index da753c2e..0be104b 100644
--- a/chrome/browser/web_applications/web_app_mac.mm
+++ b/chrome/browser/web_applications/web_app_mac.mm
@@ -281,7 +281,7 @@
   DCHECK(!app_path.empty());
   base::DeleteFile(app_path, true);
   base::FilePath apps_folder = app_path.DirName();
-  if (file_util::IsDirectoryEmpty(apps_folder))
+  if (base::IsDirectoryEmpty(apps_folder))
     base::DeleteFile(apps_folder, false);
 }
 
diff --git a/chrome/browser/web_applications/web_app_win.cc b/chrome/browser/web_applications/web_app_win.cc
index e4bb258..9c43e89 100644
--- a/chrome/browser/web_applications/web_app_win.cc
+++ b/chrome/browser/web_applications/web_app_win.cc
@@ -460,7 +460,7 @@
   base::FilePath chrome_apps_dir;
   if (PathService::Get(base::DIR_START_MENU, &chrome_apps_dir)) {
     chrome_apps_dir = chrome_apps_dir.Append(GetAppShortcutsSubdirName());
-    if (file_util::IsDirectoryEmpty(chrome_apps_dir))
+    if (base::IsDirectoryEmpty(chrome_apps_dir))
       base::DeleteFile(chrome_apps_dir, false);
   }
 }
@@ -473,7 +473,7 @@
   base::FilePath chrome_apps_dir;
   if (PathService::Get(base::DIR_START_MENU, &chrome_apps_dir)) {
     chrome_apps_dir = chrome_apps_dir.Append(GetAppShortcutsSubdirName());
-    if (file_util::IsDirectoryEmpty(chrome_apps_dir))
+    if (base::IsDirectoryEmpty(chrome_apps_dir))
       base::DeleteFile(chrome_apps_dir, false);
   }
 }
diff --git a/chrome/common/chrome_paths_linux.cc b/chrome/common/chrome_paths_linux.cc
index e90c2f5..7a71caf7 100644
--- a/chrome/common/chrome_paths_linux.cc
+++ b/chrome/common/chrome_paths_linux.cc
@@ -34,7 +34,7 @@
 #else
   *result = GetXDGUserDirectory(xdg_name.c_str(), fallback_name.c_str());
 
-  base::FilePath home = file_util::GetHomeDir();
+  base::FilePath home = base::GetHomeDir();
   if (*result != home) {
     base::FilePath desktop;
     if (!PathService::Get(base::DIR_USER_DESKTOP, &desktop))
@@ -116,7 +116,7 @@
 }
 
 bool GetUserDownloadsDirectorySafe(base::FilePath* result) {
-  base::FilePath home = file_util::GetHomeDir();
+  base::FilePath home = base::GetHomeDir();
   *result = home.Append(kDownloadsDir);
   return true;
 }
diff --git a/chrome/common/chrome_paths_unittest.cc b/chrome/common/chrome_paths_unittest.cc
index 5d97afc..5251154 100644
--- a/chrome/common/chrome_paths_unittest.cc
+++ b/chrome/common/chrome_paths_unittest.cc
@@ -29,7 +29,7 @@
   base::FilePath expected_cache_dir;
   ASSERT_TRUE(PathService::Get(base::DIR_CACHE, &expected_cache_dir));
 #elif(OS_POSIX)
-  base::FilePath homedir = file_util::GetHomeDir();
+  base::FilePath homedir = base::GetHomeDir();
   // Note: we assume XDG_CACHE_HOME/XDG_CONFIG_HOME are at their
   // default settings.
   test_profile_dir = homedir.Append(".config/foobar");
diff --git a/chrome/common/importer/firefox_importer_utils_linux.cc b/chrome/common/importer/firefox_importer_utils_linux.cc
index 51868d53..71f1a26 100644
--- a/chrome/common/importer/firefox_importer_utils_linux.cc
+++ b/chrome/common/importer/firefox_importer_utils_linux.cc
@@ -10,7 +10,7 @@
   base::FilePath ini_file;
   // The default location of the profile folder containing user data is
   // under user HOME directory in .mozilla/firefox folder on Linux.
-  base::FilePath home = file_util::GetHomeDir();
+  base::FilePath home = base::GetHomeDir();
   if (!home.empty()) {
     ini_file = home.Append(".mozilla/firefox/profiles.ini");
   }
diff --git a/chrome/installer/setup/setup_main.cc b/chrome/installer/setup/setup_main.cc
index 9ffc9862..dc2bec6c 100644
--- a/chrome/installer/setup/setup_main.cc
+++ b/chrome/installer/setup/setup_main.cc
@@ -1339,7 +1339,7 @@
 
   // Get the alternate dump directory. We use the temp path.
   base::FilePath temp_directory;
-  if (!file_util::GetTempDir(&temp_directory) || temp_directory.empty())
+  if (!base::GetTempDir(&temp_directory) || temp_directory.empty())
     return NULL;
 
   wchar_t exe_path[MAX_PATH * 2] = {0};
diff --git a/chrome/installer/setup/uninstall.cc b/chrome/installer/setup/uninstall.cc
index 460c4905..de4f3f7 100644
--- a/chrome/installer/setup/uninstall.cc
+++ b/chrome/installer/setup/uninstall.cc
@@ -447,7 +447,7 @@
 // directory is deleted, DELETE_NOT_EMPTY if it is not empty, and DELETE_FAILED
 // otherwise.
 DeleteResult DeleteEmptyDir(const base::FilePath& path) {
-  if (!file_util::IsDirectoryEmpty(path))
+  if (!base::IsDirectoryEmpty(path))
     return DELETE_NOT_EMPTY;
 
   if (base::DeleteFile(path, true))
diff --git a/chrome/installer/util/move_tree_work_item_unittest.cc b/chrome/installer/util/move_tree_work_item_unittest.cc
index 614b9d4..ef0c252 100644
--- a/chrome/installer/util/move_tree_work_item_unittest.cc
+++ b/chrome/installer/util/move_tree_work_item_unittest.cc
@@ -439,7 +439,7 @@
   EXPECT_TRUE(base::PathExists(to_dir));
   EXPECT_TRUE(base::PathExists(orig_to_file));
   // Make sure that the backup path is not empty.
-  EXPECT_FALSE(file_util::IsDirectoryEmpty(temp_to_dir_.path()));
+  EXPECT_FALSE(base::IsDirectoryEmpty(temp_to_dir_.path()));
 
   // Check that the work item believes the source to have been moved.
   EXPECT_TRUE(work_item->source_moved_to_backup_);
@@ -515,7 +515,7 @@
   EXPECT_TRUE(base::PathExists(to_dir));
   EXPECT_TRUE(base::PathExists(orig_to_file));
   // Make sure that the backup path is not empty.
-  EXPECT_FALSE(file_util::IsDirectoryEmpty(temp_to_dir_.path()));
+  EXPECT_FALSE(base::IsDirectoryEmpty(temp_to_dir_.path()));
   // Make sure that the "new" file is also present.
   base::FilePath new_to_file2(to_dir2);
   new_to_file2 = new_to_file2.AppendASCII("From_File2");
diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc
index f5b8544c..9530126 100644
--- a/chrome/installer/util/shell_util.cc
+++ b/chrome/installer/util/shell_util.cc
@@ -1328,7 +1328,7 @@
     LOG(WARNING) << "Cannot find path at location " << location;
     return false;
   }
-  if (file_util::IsDirectoryEmpty(shortcut_folder) &&
+  if (base::IsDirectoryEmpty(shortcut_folder) &&
       !base::DeleteFile(shortcut_folder, true)) {
     LOG(ERROR) << "Cannot remove folder " << shortcut_folder.value();
     return false;
diff --git a/chrome/tools/crash_service/main.cc b/chrome/tools/crash_service/main.cc
index 9fd9e87c..bb684bb 100644
--- a/chrome/tools/crash_service/main.cc
+++ b/chrome/tools/crash_service/main.cc
@@ -21,7 +21,7 @@
 
 bool GetCrashServiceDirectory(base::FilePath* dir) {
   base::FilePath temp_dir;
-  if (!file_util::GetTempDir(&temp_dir))
+  if (!base::GetTempDir(&temp_dir))
     return false;
   temp_dir = temp_dir.Append(L"chrome_crashes");
   if (!base::PathExists(temp_dir)) {
diff --git a/chrome_frame/chrome_frame_reporting.cc b/chrome_frame/chrome_frame_reporting.cc
index 0a0608a..ead924a2 100644
--- a/chrome_frame/chrome_frame_reporting.cc
+++ b/chrome_frame/chrome_frame_reporting.cc
@@ -66,7 +66,7 @@
 
   // Get the alternate dump directory. We use the temp path.
   base::FilePath temp_directory;
-  if (!file_util::GetTempDir(&temp_directory) || temp_directory.empty())
+  if (!base::GetTempDir(&temp_directory) || temp_directory.empty())
     return false;
 
   wchar_t dll_path[MAX_PATH * 2] = {0};
diff --git a/content/browser/dom_storage/session_storage_database.cc b/content/browser/dom_storage/session_storage_database.cc
index bac3df7..7b8dcd0 100644
--- a/content/browser/dom_storage/session_storage_database.cc
+++ b/content/browser/dom_storage/session_storage_database.cc
@@ -280,8 +280,7 @@
     return true;
 
   if (!create_if_needed &&
-      (!base::PathExists(file_path_) ||
-       file_util::IsDirectoryEmpty(file_path_))) {
+      (!base::PathExists(file_path_) || base::IsDirectoryEmpty(file_path_))) {
     // If the directory doesn't exist already and we haven't been asked to
     // create a file on disk, then we don't bother opening the database. This
     // means we wait until we absolutely need to put something onto disk before
diff --git a/content/common/plugin_list_posix.cc b/content/common/plugin_list_posix.cc
index 3e1353be..a5d7fac5b 100644
--- a/content/common/plugin_list_posix.cc
+++ b/content/common/plugin_list_posix.cc
@@ -464,7 +464,7 @@
   // 2) NS_USER_PLUGINS_DIR: ~/.mozilla/plugins.
   // This is a de-facto standard, so even though we're not Mozilla, let's
   // look in there too.
-  base::FilePath home = file_util::GetHomeDir();
+  base::FilePath home = base::GetHomeDir();
   if (!home.empty())
     plugin_dirs->push_back(home.Append(".mozilla/plugins"));
 
diff --git a/content/shell/browser/shell_browser_main.cc b/content/shell/browser/shell_browser_main.cc
index ed4fb62..ad2cbdae 100644
--- a/content/shell/browser/shell_browser_main.cc
+++ b/content/shell/browser/shell_browser_main.cc
@@ -151,7 +151,7 @@
       // We're outside of the message loop here, and this is a test.
       base::ThreadRestrictions::ScopedAllowIO allow_io;
       base::FilePath temp_path;
-      file_util::GetTempDir(&temp_path);
+      base::GetTempDir(&temp_path);
       test_controller.SetTempPath(temp_path);
     }
     std::string test_string;
diff --git a/crypto/nss_util.cc b/crypto/nss_util.cc
index 5f20595..a74c8b65 100644
--- a/crypto/nss_util.cc
+++ b/crypto/nss_util.cc
@@ -79,7 +79,7 @@
 
 #if defined(USE_NSS)
 base::FilePath GetDefaultConfigDirectory() {
-  base::FilePath dir = file_util::GetHomeDir();
+  base::FilePath dir = base::GetHomeDir();
   if (dir.empty()) {
     LOG(ERROR) << "Failed to get home directory.";
     return dir;
diff --git a/net/socket/unix_domain_socket_posix_unittest.cc b/net/socket/unix_domain_socket_posix_unittest.cc
index f63d60a..6520985 100644
--- a/net/socket/unix_domain_socket_posix_unittest.cc
+++ b/net/socket/unix_domain_socket_posix_unittest.cc
@@ -54,7 +54,7 @@
 
 string MakeSocketPath(const string& socket_file_name) {
   base::FilePath temp_dir;
-  file_util::GetTempDir(&temp_dir);
+  base::GetTempDir(&temp_dir);
   return temp_dir.Append(socket_file_name).value();
 }
 
diff --git a/printing/backend/cups_helper.cc b/printing/backend/cups_helper.cc
index 74df558..1ed04cb 100644
--- a/printing/backend/cups_helper.cc
+++ b/printing/backend/cups_helper.cc
@@ -99,7 +99,7 @@
   std::vector<base::FilePath> file_locations;
   file_locations.push_back(base::FilePath(kSystemLpOptionPath));
   file_locations.push_back(base::FilePath(
-      file_util::GetHomeDir().Append(kUserLpOptionPath)));
+      base::GetHomeDir().Append(kUserLpOptionPath)));
 
   for (std::vector<base::FilePath>::const_iterator it = file_locations.begin();
        it != file_locations.end(); ++it) {
diff --git a/remoting/host/branding.cc b/remoting/host/branding.cc
index 908d9bc..840e9822 100644
--- a/remoting/host/branding.cc
+++ b/remoting/host/branding.cc
@@ -46,7 +46,7 @@
 #elif defined(OS_MACOSX)
   PathService::Get(base::DIR_APP_DATA, &app_data_dir);
 #else
-  app_data_dir = file_util::GetHomeDir();
+  app_data_dir = base::GetHomeDir();
 #endif
 
   return app_data_dir.Append(kConfigDir);
diff --git a/remoting/host/setup/daemon_controller_delegate_linux.cc b/remoting/host/setup/daemon_controller_delegate_linux.cc
index 54be540..bed305f6 100644
--- a/remoting/host/setup/daemon_controller_delegate_linux.cc
+++ b/remoting/host/setup/daemon_controller_delegate_linux.cc
@@ -55,7 +55,7 @@
 
 base::FilePath GetConfigPath() {
   std::string filename = "host#" + GetMd5(net::GetHostName()) + ".json";
-  return file_util::GetHomeDir().
+  return base::GetHomeDir().
       Append(".config/chrome-remote-desktop").Append(filename);
 }
 
diff --git a/remoting/host/setup/daemon_controller_delegate_mac.mm b/remoting/host/setup/daemon_controller_delegate_mac.mm
index 749a6ab..bb27e88 100644
--- a/remoting/host/setup/daemon_controller_delegate_mac.mm
+++ b/remoting/host/setup/daemon_controller_delegate_mac.mm
@@ -224,7 +224,7 @@
     const std::string& config_data) {
   if (!config_data.empty()) {
     base::FilePath config_path;
-    if (!file_util::GetTempDir(&config_path)) {
+    if (!base::GetTempDir(&config_path)) {
       LOG(ERROR) << "Failed to get filename for saving configuration data.";
       return false;
     }
diff --git a/rlz/chromeos/lib/rlz_value_store_chromeos.cc b/rlz/chromeos/lib/rlz_value_store_chromeos.cc
index a636863..06e4a54 100644
--- a/rlz/chromeos/lib/rlz_value_store_chromeos.cc
+++ b/rlz/chromeos/lib/rlz_value_store_chromeos.cc
@@ -43,14 +43,14 @@
 // Returns file path of the RLZ storage.
 base::FilePath GetRlzStorePath() {
   return g_testing_rlz_store_path_.empty() ?
-      file_util::GetHomeDir().Append(kRLZDataFileName) :
+      base::GetHomeDir().Append(kRLZDataFileName) :
       g_testing_rlz_store_path_.Append(kRLZDataFileName);
 }
 
 // Returns file path of the RLZ storage lock file.
 base::FilePath GetRlzStoreLockPath() {
   return g_testing_rlz_store_path_.empty() ?
-      file_util::GetHomeDir().Append(kRLZLockFileName) :
+      base::GetHomeDir().Append(kRLZLockFileName) :
       g_testing_rlz_store_path_.Append(kRLZLockFileName);
 }
 
diff --git a/webkit/browser/fileapi/native_file_util.cc b/webkit/browser/fileapi/native_file_util.cc
index df290c5..48569d5 100644
--- a/webkit/browser/fileapi/native_file_util.cc
+++ b/webkit/browser/fileapi/native_file_util.cc
@@ -264,7 +264,7 @@
     return base::PLATFORM_FILE_ERROR_NOT_FOUND;
   if (!base::DirectoryExists(path))
     return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY;
-  if (!file_util::IsDirectoryEmpty(path))
+  if (!base::IsDirectoryEmpty(path))
     return base::PLATFORM_FILE_ERROR_NOT_EMPTY;
   if (!base::DeleteFile(path, false))
     return base::PLATFORM_FILE_ERROR_FAILED;