Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/download/download_target_determiner.h" | 5 #include "chrome/browser/download/download_target_determiner.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 DownloadTargetDeterminer::DoGenerateTargetPath() { | 188 DownloadTargetDeterminer::DoGenerateTargetPath() { |
| 189 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 189 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 190 DCHECK(local_path_.empty()); | 190 DCHECK(local_path_.empty()); |
| 191 DCHECK(!should_prompt_); | 191 DCHECK(!should_prompt_); |
| 192 DCHECK(!should_notify_extensions_); | 192 DCHECK(!should_notify_extensions_); |
| 193 DCHECK_EQ(DownloadPathReservationTracker::OVERWRITE, conflict_action_); | 193 DCHECK_EQ(DownloadPathReservationTracker::OVERWRITE, conflict_action_); |
| 194 bool is_forced_path = !download_->GetForcedFilePath().empty(); | 194 bool is_forced_path = !download_->GetForcedFilePath().empty(); |
| 195 | 195 |
| 196 next_state_ = STATE_NOTIFY_EXTENSIONS; | 196 next_state_ = STATE_NOTIFY_EXTENSIONS; |
| 197 | 197 |
| 198 if (!virtual_path_.empty() && HasPromptedForPath() && !is_forced_path) { | 198 if (!virtual_path_.empty() && HasPromptedForPath() && !is_forced_path) { |
|
asanka
2017/01/12 18:58:35
Apologies. I didn't read this CL as carefully as I
qinmin
2017/01/13 01:08:24
Based on our offline discussions, a non empty virt
| |
| 199 // The download is being resumed and the user has already been prompted for | 199 // The download is being resumed and the user has already been prompted for |
| 200 // a path. Assume that it's okay to overwrite the file if there's a conflict | 200 // a path. Assume that it's okay to overwrite the file if there's a conflict |
| 201 // and reuse the selection. | 201 // and reuse the selection. |
| 202 should_prompt_ = ShouldPromptForDownload(virtual_path_); | 202 should_prompt_ = ShouldPromptForDownload(virtual_path_); |
| 203 } else if (!is_forced_path) { | 203 } else if (!is_forced_path) { |
| 204 // If we don't have a forced path, we should construct a path for the | 204 // If the download already has a target path, use it. |
| 205 // download. Forced paths are only specified for programmatic downloads | 205 if (!download_->GetTargetFilePath().empty()) { |
| 206 // (WebStore, Drag&Drop). Treat the path as a virtual path. We will | 206 virtual_path_ = download_->GetTargetFilePath(); |
| 207 // eventually determine whether this is a local path and if not, figure out | 207 // If the download is interrupted due to file errors, prompt user for |
| 208 // a local path. | 208 // a new path. |
| 209 should_prompt_ = ShouldPromptForDownload(virtual_path_); | |
| 210 } else { | |
| 211 // If we don't have a forced path, we should construct a path for the | |
| 212 // download. Forced paths are only specified for programmatic downloads | |
| 213 // (WebStore, Drag&Drop). Treat the path as a virtual path. We will | |
| 214 // eventually determine whether this is a local path and if not, figure | |
| 215 // out a local path. | |
| 209 | 216 |
| 210 std::string suggested_filename = download_->GetSuggestedFilename(); | 217 std::string suggested_filename = download_->GetSuggestedFilename(); |
| 211 if (suggested_filename.empty() && | 218 if (suggested_filename.empty() && |
| 212 download_->GetMimeType() == "application/x-x509-user-cert") { | 219 download_->GetMimeType() == "application/x-x509-user-cert") { |
| 213 suggested_filename = "user.crt"; | 220 suggested_filename = "user.crt"; |
| 221 } | |
| 222 | |
| 223 std::string default_filename( | |
| 224 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); | |
| 225 base::FilePath generated_filename = net::GenerateFileName( | |
| 226 download_->GetURL(), | |
| 227 download_->GetContentDisposition(), | |
| 228 GetProfile()->GetPrefs()->GetString(prefs::kDefaultCharset), | |
| 229 suggested_filename, | |
| 230 download_->GetMimeType(), | |
| 231 default_filename); | |
| 232 should_prompt_ = ShouldPromptForDownload(generated_filename); | |
| 233 base::FilePath target_directory; | |
| 234 if (should_prompt_) { | |
| 235 DCHECK(!download_prefs_->IsDownloadPathManaged()); | |
| 236 // If the user is going to be prompted and the user has been prompted | |
| 237 // before, then always prefer the last directory that the user selected. | |
| 238 target_directory = download_prefs_->SaveFilePath(); | |
| 239 } else { | |
| 240 target_directory = download_prefs_->DownloadPath(); | |
| 241 } | |
| 242 virtual_path_ = target_directory.Append(generated_filename); | |
| 243 should_notify_extensions_ = true; | |
| 214 } | 244 } |
| 215 | |
| 216 std::string default_filename( | |
| 217 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); | |
| 218 base::FilePath generated_filename = net::GenerateFileName( | |
| 219 download_->GetURL(), | |
| 220 download_->GetContentDisposition(), | |
| 221 GetProfile()->GetPrefs()->GetString(prefs::kDefaultCharset), | |
| 222 suggested_filename, | |
| 223 download_->GetMimeType(), | |
| 224 default_filename); | |
| 225 should_prompt_ = ShouldPromptForDownload(generated_filename); | |
| 226 base::FilePath target_directory; | |
| 227 if (should_prompt_) { | |
| 228 DCHECK(!download_prefs_->IsDownloadPathManaged()); | |
| 229 // If the user is going to be prompted and the user has been prompted | |
| 230 // before, then always prefer the last directory that the user selected. | |
| 231 target_directory = download_prefs_->SaveFilePath(); | |
| 232 } else { | |
| 233 target_directory = download_prefs_->DownloadPath(); | |
| 234 } | |
| 235 virtual_path_ = target_directory.Append(generated_filename); | |
| 236 #if defined(OS_ANDROID) | 245 #if defined(OS_ANDROID) |
| 237 conflict_action_ = DownloadPathReservationTracker::PROMPT; | 246 conflict_action_ = DownloadPathReservationTracker::PROMPT; |
| 238 #else | 247 #else |
| 239 conflict_action_ = DownloadPathReservationTracker::UNIQUIFY; | 248 conflict_action_ = DownloadPathReservationTracker::UNIQUIFY; |
| 240 #endif | 249 #endif |
| 241 should_notify_extensions_ = true; | |
| 242 } else { | 250 } else { |
| 243 virtual_path_ = download_->GetForcedFilePath(); | 251 virtual_path_ = download_->GetForcedFilePath(); |
| 244 // If this is a resumed download which was previously interrupted due to an | 252 // If this is a resumed download which was previously interrupted due to an |
| 245 // issue with the forced path, the user is still not prompted. If the path | 253 // issue with the forced path, the user is still not prompted. If the path |
| 246 // supplied to a programmatic download is invalid, then the caller needs to | 254 // supplied to a programmatic download is invalid, then the caller needs to |
| 247 // intervene. | 255 // intervene. |
| 248 } | 256 } |
| 249 DCHECK(virtual_path_.IsAbsolute()); | 257 DCHECK(virtual_path_.IsAbsolute()); |
| 250 DVLOG(20) << "Generated virtual path: " << virtual_path_.AsUTF8Unsafe(); | 258 DVLOG(20) << "Generated virtual path: " << virtual_path_.AsUTF8Unsafe(); |
| 251 | 259 |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 943 const base::FilePath& suggested_path) { | 951 const base::FilePath& suggested_path) { |
| 944 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); | 952 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); |
| 945 } | 953 } |
| 946 | 954 |
| 947 #if defined(OS_WIN) | 955 #if defined(OS_WIN) |
| 948 // static | 956 // static |
| 949 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() { | 957 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() { |
| 950 return g_is_adobe_reader_up_to_date_; | 958 return g_is_adobe_reader_up_to_date_; |
| 951 } | 959 } |
| 952 #endif | 960 #endif |
| OLD | NEW |