Commit a87c920b authored by thestig@chromium.org's avatar thestig@chromium.org

Add PathService::Get(chrome::DIR_USER_PICTURES).

BUG=none
TEST=none

Review URL: https://chromiumcodereview.appspot.com/10392094

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137596 0039d316-1c4b-4281-b951-d872f2087c98
parent 4266def2
......@@ -4,7 +4,6 @@
#include "chrome/common/chrome_paths.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/mac/bundle_locations.h"
......@@ -14,7 +13,6 @@
#include "base/version.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/chrome_switches.h"
#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
......@@ -155,6 +153,10 @@ bool PathProvider(int key, FilePath* result) {
return false;
create_dir = true;
break;
case chrome::DIR_USER_PICTURES:
if (!GetUserPicturesDirectory(&cur))
return false;
break;
case chrome::DIR_DEFAULT_DOWNLOADS_SAFE:
#if defined(OS_WIN) || defined(OS_LINUX)
if (!GetUserDownloadsDirectorySafe(&cur))
......
......@@ -26,6 +26,7 @@ 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_PICTURES, // Directory for a user's pictures.
DIR_DEFAULT_DOWNLOADS_SAFE, // Directory for a user's
// "My Documents/Downloads", (Windows) or
// "Downloads". (Linux)
......
......@@ -33,6 +33,11 @@ bool GetUserDownloadsDirectory(FilePath* result) {
return true;
}
bool GetUserPicturesDirectory(FilePath* result) {
NOTIMPLEMENTED();
return false;
}
bool GetUserDesktop(FilePath* result) {
NOTIMPLEMENTED() << "Android doesn't support GetUserDesktop";
return false;
......
......@@ -51,6 +51,9 @@ bool GetUserDownloadsDirectorySafe(FilePath* result);
// Get the path to the user's downloads directory.
bool GetUserDownloadsDirectory(FilePath* result);
// Gets the path to the user's pictures directory.
bool GetUserPicturesDirectory(FilePath* result);
// The path to the user's desktop.
bool GetUserDesktop(FilePath* result);
......
......@@ -7,13 +7,14 @@
#include "base/environment.h"
#include "base/file_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/path_service.h"
#include "base/nix/xdg_util.h"
#include "base/path_service.h"
namespace {
const char kDotConfigDir[] = ".config";
const char kDownloadsDir[] = "Downloads";
const char kPicturesDir[] = "Pictures";
const char kXdgConfigHomeEnvVar[] = "XDG_CONFIG_HOME";
} // namespace
......@@ -97,6 +98,25 @@ bool GetUserDownloadsDirectory(FilePath* result) {
return true;
}
// 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) {
scoped_ptr<base::Environment> env(base::Environment::Create());
*result = base::nix::GetXDGUserDirectory(env.get(), "PICTURES", kPicturesDir);
FilePath home = file_util::GetHomeDir();
if (*result != home) {
FilePath desktop;
GetUserDesktop(&desktop);
if (*result != desktop) {
return true;
}
}
*result = home.Append(kPicturesDir);
return true;
}
bool GetUserDesktop(FilePath* result) {
scoped_ptr<base::Environment> env(base::Environment::Create());
*result = base::nix::GetXDGUserDirectory(env.get(), "DESKTOP", "Desktop");
......
......@@ -19,6 +19,12 @@
namespace {
// TODO(thestig) Remove this once we switch to the 10.6 SDK.
#if !defined(MAC_OS_X_VERSION_10_6) || \
MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
#define NSPicturesDirectory 19
#endif
const FilePath* g_override_versioned_directory = NULL;
// Return a retained (NOT autoreleased) NSBundle* as the internal
......@@ -135,6 +141,10 @@ bool GetUserDownloadsDirectory(FilePath* result) {
return base::mac::GetUserDirectory(NSDownloadsDirectory, result);
}
bool GetUserPicturesDirectory(FilePath* result) {
return base::mac::GetUserDirectory(NSPicturesDirectory, result);
}
bool GetUserDesktop(FilePath* result) {
return base::mac::GetUserDirectory(NSDesktopDirectory, result);
}
......
......@@ -11,8 +11,8 @@
#include <shobjidl.h>
#include "base/file_path.h"
#include "base/win/metro.h"
#include "base/path_service.h"
#include "base/win/metro.h"
#include "base/win/scoped_co_mem.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/installer/util/browser_distribution.h"
......@@ -83,6 +83,16 @@ bool GetUserDownloadsDirectory(FilePath* result) {
return GetUserDownloadsDirectorySafe(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;
}
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
......@@ -92,8 +102,9 @@ bool GetUserDesktop(FilePath* result) {
wchar_t system_buffer[MAX_PATH];
system_buffer[0] = 0;
if (FAILED(SHGetFolderPath(NULL, CSIDL_DESKTOPDIRECTORY, NULL,
SHGFP_TYPE_CURRENT, system_buffer)))
SHGFP_TYPE_CURRENT, system_buffer))) {
return false;
}
*result = FilePath(system_buffer);
return true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment