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

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

Issue 219017: Create the download folder if it doesn't exist. That is, the actual download ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix unit tests Created 11 years, 3 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/save_package.h ('k') | chrome/common/chrome_paths.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/download/save_package.cc
===================================================================
--- chrome/browser/download/save_package.cc (revision 27115)
+++ chrome/browser/download/save_package.cc (working copy)
@@ -144,6 +144,7 @@
saved_main_file_path_.value().length() <= kMaxFilePathLength);
DCHECK(!saved_main_directory_path_.empty() &&
saved_main_directory_path_.value().length() < kMaxFilePathLength);
+ InternalInit();
}
SavePackage::SavePackage(TabContents* tab_contents)
@@ -160,10 +161,12 @@
const GURL& current_page_url = tab_contents_->GetURL();
DCHECK(current_page_url.is_valid());
page_url_ = current_page_url;
+ InternalInit();
}
// This is for testing use. Set |finished_| as true because we don't want
// method Cancel to be be called in destructor in test mode.
+// We also don't call InternalInit().
SavePackage::SavePackage(const FilePath& file_full_path,
const FilePath& directory_full_path)
: file_manager_(NULL),
@@ -231,6 +234,22 @@
}
}
+// Init() can be called directly, or indirectly via GetSaveInfo(). In both
+// cases, we need file_manager_ to be initialized, so we do this first.
+void SavePackage::InternalInit() {
+ ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host();
+ if (!rdh) {
+ NOTREACHED();
+ return;
+ }
+
+ file_manager_ = rdh->save_file_manager();
+ if (!file_manager_) {
+ NOTREACHED();
+ return;
+ }
+}
+
// Initialize the SavePackage.
bool SavePackage::Init() {
// Set proper running state.
@@ -248,18 +267,6 @@
request_context_ = profile->GetRequestContext();
- ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host();
- if (!rdh) {
- NOTREACHED();
- return false;
- }
-
- file_manager_ = rdh->save_file_manager();
- if (!file_manager_) {
- NOTREACHED();
- return false;
- }
-
// Create the fake DownloadItem and display the view.
download_ = new DownloadItem(1, saved_main_file_path_, 0, page_url_, GURL(),
"", FilePath(), Time::Now(), 0, -1, -1, false, false);
@@ -1044,6 +1051,17 @@
}
void SavePackage::GetSaveInfo() {
+ FilePath save_dir =
+ GetSaveDirPreference(tab_contents_->profile()->GetPrefs());
+ file_manager_->file_loop()->PostTask(FROM_HERE,
+ NewRunnableMethod(file_manager_,
+ &SaveFileManager::CreateDownloadDirectory,
+ save_dir,
+ this));
+ // CreateDownloadDirectory() calls ContinueGetSaveInfo() below.
+}
+
+void SavePackage::ContinueGetSaveInfo(FilePath save_dir) {
// Use "Web Page, Complete" option as default choice of saving page.
int file_type_index = 2;
SelectFileDialog::FileTypeInfo file_type_info;
@@ -1057,8 +1075,6 @@
FilePath title =
FilePath::FromWStringHack(UTF16ToWideHack(tab_contents_->GetTitle()));
- FilePath save_dir =
- GetSaveDirPreference(tab_contents_->profile()->GetPrefs());
FilePath suggested_path =
save_dir.Append(GetSuggestedNameForSaveAs(title, can_save_as_complete));
« no previous file with comments | « chrome/browser/download/save_package.h ('k') | chrome/common/chrome_paths.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698