summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-15 23:42:21 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-15 23:42:21 +0000
commit834c8e169509ad7e29e924194b4d0d7f0c19d3a2 (patch)
tree2a8e1eba3c22ac081210d85aa9722ae007d25e1f
parente7d8daa2364d2b2d25609704b857243225527a4f (diff)
downloadchromium_src-834c8e169509ad7e29e924194b4d0d7f0c19d3a2.zip
chromium_src-834c8e169509ad7e29e924194b4d0d7f0c19d3a2.tar.gz
chromium_src-834c8e169509ad7e29e924194b4d0d7f0c19d3a2.tar.bz2
chromeos: Do not peek at /home/chronos/user/Downloads
Use $HOME/Downloads if running on Linux desktop. Note that gspencer@ tried to solve this problem in a cleaner way: http://codereview.chromium.org/9455073/ However his patch didn't work. I patched it locally, but mount points like /media/removable didn't show up in the file manager, and the renderer crashed when I clicked on the "Open downloads folder" in chrome://downloads, as he warned me beforehand. Hence I decided to go with a simpler approach in this patch. BUG=chromium-os:27859 TEST=confirm that contents in ~/Downloads are shown in the file browser on Linux desktop Review URL: https://chromiumcodereview.appspot.com/9700077 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127030 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--webkit/chromeos/fileapi/cros_mount_point_provider.cc55
1 files changed, 28 insertions, 27 deletions
diff --git a/webkit/chromeos/fileapi/cros_mount_point_provider.cc b/webkit/chromeos/fileapi/cros_mount_point_provider.cc
index 839a848..5004ed8 100644
--- a/webkit/chromeos/fileapi/cros_mount_point_provider.cc
+++ b/webkit/chromeos/fileapi/cros_mount_point_provider.cc
@@ -26,28 +26,31 @@ namespace {
const char kChromeUIScheme[] = "chrome";
-// Top level file system elements exposed in FileAPI in ChromeOS:
-// TODO(zelidrag): Move fixed mount path initialization out of webkit layer.
-struct LocalMountPointInfo {
- const char* const web_root_path;
- const char* const local_root_path;
- chromeos::CrosMountPointProvider::FileSystemLocation location;
-};
-
-const LocalMountPointInfo kFixedExposedPaths[] = {
- {"Downloads",
- "/home/chronos/user/",
- chromeos::CrosMountPointProvider::LOCAL},
- {"archive",
- "/media",
- chromeos::CrosMountPointProvider::LOCAL},
- {"removable",
- "/media",
- chromeos::CrosMountPointProvider::LOCAL},
-};
+// Copied from chrome/browser/chromeos/system/runtime_environment.h
+// TODO(satorux): oshima is now moving the function to 'base/chromeos'.
+// Use the one in 'base/chromeos' once it's done.
+bool IsRunningOnChromeOS() {
+ // Check if the user name is chronos. Note that we don't go with
+ // getuid() + getpwuid_r() as it may end up reading /etc/passwd, which
+ // can be expensive.
+ const char* user = getenv("USER");
+ return user && strcmp(user, "chronos") == 0;
+}
+
+// Returns the home directory path, or an empty string if the home directory
+// is not found.
+std::string GetHomeDirectory() {
+ if (IsRunningOnChromeOS())
+ return "/home/chronos/user";
+ const char* home = getenv("HOME");
+ if (home)
+ return home;
+ return "";
}
+} // namespace
+
namespace chromeos {
CrosMountPointProvider::MountPoint::MountPoint(
@@ -68,15 +71,13 @@ CrosMountPointProvider::CrosMountPointProvider(
file_access_permissions_(new FileAccessPermissions()),
local_file_util_(
new fileapi::LocalFileUtil(new fileapi::NativeFileUtil())) {
- for (size_t i = 0; i < arraysize(kFixedExposedPaths); i++) {
- mount_point_map_.insert(std::make_pair(
- std::string(kFixedExposedPaths[i].web_root_path),
- MountPoint(
- FilePath(std::string(kFixedExposedPaths[i].web_root_path)),
- FilePath(std::string(kFixedExposedPaths[i].local_root_path)),
- kFixedExposedPaths[i].location,
- NULL)));
+ const std::string home = GetHomeDirectory();
+ if (!home.empty()) {
+ AddLocalMountPoint(
+ FilePath::FromUTF8Unsafe(home).AppendASCII("Downloads"));
}
+ AddLocalMountPoint(FilePath(FILE_PATH_LITERAL("/media/archive")));
+ AddLocalMountPoint(FilePath(FILE_PATH_LITERAL("/media/removable")));
}
CrosMountPointProvider::~CrosMountPointProvider() {