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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 ScheduleCallbackAndDeleteSelf(); | 184 ScheduleCallbackAndDeleteSelf(); |
| 185 } | 185 } |
| 186 | 186 |
| 187 DownloadTargetDeterminer::Result | 187 DownloadTargetDeterminer::Result |
| 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 // If the download already has a forced path or a target path, use it. |
| 195 bool has_target_path = !download_->GetForcedFilePath().empty() | |
| 196 || !download_->GetTargetFilePath().empty(); | |
| 195 | 197 |
| 196 next_state_ = STATE_NOTIFY_EXTENSIONS; | 198 next_state_ = STATE_NOTIFY_EXTENSIONS; |
| 197 | 199 |
| 198 if (!virtual_path_.empty() && HasPromptedForPath() && !is_forced_path) { | 200 if (!virtual_path_.empty() && HasPromptedForPath() && !has_target_path) { |
| 199 // The download is being resumed and the user has already been prompted for | 201 // 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 | 202 // a path. Assume that it's okay to overwrite the file if there's a conflict |
| 201 // and reuse the selection. | 203 // and reuse the selection. |
| 202 should_prompt_ = ShouldPromptForDownload(virtual_path_); | 204 should_prompt_ = ShouldPromptForDownload(virtual_path_); |
| 203 } else if (!is_forced_path) { | 205 } else if (!has_target_path) { |
| 204 // If we don't have a forced path, we should construct a path for the | 206 // If we don't have a forced path, we should construct a path for the |
| 205 // download. Forced paths are only specified for programmatic downloads | 207 // download. Forced paths are only specified for programmatic downloads |
| 206 // (WebStore, Drag&Drop). Treat the path as a virtual path. We will | 208 // (WebStore, Drag&Drop). Treat the path as a virtual path. We will |
| 207 // eventually determine whether this is a local path and if not, figure out | 209 // eventually determine whether this is a local path and if not, figure out |
| 208 // a local path. | 210 // a local path. |
| 209 | 211 |
| 210 std::string suggested_filename = download_->GetSuggestedFilename(); | 212 std::string suggested_filename = download_->GetSuggestedFilename(); |
| 211 if (suggested_filename.empty() && | 213 if (suggested_filename.empty() && |
| 212 download_->GetMimeType() == "application/x-x509-user-cert") { | 214 download_->GetMimeType() == "application/x-x509-user-cert") { |
| 213 suggested_filename = "user.crt"; | 215 suggested_filename = "user.crt"; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 233 target_directory = download_prefs_->DownloadPath(); | 235 target_directory = download_prefs_->DownloadPath(); |
| 234 } | 236 } |
| 235 virtual_path_ = target_directory.Append(generated_filename); | 237 virtual_path_ = target_directory.Append(generated_filename); |
| 236 #if defined(OS_ANDROID) | 238 #if defined(OS_ANDROID) |
| 237 conflict_action_ = DownloadPathReservationTracker::PROMPT; | 239 conflict_action_ = DownloadPathReservationTracker::PROMPT; |
| 238 #else | 240 #else |
| 239 conflict_action_ = DownloadPathReservationTracker::UNIQUIFY; | 241 conflict_action_ = DownloadPathReservationTracker::UNIQUIFY; |
| 240 #endif | 242 #endif |
| 241 should_notify_extensions_ = true; | 243 should_notify_extensions_ = true; |
| 242 } else { | 244 } else { |
| 243 virtual_path_ = download_->GetForcedFilePath(); | 245 virtual_path_ = download_->GetForcedFilePath().empty() ? |
|
David Trainor- moved to gerrit
2017/01/06 23:26:41
Since we're using this logic a lot, would it be cl
qinmin
2017/01/09 22:17:27
Done.
| |
| 246 download_->GetTargetFilePath() : download_->GetForcedFilePath(); | |
| 244 // If this is a resumed download which was previously interrupted due to an | 247 // 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 | 248 // 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 | 249 // supplied to a programmatic download is invalid, then the caller needs to |
| 247 // intervene. | 250 // intervene. |
| 248 } | 251 } |
| 249 DCHECK(virtual_path_.IsAbsolute()); | 252 DCHECK(virtual_path_.IsAbsolute()); |
| 250 DVLOG(20) << "Generated virtual path: " << virtual_path_.AsUTF8Unsafe(); | 253 DVLOG(20) << "Generated virtual path: " << virtual_path_.AsUTF8Unsafe(); |
| 251 | 254 |
| 252 return CONTINUE; | 255 return CONTINUE; |
| 253 } | 256 } |
| (...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 943 const base::FilePath& suggested_path) { | 946 const base::FilePath& suggested_path) { |
| 944 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); | 947 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); |
| 945 } | 948 } |
| 946 | 949 |
| 947 #if defined(OS_WIN) | 950 #if defined(OS_WIN) |
| 948 // static | 951 // static |
| 949 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() { | 952 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() { |
| 950 return g_is_adobe_reader_up_to_date_; | 953 return g_is_adobe_reader_up_to_date_; |
| 951 } | 954 } |
| 952 #endif | 955 #endif |
| OLD | NEW |