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