Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(971)

Unified Diff: chrome/browser/download/download_manager.cc

Issue 7324031: Revert 91861 - When the download folder does not exist, change the download folder to a user's "D... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/download/download_manager.h ('k') | chrome/browser/download/download_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/download/download_manager.cc
===================================================================
--- chrome/browser/download/download_manager.cc (revision 91868)
+++ chrome/browser/download/download_manager.cc (working copy)
@@ -8,6 +8,7 @@
#include "base/file_util.h"
#include "base/i18n/case_conversion.h"
#include "base/logging.h"
+#include "base/path_service.h"
#include "base/rand_util.h"
#include "base/stl_util-inl.h"
#include "base/stringprintf.h"
@@ -409,23 +410,30 @@
download_prefs()->download_path()));
}
-void DownloadManager::CheckIfSuggestedPathExists(
- int32 download_id,
- DownloadStateInfo state,
- const FilePath& download_save_dir) {
+void DownloadManager::CheckIfSuggestedPathExists(int32 download_id,
+ DownloadStateInfo state,
+ const FilePath& default_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- FilePath default_download_dir =
- download_util::GetDefaultDownloadDirectoryFromPathService();
- FilePath save_dir;
- if (download_util::ChooseSavableDirectory(
- FilePath(), download_save_dir, default_download_dir, &save_dir))
+ // Make sure the default download directory exists.
+ // TODO(phajdan.jr): only create the directory when we're sure the user
+ // is going to save there and not to another directory of his choice.
+ file_util::CreateDirectory(default_path);
+
+ // Check writability of the suggested path. If we can't write to it, default
+ // to the user's "My Documents" directory. We'll prompt them in this case.
+ FilePath dir = state.suggested_path.DirName();
+ FilePath filename = state.suggested_path.BaseName();
+ if (!file_util::PathIsWritable(dir)) {
+ VLOG(1) << "Unable to write to directory \"" << dir.value() << "\"";
state.prompt_user_for_save_location = true;
- state.suggested_path = save_dir.Append(state.suggested_path.BaseName());
+ PathService::Get(chrome::DIR_USER_DOCUMENTS, &state.suggested_path);
+ state.suggested_path = state.suggested_path.Append(filename);
+ }
// If the download is deemed dangerous, we'll use a temporary name for it.
if (state.IsDangerous()) {
- state.target_name = state.suggested_path.BaseName();
+ state.target_name = FilePath(state.suggested_path).BaseName();
// Create a temporary file to hold the file until the user approves its
// download.
FilePath::StringType file_name;
@@ -444,7 +452,7 @@
unconfirmed_prefix.append(
FILE_PATH_LITERAL(" %d.crdownload")).c_str(),
base::RandInt(0, 100000));
- path = state.suggested_path.DirName().Append(file_name);
+ path = dir.Append(file_name);
if (file_util::PathExists(path))
path = FilePath();
}
@@ -534,7 +542,7 @@
contents, owning_window,
reinterpret_cast<void*>(id_ptr));
FOR_EACH_OBSERVER(Observer, observers_,
- SelectFileDialogDisplayed(download_id, suggested_path));
+ SelectFileDialogDisplayed(download_id));
} else {
// No prompting for download, just continue with the suggested name.
ContinueDownloadWithPath(download, suggested_path);
« no previous file with comments | « chrome/browser/download/download_manager.h ('k') | chrome/browser/download/download_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698