diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-24 22:42:05 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-24 22:42:05 +0000 |
commit | 2b2f8f72f90cf73a432978b7f42f2abaae9112da (patch) | |
tree | 82fb9e5d6fd6dadc75d88bd9f231d583e8be63f4 /chrome | |
parent | d3fc2565089f8471ddc4eaae1b0bd78d40981547 (diff) | |
download | chromium_src-2b2f8f72f90cf73a432978b7f42f2abaae9112da.zip chromium_src-2b2f8f72f90cf73a432978b7f42f2abaae9112da.tar.gz chromium_src-2b2f8f72f90cf73a432978b7f42f2abaae9112da.tar.bz2 |
Final step needed to get be able to download things on linux.
There's still no UI though.
Review URL: http://codereview.chromium.org/27097
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10299 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/download/download_manager.cc | 26 | ||||
-rw-r--r-- | chrome/common/chrome_paths.cc | 7 | ||||
-rw-r--r-- | chrome/common/chrome_paths_linux.cc | 50 |
3 files changed, 50 insertions, 33 deletions
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc index 7db3d54..aafb641 100644 --- a/chrome/browser/download/download_manager.cc +++ b/chrome/browser/download/download_manager.cc @@ -92,7 +92,8 @@ static int GetUniquePathNumber(const FilePath& path) { return -1; } -#if defined(OS_WIN) +// TODO(port): enable this for mac later. For now, it gives a not used warning. +#if defined(OS_WIN) || defined(OS_LINUX) static bool DownloadPathIsDangerous(const FilePath& download_path) { FilePath desktop_dir; if (!PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_dir)) { @@ -298,8 +299,8 @@ void DownloadManager::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterStringPref(prefs::kDownloadExtensionsToOpen, L""); prefs->RegisterBooleanPref(prefs::kDownloadDirUpgraded, false); -// TODO(port): port the necessary bits of chrome_paths. -#if defined(OS_WIN) +// TODO(port): port the necessary bits of chrome_paths_mac. +#if defined(OS_WIN) || defined(OS_LINUX) // The default download path is userprofile\download. FilePath default_download_path; if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, @@ -322,7 +323,7 @@ void DownloadManager::RegisterUserPrefs(PrefService* prefs) { } prefs->SetBoolean(prefs::kDownloadDirUpgraded, true); } -#endif +#endif // defined(OS_WIN) || defined(OS_LINUX) } DownloadManager::DownloadManager() @@ -485,8 +486,8 @@ bool DownloadManager::Init(Profile* profile) { DCHECK(prefs); prompt_for_download_.Init(prefs::kPromptForDownload, prefs, NULL); -// TODO(port): enable this after implementing chrome_paths for posix. -#if defined(OS_WIN) +// TODO(port): enable this after implementing chrome_paths for mac. +#if defined(OS_WIN) || defined(OS_LINUX) download_path_.Init(prefs::kDownloadDefaultDirectory, prefs, NULL); // This variable is needed to resolve which CreateDirectory we want to point @@ -497,14 +498,17 @@ bool DownloadManager::Init(Profile* profile) { // Ensure that the download directory specified in the preferences exists. file_loop_->PostTask(FROM_HERE, NewRunnableFunction( CreateDirectoryPtr, download_path())); +#elif defined(OS_MACOSX) + NOTIMPLEMENTED(); +#endif - // We store any file extension that should be opened automatically at - // download completion in this pref. +#if defined(OS_WIN) + // We use this on windows to determine possibly dangerous downloads. download_util::InitializeExeTypes(&exe_types_); -#elif defined(OS_POSIX) - NOTIMPLEMENTED(); #endif + // We store any file extension that should be opened automatically at + // download completion in this pref. std::wstring extensions_to_open = prefs->GetString(prefs::kDownloadExtensionsToOpen); std::vector<std::wstring> extensions; @@ -1334,10 +1338,10 @@ void DownloadManager::GenerateSafeFilename(const std::string& mime_type, GenerateExtension(*file_name, mime_type, &extension); file_util::ReplaceExtension(file_name, extension); +#if defined(OS_WIN) // Prepend "_" to the file name if it's a reserved name FilePath::StringType leaf_name = file_name->BaseName().value(); DCHECK(!leaf_name.empty()); -#if defined(OS_WIN) if (win_util::IsReservedName(leaf_name)) { leaf_name = FilePath::StringType(FILE_PATH_LITERAL("_")) + leaf_name; *file_name = file_name->DirName(); diff --git a/chrome/common/chrome_paths.cc b/chrome/common/chrome_paths.cc index c3c542d..0c16079 100644 --- a/chrome/common/chrome_paths.cc +++ b/chrome/common/chrome_paths.cc @@ -72,9 +72,10 @@ bool PathProvider(int key, FilePath* result) { if (!PathService::Get(chrome::DIR_USER_DOCUMENTS, &cur)) return false; cur = cur.Append(FILE_PATH_LITERAL("Downloads")); - // TODO(port): This will fail on other platforms unless we - // implement DIR_USER_DOCUMENTS or use xdg-user-dirs to - // get the download directory independently of DIR_USER_DOCUMENTS. + // TODO(port): this may not be what we want on other platforms. But it + // is not clear what we would prefer: $XDG_DOWNLOAD_DIR appears to point + // to ~/Downloads for many users, which is something we want to avoid. + // We probably need to add a GetUserDownloadsDirectory(). break; case chrome::DIR_CRASH_DUMPS: // The crash reports are always stored relative to the default user data diff --git a/chrome/common/chrome_paths_linux.cc b/chrome/common/chrome_paths_linux.cc index cde9949..f416710 100644 --- a/chrome/common/chrome_paths_linux.cc +++ b/chrome/common/chrome_paths_linux.cc @@ -8,6 +8,32 @@ #include "base/file_path.h" #include "base/logging.h" +namespace { + +// |env_name| is the name of an environment variable that we want to use to get +// a directory path. |fallback_dir| is the directory relative to $HOME that we +// use if |env_name| cannot be found or is empty. |fallback_dir| may be NULL. +// TODO(thestig): Don't use g_getenv() here because most of the time XDG +// environment variables won't actually be loaded. +FilePath GetStandardDirectory(const char* env_name, const char* fallback_dir) { + FilePath rv; + const char* env_value = g_getenv(env_name); + if (env_value && env_value[0]) { + rv = FilePath(env_value); + } else { + const char* home_dir = g_getenv("HOME"); + if (!home_dir) + home_dir = g_get_home_dir(); + rv = FilePath(home_dir); + if (fallback_dir) + rv = rv.Append(fallback_dir); + } + + return rv; +} + +} // namespace + namespace chrome { // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html @@ -16,17 +42,7 @@ namespace chrome { // ~/.config/google-chrome/ for official builds. // (This also helps us sidestep issues with other apps grabbing ~/.chromium .) bool GetDefaultUserDataDirectory(FilePath* result) { - FilePath config_dir; - const char* config_home = g_getenv("XDG_CONFIG_HOME"); - if (config_home && config_home[0]) { - config_dir = FilePath(config_home); - } else { - const char* home_dir = g_getenv("HOME"); - if (!home_dir) - home_dir = g_get_home_dir(); - config_dir = FilePath(home_dir).Append(".config"); - } - + FilePath config_dir = GetStandardDirectory("XDG_CONFIG_HOME", ".config"); #if defined(GOOGLE_CHROME_BUILD) *result = config_dir.Append("google-chrome"); #else @@ -36,17 +52,13 @@ bool GetDefaultUserDataDirectory(FilePath* result) { } bool GetUserDocumentsDirectory(FilePath* result) { - // TODO(port): Get the path (possibly using xdg-user-dirs) - // or decide we don't need it on other platforms. - NOTIMPLEMENTED(); - return false; + *result = GetStandardDirectory("XDG_DOCUMENTS_DIR", "Documents"); + return true; } bool GetUserDesktop(FilePath* result) { - // TODO(port): Get the path (possibly using xdg-user-dirs) - // or decide we don't need it on other platforms. - NOTIMPLEMENTED(); - return false; + *result = GetStandardDirectory("XDG_DESKTOP_DIR", "Desktop"); + return true; } } // namespace chrome |