Skip to content

Commit

Permalink
Added a check to see if the SaveFileDefaultDirectory exists, if not i…
Browse files Browse the repository at this point in the history
…t 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
  • Loading branch information
tony@chromium.org committed Oct 1, 2010
1 parent ccb7d64 commit 916afa3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ James Willcox <jwillcox@litl.com>
Shreyas VA <v.a.shreyas@gmail.com>
Steven Pennington <spenn@engr.uvic.ca>
Jorge Villatoro <jorge@tomatocannon.com>
Paul Nettleship <pnettleship@gmail.com>
53 changes: 35 additions & 18 deletions chrome/browser/download/save_package.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down Expand Up @@ -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.
}

Expand Down

0 comments on commit 916afa3

Please sign in to comment.