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

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

Issue 6973052: When the download folder does not exist, change the download folder to a user's "Downloads" (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add ChooseSavableDirectory() and ScopedDefaultDownloadDirectory Created 9 years, 6 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
Index: chrome/browser/download/save_package.cc
diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc
index 81bdfcfdfe5a2dd5d252165196836d0e304fa532..64381f3061399518ea4924ee2e5ab67eabe14314 100644
--- a/chrome/browser/download/save_package.cc
+++ b/chrome/browser/download/save_package.cc
@@ -1256,6 +1256,8 @@ FilePath SavePackage::GetSaveDirPreference(PrefService* prefs) {
}
void SavePackage::GetSaveInfo() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
// Can't use tab_contents_ in the file thread, so get the data that we need
// before calling to it.
PrefService* prefs = tab_contents()->profile()->GetPrefs();
@@ -1267,24 +1269,22 @@ void SavePackage::GetSaveInfo() {
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
NewRunnableMethod(this, &SavePackage::CreateDirectoryOnFileThread,
- website_save_dir, download_save_dir, mime_type));
+ website_save_dir, download_save_dir, mime_type));
}
void SavePackage::CreateDirectoryOnFileThread(
const FilePath& website_save_dir,
const FilePath& download_save_dir,
const std::string& mime_type) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+
+ FilePath default_downloads_dir =
+ download_util::DefaultDownloadDirectory::Get();
Randy Smith (Not in Mondays) 2011/06/10 20:58:53 (Reference to other comment.) This is the current
haraken1 2011/06/14 11:10:05 Done.
FilePath save_dir;
- // If the default html/websites save folder doesn't exist...
- if (!file_util::DirectoryExists(website_save_dir)) {
- // If the default download dir doesn't exist, create it.
- if (!file_util::DirectoryExists(download_save_dir))
- file_util::CreateDirectory(download_save_dir);
- save_dir = download_save_dir;
- } else {
- // If it does exist, use the default save dir param.
- save_dir = website_save_dir;
- }
+ // Ignores the returned value since the select file dialog should be
+ // displayed in any case.
+ download_util::ChooseSavableDirectory(
+ website_save_dir, download_save_dir, default_downloads_dir, &save_dir);
bool can_save_as_complete = CanSaveAsComplete(mime_type);
FilePath suggested_filename = GetSuggestedNameForSaveAs(can_save_as_complete,
@@ -1314,6 +1314,8 @@ void SavePackage::CreateDirectoryOnFileThread(
void SavePackage::ContinueGetSaveInfo(const FilePath& suggested_path,
bool can_save_as_complete) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
// The TabContents which owns this SavePackage may have disappeared during
// the UI->FILE->UI thread hop of
// GetSaveInfo->CreateDirectoryOnFileThread->ContinueGetSaveInfo.
@@ -1403,6 +1405,8 @@ void SavePackage::ContinueGetSaveInfo(const FilePath& suggested_path,
// Called after the save file dialog box returns.
void SavePackage::ContinueSave(const FilePath& final_name,
int index) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
// Ensure the filename is safe.
saved_main_file_path_ = final_name;
download_util::GenerateSafeFileName(tab_contents()->contents_mime_type(),

Powered by Google App Engine
This is Rietveld 408576698