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

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

Issue 2618743006: Use previous target path when resuming a download after crash (Closed)
Patch Set: move the target path logic into if(!is_forced_path) statement Created 3 years, 11 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 | « no previous file | chrome/browser/download/download_target_determiner_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/download/download_target_determiner.cc
diff --git a/chrome/browser/download/download_target_determiner.cc b/chrome/browser/download/download_target_determiner.cc
index f1d1845138c9e82acb617c042c178e5ba0136088..6b0b7c46a2217764bbb822ef831ef55618311cbe 100644
--- a/chrome/browser/download/download_target_determiner.cc
+++ b/chrome/browser/download/download_target_determiner.cc
@@ -201,44 +201,52 @@ DownloadTargetDeterminer::Result
// and reuse the selection.
should_prompt_ = ShouldPromptForDownload(virtual_path_);
} else if (!is_forced_path) {
- // If we don't have a forced path, we should construct a path for the
- // download. Forced paths are only specified for programmatic downloads
- // (WebStore, Drag&Drop). Treat the path as a virtual path. We will
- // eventually determine whether this is a local path and if not, figure out
- // a local path.
-
- std::string suggested_filename = download_->GetSuggestedFilename();
- if (suggested_filename.empty() &&
- download_->GetMimeType() == "application/x-x509-user-cert") {
- suggested_filename = "user.crt";
- }
-
- std::string default_filename(
- l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME));
- base::FilePath generated_filename = net::GenerateFileName(
- download_->GetURL(),
- download_->GetContentDisposition(),
- GetProfile()->GetPrefs()->GetString(prefs::kDefaultCharset),
- suggested_filename,
- download_->GetMimeType(),
- default_filename);
- should_prompt_ = ShouldPromptForDownload(generated_filename);
- base::FilePath target_directory;
- if (should_prompt_) {
- DCHECK(!download_prefs_->IsDownloadPathManaged());
- // If the user is going to be prompted and the user has been prompted
- // before, then always prefer the last directory that the user selected.
- target_directory = download_prefs_->SaveFilePath();
+ // If the download already has a target path, use it.
+ if (!download_->GetTargetFilePath().empty()) {
+ virtual_path_ = download_->GetTargetFilePath();
+ // If the download is interrupted due to file errors, prompt user for
+ // a new path.
+ should_prompt_ = ShouldPromptForDownload(virtual_path_);
} else {
- target_directory = download_prefs_->DownloadPath();
+ // If we don't have a forced path, we should construct a path for the
+ // download. Forced paths are only specified for programmatic downloads
+ // (WebStore, Drag&Drop). Treat the path as a virtual path. We will
+ // eventually determine whether this is a local path and if not, figure
+ // out a local path.
+
+ std::string suggested_filename = download_->GetSuggestedFilename();
+ if (suggested_filename.empty() &&
+ download_->GetMimeType() == "application/x-x509-user-cert") {
+ suggested_filename = "user.crt";
+ }
+
+ std::string default_filename(
+ l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME));
+ base::FilePath generated_filename = net::GenerateFileName(
+ download_->GetURL(),
+ download_->GetContentDisposition(),
+ GetProfile()->GetPrefs()->GetString(prefs::kDefaultCharset),
+ suggested_filename,
+ download_->GetMimeType(),
+ default_filename);
+ should_prompt_ = ShouldPromptForDownload(generated_filename);
+ base::FilePath target_directory;
+ if (should_prompt_) {
+ DCHECK(!download_prefs_->IsDownloadPathManaged());
+ // If the user is going to be prompted and the user has been prompted
+ // before, then always prefer the last directory that the user selected.
+ target_directory = download_prefs_->SaveFilePath();
+ } else {
+ target_directory = download_prefs_->DownloadPath();
+ }
+ virtual_path_ = target_directory.Append(generated_filename);
+ should_notify_extensions_ = true;
}
- virtual_path_ = target_directory.Append(generated_filename);
#if defined(OS_ANDROID)
conflict_action_ = DownloadPathReservationTracker::PROMPT;
#else
conflict_action_ = DownloadPathReservationTracker::UNIQUIFY;
#endif
- should_notify_extensions_ = true;
} else {
virtual_path_ = download_->GetForcedFilePath();
// If this is a resumed download which was previously interrupted due to an
« no previous file with comments | « no previous file | chrome/browser/download/download_target_determiner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698