diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-14 04:18:14 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-14 04:18:14 +0000 |
commit | fa9ac63a311ff3754dae28f8facc6ffd5db37f5d (patch) | |
tree | a7cf6404ddd4700619ce569a605371a0072cb243 | |
parent | ad377ae01314e1b74db3e7810c151ddfc6daaa7c (diff) | |
download | chromium_src-fa9ac63a311ff3754dae28f8facc6ffd5db37f5d.zip chromium_src-fa9ac63a311ff3754dae28f8facc6ffd5db37f5d.tar.gz chromium_src-fa9ac63a311ff3754dae28f8facc6ffd5db37f5d.tar.bz2 |
Add Add PathService::Get(chrome::DIR_USER_MUSIC) and PathService::Get(chrome::DIR_USER_VIDEOS).
Review URL: https://chromiumcodereview.appspot.com/10918228
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156737 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/common/chrome_paths.cc | 8 | ||||
-rw-r--r-- | chrome/common/chrome_paths.h | 2 | ||||
-rw-r--r-- | chrome/common/chrome_paths_android.cc | 10 | ||||
-rw-r--r-- | chrome/common/chrome_paths_internal.h | 6 | ||||
-rw-r--r-- | chrome/common/chrome_paths_linux.cc | 67 | ||||
-rw-r--r-- | chrome/common/chrome_paths_mac.mm | 8 | ||||
-rw-r--r-- | chrome/common/chrome_paths_win.cc | 54 |
7 files changed, 106 insertions, 49 deletions
diff --git a/chrome/common/chrome_paths.cc b/chrome/common/chrome_paths.cc index 0e76828..ec3d49e 100644 --- a/chrome/common/chrome_paths.cc +++ b/chrome/common/chrome_paths.cc @@ -167,10 +167,18 @@ bool PathProvider(int key, FilePath* result) { return false; create_dir = true; break; + case chrome::DIR_USER_MUSIC: + if (!GetUserMusicDirectory(&cur)) + return false; + break; case chrome::DIR_USER_PICTURES: if (!GetUserPicturesDirectory(&cur)) return false; break; + case chrome::DIR_USER_VIDEOS: + if (!GetUserVideosDirectory(&cur)) + return false; + break; case chrome::DIR_DEFAULT_DOWNLOADS_SAFE: #if defined(OS_WIN) || defined(OS_LINUX) if (!GetUserDownloadsDirectorySafe(&cur)) diff --git a/chrome/common/chrome_paths.h b/chrome/common/chrome_paths.h index 8841c3b..084c6c1 100644 --- a/chrome/common/chrome_paths.h +++ b/chrome/common/chrome_paths.h @@ -29,7 +29,9 @@ enum { DIR_INSPECTOR, // Directory where web inspector is located. DIR_APP_DICTIONARIES, // Directory where the global dictionaries are. DIR_USER_DOCUMENTS, // Directory for a user's "My Documents". + DIR_USER_MUSIC, // Directory for a user's music. DIR_USER_PICTURES, // Directory for a user's pictures. + DIR_USER_VIDEOS, // Directory for a user's videos. DIR_DEFAULT_DOWNLOADS_SAFE, // Directory for a user's // "My Documents/Downloads", (Windows) or // "Downloads". (Linux) diff --git a/chrome/common/chrome_paths_android.cc b/chrome/common/chrome_paths_android.cc index 00516f5..d647806 100644 --- a/chrome/common/chrome_paths_android.cc +++ b/chrome/common/chrome_paths_android.cc @@ -33,11 +33,21 @@ bool GetUserDownloadsDirectory(FilePath* result) { return true; } +bool GetUserMusicDirectory(FilePath* result) { + NOTIMPLEMENTED(); + return false; +} + bool GetUserPicturesDirectory(FilePath* result) { NOTIMPLEMENTED(); return false; } +bool GetUserVideosDirectory(FilePath* result) { + NOTIMPLEMENTED(); + return false; +} + bool GetUserDesktop(FilePath* result) { NOTIMPLEMENTED() << "Android doesn't support GetUserDesktop"; return false; diff --git a/chrome/common/chrome_paths_internal.h b/chrome/common/chrome_paths_internal.h index 6add8689..40e9742 100644 --- a/chrome/common/chrome_paths_internal.h +++ b/chrome/common/chrome_paths_internal.h @@ -56,9 +56,15 @@ bool GetUserDownloadsDirectorySafe(FilePath* result); // Get the path to the user's downloads directory. bool GetUserDownloadsDirectory(FilePath* result); +// Gets the path to the user's music directory. +bool GetUserMusicDirectory(FilePath* result); + // Gets the path to the user's pictures directory. bool GetUserPicturesDirectory(FilePath* result); +// Gets the path to the user's videos directory. +bool GetUserVideosDirectory(FilePath* result); + // The path to the user's desktop. bool GetUserDesktop(FilePath* result); diff --git a/chrome/common/chrome_paths_linux.cc b/chrome/common/chrome_paths_linux.cc index adfcca6..321032f 100644 --- a/chrome/common/chrome_paths_linux.cc +++ b/chrome/common/chrome_paths_linux.cc @@ -10,19 +10,45 @@ #include "base/nix/xdg_util.h" #include "base/path_service.h" +namespace chrome { + +using base::nix::GetXDGDirectory; +using base::nix::GetXDGUserDirectory; +using base::nix::kDotConfigDir; +using base::nix::kXdgConfigHomeEnvVar; + namespace { const char kDownloadsDir[] = "Downloads"; +const char kMusicDir[] = "Music"; const char kPicturesDir[] = "Pictures"; +const char kVideosDir[] = "Videos"; -} // namespace +// Generic function for GetUser{Music,Pictures,Video}Directory. +bool GetUserMediaDirectory(const std::string& xdg_name, + const std::string& fallback_name, + FilePath* result) { +#if defined(OS_CHROMEOS) + // No local media directories on CrOS. + return false; +#else + *result = GetXDGUserDirectory(xdg_name.c_str(), fallback_name.c_str()); -namespace chrome { + FilePath home = file_util::GetHomeDir(); + if (*result != home) { + FilePath desktop; + GetUserDesktop(&desktop); + if (*result != desktop) { + return true; + } + } -using base::nix::GetXDGDirectory; -using base::nix::GetXDGUserDirectory; -using base::nix::kDotConfigDir; -using base::nix::kXdgConfigHomeEnvVar; + *result = home.Append(fallback_name); + return true; +#endif +} + +} // namespace // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html // for a spec on where config files go. The net effect for most @@ -99,26 +125,21 @@ bool GetUserDownloadsDirectory(FilePath* result) { } // We respect the user's preferred pictures location, unless it is +// ~ or their desktop directory, in which case we default to ~/Music. +bool GetUserMusicDirectory(FilePath* result) { + return GetUserMediaDirectory("MUSIC", kMusicDir, result); +} + +// We respect the user's preferred pictures location, unless it is // ~ or their desktop directory, in which case we default to ~/Pictures. bool GetUserPicturesDirectory(FilePath* result) { -#if defined(OS_CHROMEOS) - // No local Pictures directory on CrOS. - return false; -#else - *result = GetXDGUserDirectory("PICTURES", kPicturesDir); - - FilePath home = file_util::GetHomeDir(); - if (*result != home) { - FilePath desktop; - GetUserDesktop(&desktop); - if (*result != desktop) { - return true; - } - } + return GetUserMediaDirectory("PICTURES", kPicturesDir, result); +} - *result = home.Append(kPicturesDir); - return true; -#endif +// We respect the user's preferred pictures location, unless it is +// ~ or their desktop directory, in which case we default to ~/Videos. +bool GetUserVideosDirectory(FilePath* result) { + return GetUserMediaDirectory("VIDEOS", kVideosDir, result); } bool GetUserDesktop(FilePath* result) { diff --git a/chrome/common/chrome_paths_mac.mm b/chrome/common/chrome_paths_mac.mm index 7745be8..f933796 100644 --- a/chrome/common/chrome_paths_mac.mm +++ b/chrome/common/chrome_paths_mac.mm @@ -135,10 +135,18 @@ bool GetUserDownloadsDirectory(FilePath* result) { return base::mac::GetUserDirectory(NSDownloadsDirectory, result); } +bool GetUserMusicDirectory(FilePath* result) { + return base::mac::GetUserDirectory(NSMusicDirectory, result); +} + bool GetUserPicturesDirectory(FilePath* result) { return base::mac::GetUserDirectory(NSPicturesDirectory, result); } +bool GetUserVideosDirectory(FilePath* result) { + return base::mac::GetUserDirectory(NSMoviesDirectory, result); +} + bool GetUserDesktop(FilePath* result) { return base::mac::GetUserDirectory(NSDesktopDirectory, result); } diff --git a/chrome/common/chrome_paths_win.cc b/chrome/common/chrome_paths_win.cc index 7d009d0..c4a03c7 100644 --- a/chrome/common/chrome_paths_win.cc +++ b/chrome/common/chrome_paths_win.cc @@ -45,6 +45,23 @@ bool GetUserDataDirectoryForEnvironment(bool current, FilePath* result) { return true; } +// Generic function to call SHGetFolderPath(). +bool GetUserDirectory(int csidl_folder, FilePath* result) { + // We need to go compute the value. It would be nice to support paths + // with names longer than MAX_PATH, but the system functions don't seem + // to be designed for it either, with the exception of GetTempPath + // (but other things will surely break if the temp path is too long, + // so we don't bother handling it. + wchar_t path_buf[MAX_PATH]; + path_buf[0] = 0; + if (FAILED(SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, + SHGFP_TYPE_CURRENT, path_buf))) { + return false; + } + *result = FilePath(path_buf); + return true; +} + } // namespace bool GetDefaultUserDataDirectory(FilePath* result) { @@ -71,12 +88,7 @@ void GetUserCacheDirectory(const FilePath& profile_dir, FilePath* result) { } bool GetUserDocumentsDirectory(FilePath* result) { - wchar_t path_buf[MAX_PATH]; - if (FAILED(SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, - SHGFP_TYPE_CURRENT, path_buf))) - return false; - *result = FilePath(path_buf); - return true; + return GetUserDirectory(CSIDL_MYDOCUMENTS, result); } // Return a default path for downloads that is safe. @@ -107,30 +119,20 @@ bool GetUserDownloadsDirectory(FilePath* result) { return GetUserDownloadsDirectorySafe(result); } +bool GetUserMusicDirectory(FilePath* result) { + return GetUserDirectory(CSIDL_MYMUSIC, result); +} + bool GetUserPicturesDirectory(FilePath* result) { - wchar_t path_buf[MAX_PATH]; - if (FAILED(SHGetFolderPath(NULL, CSIDL_MYPICTURES, NULL, - SHGFP_TYPE_CURRENT, path_buf))) { - return false; - } - *result = FilePath(path_buf); - return true; + return GetUserDirectory(CSIDL_MYPICTURES, result); +} + +bool GetUserVideosDirectory(FilePath* result) { + return GetUserDirectory(CSIDL_MYVIDEO, result); } bool GetUserDesktop(FilePath* result) { - // We need to go compute the value. It would be nice to support paths - // with names longer than MAX_PATH, but the system functions don't seem - // to be designed for it either, with the exception of GetTempPath - // (but other things will surely break if the temp path is too long, - // so we don't bother handling it. - wchar_t system_buffer[MAX_PATH]; - system_buffer[0] = 0; - if (FAILED(SHGetFolderPath(NULL, CSIDL_DESKTOPDIRECTORY, NULL, - SHGFP_TYPE_CURRENT, system_buffer))) { - return false; - } - *result = FilePath(system_buffer); - return true; + return GetUserDirectory(CSIDL_DESKTOPDIRECTORY, result); } bool ProcessNeedsProfileDir(const std::string& process_type) { |