diff options
author | thorogood@chromium.org <thorogood@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-23 08:22:44 +0000 |
---|---|---|
committer | thorogood@chromium.org <thorogood@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-23 08:22:44 +0000 |
commit | 92e44ae0ad94910984b79979ad47d6b32b534c57 (patch) | |
tree | 9144c20bd36d281f3885c1b29539142b8cce0a55 | |
parent | af312ef7fecc613eef9532fd64b48ca23110db09 (diff) | |
download | chromium_src-92e44ae0ad94910984b79979ad47d6b32b534c57.zip chromium_src-92e44ae0ad94910984b79979ad47d6b32b534c57.tar.gz chromium_src-92e44ae0ad94910984b79979ad47d6b32b534c57.tar.bz2 |
Prettify output from chrome.fileSystem.getDisplayPath for POSIX profile directories
This duplicates review 10693089, except for POSIX. Modifies e.g. "/home/sam/foo" to "~/foo". As a dependency, adds DIR_HOME to PathService for retrieving POSIX home directory.
BUG=135690
TEST=
Review URL: https://chromiumcodereview.appspot.com/10700136
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147833 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/base_paths.h | 1 | ||||
-rw-r--r-- | base/base_paths_mac.mm | 4 | ||||
-rw-r--r-- | base/base_paths_posix.cc | 7 | ||||
-rw-r--r-- | base/file_util_posix.cc | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/api/file_system/file_system_api.cc | 14 | ||||
-rw-r--r-- | chrome/browser/extensions/api/file_system/file_system_apitest.cc | 9 |
6 files changed, 24 insertions, 13 deletions
diff --git a/base/base_paths.h b/base/base_paths.h index ea62a8b..3875fb4 100644 --- a/base/base_paths.h +++ b/base/base_paths.h @@ -40,6 +40,7 @@ enum BasePathKey { // browser cache can be a subdirectory. // This is $XDG_CACHE_HOME on Linux and // ~/Library/Caches on Mac. + DIR_HOME, // $HOME on POSIX-like systems. #endif PATH_END diff --git a/base/base_paths_mac.mm b/base/base_paths_mac.mm index 56f3ecb..e46fd1e 100644 --- a/base/base_paths_mac.mm +++ b/base/base_paths_mac.mm @@ -83,6 +83,10 @@ bool PathProviderMac(int key, FilePath* result) { #endif return true; } + case base::DIR_HOME: { + *result = base::mac::NSStringToFilePath(NSHomeDirectory()); + return true; + } default: return false; } diff --git a/base/base_paths_posix.cc b/base/base_paths_posix.cc index d8d5ae6..743f77a 100644 --- a/base/base_paths_posix.cc +++ b/base/base_paths_posix.cc @@ -85,12 +85,17 @@ bool PathProviderPosix(int key, FilePath* result) { << "Try running from your chromium/src directory."; return false; } - case base::DIR_CACHE: + case base::DIR_CACHE: { scoped_ptr<base::Environment> env(base::Environment::Create()); FilePath cache_dir(base::nix::GetXDGDirectory(env.get(), "XDG_CACHE_HOME", ".cache")); *result = cache_dir; return true; + } + case base::DIR_HOME: { + *result = file_util::GetHomeDir(); + return true; + } } return false; } diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc index f198f44..0dc4f33 100644 --- a/base/file_util_posix.cc +++ b/base/file_util_posix.cc @@ -1085,7 +1085,7 @@ bool CopyFile(const FilePath& from_path, const FilePath& to_path) { return result; } -#endif // defined(OS_MACOSX) +#endif // !defined(OS_MACOSX) bool VerifyPathControlledByUser(const FilePath& base, const FilePath& path, diff --git a/chrome/browser/extensions/api/file_system/file_system_api.cc b/chrome/browser/extensions/api/file_system/file_system_api.cc index c3c7125..eb20c11 100644 --- a/chrome/browser/extensions/api/file_system/file_system_api.cc +++ b/chrome/browser/extensions/api/file_system/file_system_api.cc @@ -51,19 +51,14 @@ struct RewritePair { const RewritePair g_rewrite_pairs[] = { #if defined(OS_WIN) {base::DIR_PROFILE, "~"}, +#elif defined(OS_POSIX) + {base::DIR_HOME, "~"}, #endif }; FilePath PrettifyPath(const FilePath& file_path) { - // Note that when g_rewrite_pairs includes at least one value on all - // platforms, this code can be cleaned up. -#if defined(OS_WIN) - size_t size = arraysize(g_rewrite_pairs); -#else - size_t size = 0; -#endif - - for (size_t i = 0; i < size; ++i) { +#if defined(OS_WIN) || defined(OS_POSIX) + for (size_t i = 0; i < arraysize(g_rewrite_pairs); ++i) { FilePath candidate_path; if (!PathService::Get(g_rewrite_pairs[i].path_key, &candidate_path)) continue; // We don't DCHECK this value, as Get will return false even @@ -77,6 +72,7 @@ FilePath PrettifyPath(const FilePath& file_path) { return output; } } +#endif return file_path; } diff --git a/chrome/browser/extensions/api/file_system/file_system_apitest.cc b/chrome/browser/extensions/api/file_system/file_system_apitest.cc index 4cdbe4f..0bc334d 100644 --- a/chrome/browser/extensions/api/file_system/file_system_apitest.cc +++ b/chrome/browser/extensions/api/file_system/file_system_apitest.cc @@ -48,9 +48,14 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetDisplayPath) { << message_; } -#if defined(OS_WIN) +#if defined(OS_WIN) || defined(OS_POSIX) IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetDisplayPathPrettify) { - ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(base::DIR_PROFILE, +#if defined(OS_WIN) + int override = base::DIR_PROFILE; +#elif defined(OS_POSIX) + int override = base::DIR_HOME; +#endif + ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(override, test_root_folder_, false)); FilePath test_file = test_root_folder_.AppendASCII("gold.txt"); |