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

Side by Side Diff: chrome/browser/download/download_target_determiner.cc

Issue 2618743006: Use previous target path when resuming a download after crash (Closed)
Patch Set: add code for test 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/download/download_target_determiner_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 // 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
201 // 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
202 // and reuse the selection. 202 // and reuse the selection.
203 should_prompt_ = ShouldPromptForDownload(virtual_path_); 203 should_prompt_ = ShouldPromptForDownload(virtual_path_);
204 } else if (!is_forced_path) { 204 } else if (!is_forced_path) {
205 // 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
206 // download. Forced paths are only specified for programmatic downloads 206 // download. Forced paths are only specified for programmatic downloads
207 // (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
208 // 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
209 // a local path. 209 // a local path.
210
211 std::string suggested_filename = download_->GetSuggestedFilename(); 210 std::string suggested_filename = download_->GetSuggestedFilename();
212 if (suggested_filename.empty() && 211 if (suggested_filename.empty() &&
213 download_->GetMimeType() == "application/x-x509-user-cert") { 212 download_->GetMimeType() == "application/x-x509-user-cert") {
214 suggested_filename = "user.crt"; 213 suggested_filename = "user.crt";
215 } 214 }
216 215
217 std::string default_filename( 216 std::string default_filename(
218 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); 217 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME));
219 base::FilePath generated_filename = net::GenerateFileName( 218 base::FilePath generated_filename = net::GenerateFileName(
220 download_->GetURL(), 219 download_->GetURL(),
221 download_->GetContentDisposition(), 220 download_->GetContentDisposition(),
222 GetProfile()->GetPrefs()->GetString(prefs::kDefaultCharset), 221 GetProfile()->GetPrefs()->GetString(prefs::kDefaultCharset),
223 suggested_filename, 222 suggested_filename,
224 download_->GetMimeType(), 223 download_->GetMimeType(),
225 default_filename); 224 default_filename);
226 should_prompt_ = ShouldPromptForDownload(generated_filename); 225 should_prompt_ = ShouldPromptForDownload(generated_filename);
227 base::FilePath target_directory; 226 base::FilePath target_directory;
228 if (should_prompt_) { 227 if (should_prompt_) {
229 DCHECK(!download_prefs_->IsDownloadPathManaged()); 228 DCHECK(!download_prefs_->IsDownloadPathManaged());
230 // If the user is going to be prompted and the user has been prompted 229 // If the user is going to be prompted and the user has been prompted
231 // before, then always prefer the last directory that the user selected. 230 // before, then always prefer the last directory that the user selected.
232 target_directory = download_prefs_->SaveFilePath(); 231 target_directory = download_prefs_->SaveFilePath();
233 } else { 232 } else {
234 target_directory = download_prefs_->DownloadPath(); 233 target_directory = download_prefs_->DownloadPath();
235 } 234 }
236 virtual_path_ = target_directory.Append(generated_filename);
237 #if defined(OS_ANDROID) 235 #if defined(OS_ANDROID)
238 conflict_action_ = DownloadPathReservationTracker::PROMPT; 236 // If |virtual_path_| is not empty, we are resuming a download which already
237 // has a target path. Don't prompt user in this case.
238 if (!virtual_path_.empty()) {
239 conflict_action_ = DownloadPathReservationTracker::UNIQUIFY;
240 } else {
241 conflict_action_ = DownloadPathReservationTracker::PROMPT;
242 }
239 #else 243 #else
240 conflict_action_ = DownloadPathReservationTracker::UNIQUIFY; 244 conflict_action_ = DownloadPathReservationTracker::UNIQUIFY;
241 #endif 245 #endif
246 virtual_path_ = target_directory.Append(generated_filename);
242 should_notify_extensions_ = true; 247 should_notify_extensions_ = true;
243 } else { 248 } else {
244 virtual_path_ = download_->GetForcedFilePath(); 249 virtual_path_ = download_->GetForcedFilePath();
245 // If this is a resumed download which was previously interrupted due to an 250 // If this is a resumed download which was previously interrupted due to an
246 // issue with the forced path, the user is still not prompted. If the path 251 // issue with the forced path, the user is still not prompted. If the path
247 // supplied to a programmatic download is invalid, then the caller needs to 252 // supplied to a programmatic download is invalid, then the caller needs to
248 // intervene. 253 // intervene.
249 } 254 }
250 DCHECK(virtual_path_.IsAbsolute()); 255 DCHECK(virtual_path_.IsAbsolute());
251 DVLOG(20) << "Generated virtual path: " << virtual_path_.AsUTF8Unsafe(); 256 DVLOG(20) << "Generated virtual path: " << virtual_path_.AsUTF8Unsafe();
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 DCHECK_CURRENTLY_ON(BrowserThread::UI); 618 DCHECK_CURRENTLY_ON(BrowserThread::UI);
614 DVLOG(20) << "URL Check Result:" << danger_type; 619 DVLOG(20) << "URL Check Result:" << danger_type;
615 DCHECK_EQ(STATE_CHECK_VISITED_REFERRER_BEFORE, next_state_); 620 DCHECK_EQ(STATE_CHECK_VISITED_REFERRER_BEFORE, next_state_);
616 danger_type_ = danger_type; 621 danger_type_ = danger_type;
617 DoLoop(); 622 DoLoop();
618 } 623 }
619 624
620 DownloadTargetDeterminer::Result 625 DownloadTargetDeterminer::Result
621 DownloadTargetDeterminer::DoCheckVisitedReferrerBefore() { 626 DownloadTargetDeterminer::DoCheckVisitedReferrerBefore() {
622 DCHECK_CURRENTLY_ON(BrowserThread::UI); 627 DCHECK_CURRENTLY_ON(BrowserThread::UI);
623
624 next_state_ = STATE_DETERMINE_INTERMEDIATE_PATH; 628 next_state_ = STATE_DETERMINE_INTERMEDIATE_PATH;
625 629
626 // Checking if there are prior visits to the referrer is only necessary if the 630 // Checking if there are prior visits to the referrer is only necessary if the
627 // danger level of the download depends on the file type. 631 // danger level of the download depends on the file type.
628 if (danger_type_ != content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS && 632 if (danger_type_ != content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS &&
629 danger_type_ != content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT) 633 danger_type_ != content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT)
630 return CONTINUE; 634 return CONTINUE;
631 635
632 // First determine the danger level assuming that the user doesn't have any 636 // First determine the danger level assuming that the user doesn't have any
633 // prior visits to the referrer recoreded in history. The resulting danger 637 // prior visits to the referrer recoreded in history. The resulting danger
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 const base::FilePath& suggested_path) { 951 const base::FilePath& suggested_path) {
948 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); 952 return base::FilePath(suggested_path.value() + kCrdownloadSuffix);
949 } 953 }
950 954
951 #if defined(OS_WIN) 955 #if defined(OS_WIN)
952 // static 956 // static
953 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() { 957 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() {
954 return g_is_adobe_reader_up_to_date_; 958 return g_is_adobe_reader_up_to_date_;
955 } 959 }
956 #endif 960 #endif
OLDNEW
« 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