diff options
author | beng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-19 07:24:12 +0000 |
---|---|---|
committer | beng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-19 07:24:12 +0000 |
commit | 905a08d1f74eced28716bb082e8f0bc08e2136e1 (patch) | |
tree | f64607304183aa7337f9ed3e629e526eba89e818 /chrome/browser | |
parent | 85c1d8296cfe9e184bc2890e169bd2f770fb5c63 (diff) | |
download | chromium_src-905a08d1f74eced28716bb082e8f0bc08e2136e1.zip chromium_src-905a08d1f74eced28716bb082e8f0bc08e2136e1.tar.gz chromium_src-905a08d1f74eced28716bb082e8f0bc08e2136e1.tar.bz2 |
Change by Alex Mendes da Costa <alexmdac@google.com>
Use the most recently used download path when displaying a "save as" dialog. Reset the download path when the user clears the download history.
BUG=293 (http://code.google.com/p/chromium/issues/detail?id=293)
Review URL: http://codereview.chromium.org/10743
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5674 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browsing_data_remover.cc | 1 | ||||
-rw-r--r-- | chrome/browser/download/download_manager.cc | 24 | ||||
-rw-r--r-- | chrome/browser/download/download_manager.h | 7 |
3 files changed, 28 insertions, 4 deletions
diff --git a/chrome/browser/browsing_data_remover.cc b/chrome/browser/browsing_data_remover.cc index cfb5f9c..41aa9ae 100644 --- a/chrome/browser/browsing_data_remover.cc +++ b/chrome/browser/browsing_data_remover.cc @@ -90,6 +90,7 @@ void BrowsingDataRemover::Remove(int remove_mask) { UserMetrics::RecordAction(L"ClearBrowsingData_Downloads", profile_); DownloadManager* download_manager = profile_->GetDownloadManager(); download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_); + download_manager->ClearLastDownloadPath(); } if (remove_mask & REMOVE_COOKIES) { diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc index ec6aa37..6780581 100644 --- a/chrome/browser/download/download_manager.cc +++ b/chrome/browser/download/download_manager.cc @@ -398,6 +398,17 @@ void DownloadManager::Shutdown() { shutdown_needed_ = false; } +// Determines whether the "save as" dialog should be displayed to the user +// when downloading a file. +bool DownloadManager::ShouldDisplaySaveAsDialog( + const DownloadCreateInfo* info) { + return + *prompt_for_download_ || // User always wants a prompt. + info->save_as || // "Save as ..." operation. + info->path_uniquifier == -1; // Last attempt to generate a unique file + // name failed. +} + // Issue a history query for downloads matching 'search_text'. If 'search_text' // is empty, return all downloads that we know about. void DownloadManager::GetDownloads(Observer* observer, @@ -523,14 +534,14 @@ void DownloadManager::StartDownload(DownloadCreateInfo* info) { // download directory, or prompting the user. std::wstring generated_name; GenerateFilename(info, &generated_name); - if (*prompt_for_download_ && !last_download_path_.empty()) + if (ShouldDisplaySaveAsDialog(info) && !last_download_path_.empty()) info->suggested_path = last_download_path_; else info->suggested_path = *download_path_; file_util::AppendToPath(&info->suggested_path, generated_name); // Let's check if this download is dangerous, based on its name. - if (!*prompt_for_download_ && !info->save_as) { + if (!ShouldDisplaySaveAsDialog(info)) { const std::wstring filename = file_util::GetFilenameFromPath(info->suggested_path); info->is_dangerous = IsDangerous(filename); @@ -597,7 +608,7 @@ void DownloadManager::OnPathExistenceAvailable(DownloadCreateInfo* info) { DCHECK(MessageLoop::current() == ui_loop_); DCHECK(info); - if (*prompt_for_download_ || info->save_as || info->path_uniquifier == -1) { + if (ShouldDisplaySaveAsDialog(info)) { // We must ask the user for the place to put the download. if (!select_file_dialog_.get()) select_file_dialog_ = SelectFileDialog::Create(this); @@ -1210,7 +1221,7 @@ void DownloadManager::SaveAutoOpens() { void DownloadManager::FileSelected(const std::wstring& path, void* params) { DownloadCreateInfo* info = reinterpret_cast<DownloadCreateInfo*>(params); - if (*prompt_for_download_) + if (ShouldDisplaySaveAsDialog(info)) last_download_path_ = file_util::GetDirectoryFromPath(path); ContinueStartDownload(info, path); } @@ -1334,3 +1345,8 @@ void DownloadManager::OnSearchComplete(HistoryService::Handle handle, requestor->SetDownloads(searched_downloads); } + +// Clears the last download path, used to initialize "save as" dialogs. +void DownloadManager::ClearLastDownloadPath() { + last_download_path_.clear(); +} diff --git a/chrome/browser/download/download_manager.h b/chrome/browser/download/download_manager.h index 38cc044..63e1e4c 100644 --- a/chrome/browser/download/download_manager.h +++ b/chrome/browser/download/download_manager.h @@ -366,6 +366,9 @@ class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>, std::wstring download_path() { return *download_path_; } + // Clears the last download path, used to initialize "save as" dialogs. + void ClearLastDownloadPath(); + // Registers this file extension for automatic opening upon download // completion if 'open' is true, or prevents the extension from automatic // opening if 'open' is false. @@ -401,6 +404,10 @@ class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>, // Shutdown the download manager. This call is needed only after Init. void Shutdown(); + // Determines whether the "save as" dialog should be displayed to the user + // when downloading a file. + bool ShouldDisplaySaveAsDialog(const DownloadCreateInfo* info); + // Called on the download thread to check whether the suggested file path // exists. We don't check if the file exists on the UI thread to avoid UI // stalls from interacting with the file system. |