diff options
author | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-01 19:25:40 +0000 |
---|---|---|
committer | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-01 19:25:40 +0000 |
commit | 916afa33c243834cb699ff3f826e8a1d689818c3 (patch) | |
tree | 641aa58211c5b4b2e2126e0d05785d83b1649243 /chrome/browser/download/save_package.cc | |
parent | ccb7d64aac531208d66f0531e51f3865afd00445 (diff) | |
download | chromium_src-916afa33c243834cb699ff3f826e8a1d689818c3.zip chromium_src-916afa33c243834cb699ff3f826e8a1d689818c3.tar.gz chromium_src-916afa33c243834cb699ff3f826e8a1d689818c3.tar.bz2 |
Added a check to see if the SaveFileDefaultDirectory exists, if not it uses the DownloadDefaultDirectory instead.
Contributed by pnettleship@gmail.com
BUG=47561
TEST=Create folder, save html page into folder, delete folder, resave page. If the deleted folder is not re-created automatically, and you are defaulting to the default download di then it worked.
Review URL: http://codereview.chromium.org/3449022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61214 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download/save_package.cc')
-rw-r--r-- | chrome/browser/download/save_package.cc | 53 |
1 files changed, 35 insertions, 18 deletions
diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc index f624e44..4ce3e36 100644 --- a/chrome/browser/download/save_package.cc +++ b/chrome/browser/download/save_package.cc @@ -183,26 +183,42 @@ bool GetSafePureFileName(const FilePath& dir_path, return false; } -// This task creates a directory and then posts a task on the given thread. +// This task creates a directory (if needed) and then posts a task on the given +// thread. class CreateDownloadDirectoryTask : public Task { public: - CreateDownloadDirectoryTask(const FilePath& save_dir, - Task* follow_up, - MessageLoop* target_thread) - : save_dir_(save_dir), - follow_up_(follow_up), - target_thread_(target_thread) { + CreateDownloadDirectoryTask(SavePackage* save_package, + const FilePath& default_save_file_dir, + const FilePath& default_download_dir) + : save_package_(save_package), + default_save_file_dir_(default_save_file_dir), + default_download_dir_(default_download_dir){ } virtual void Run() { - file_util::CreateDirectory(save_dir_); - target_thread_->PostTask(FROM_HERE, follow_up_); + // If the default html/websites save folder doesn't exist... + if (!file_util::DirectoryExists(default_save_file_dir_)) { + // If the default download dir doesn't exist, create it. + if (!file_util::DirectoryExists(default_download_dir_)) + file_util::CreateDirectory(default_download_dir_); + + ChromeThread::PostTask(ChromeThread::UI, FROM_HERE, + NewRunnableMethod(save_package_, + &SavePackage::ContinueGetSaveInfo, + default_download_dir_)); + } else { + // If it does exist, use the default save dir param. + ChromeThread::PostTask(ChromeThread::UI, FROM_HERE, + NewRunnableMethod(save_package_, + &SavePackage::ContinueGetSaveInfo, + default_save_file_dir_)); + } } private: - FilePath save_dir_; - Task* follow_up_; - MessageLoop* target_thread_; + SavePackage* save_package_; + FilePath default_save_file_dir_; + FilePath default_download_dir_; DISALLOW_COPY_AND_ASSIGN(CreateDownloadDirectoryTask); }; @@ -1219,15 +1235,16 @@ FilePath SavePackage::GetSaveDirPreference(PrefService* prefs) { } void SavePackage::GetSaveInfo() { - FilePath save_dir = - GetSaveDirPreference(tab_contents_->profile()->GetPrefs()); + PrefService* prefs = tab_contents_->profile()->GetPrefs(); + FilePath website_save_dir = GetSaveDirPreference(prefs); + FilePath download_save_dir = prefs->GetFilePath( + prefs::kDownloadDefaultDirectory); ChromeThread::PostTask( ChromeThread::FILE, FROM_HERE, - new CreateDownloadDirectoryTask(save_dir, - method_factory_.NewRunnableMethod( - &SavePackage::ContinueGetSaveInfo, save_dir), - MessageLoop::current())); + new CreateDownloadDirectoryTask(this, + website_save_dir, + download_save_dir)); // CreateDownloadDirectoryTask calls ContinueGetSaveInfo() below. } |