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

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: remove GetLastTargetPath function 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
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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 base::FilePath last_target_path = download_->GetForcedFilePath().empty() ?
196 download_->GetTargetFilePath() : download_->GetForcedFilePath();
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() &&
201 last_target_path.empty()) {
199 // The download is being resumed and the user has already been prompted for 202 // 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 203 // a path. Assume that it's okay to overwrite the file if there's a conflict
201 // and reuse the selection. 204 // and reuse the selection.
202 should_prompt_ = ShouldPromptForDownload(virtual_path_); 205 should_prompt_ = ShouldPromptForDownload(virtual_path_);
203 } else if (!is_forced_path) { 206 } else if (last_target_path.empty()) {
204 // If we don't have a forced path, we should construct a path for the 207 // 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 208 // download. Forced paths are only specified for programmatic downloads
206 // (WebStore, Drag&Drop). Treat the path as a virtual path. We will 209 // (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 210 // eventually determine whether this is a local path and if not, figure out
208 // a local path. 211 // a local path.
209 212
210 std::string suggested_filename = download_->GetSuggestedFilename(); 213 std::string suggested_filename = download_->GetSuggestedFilename();
211 if (suggested_filename.empty() && 214 if (suggested_filename.empty() &&
212 download_->GetMimeType() == "application/x-x509-user-cert") { 215 download_->GetMimeType() == "application/x-x509-user-cert") {
213 suggested_filename = "user.crt"; 216 suggested_filename = "user.crt";
(...skipping 19 matching lines...) Expand all
233 target_directory = download_prefs_->DownloadPath(); 236 target_directory = download_prefs_->DownloadPath();
234 } 237 }
235 virtual_path_ = target_directory.Append(generated_filename); 238 virtual_path_ = target_directory.Append(generated_filename);
236 #if defined(OS_ANDROID) 239 #if defined(OS_ANDROID)
237 conflict_action_ = DownloadPathReservationTracker::PROMPT; 240 conflict_action_ = DownloadPathReservationTracker::PROMPT;
238 #else 241 #else
239 conflict_action_ = DownloadPathReservationTracker::UNIQUIFY; 242 conflict_action_ = DownloadPathReservationTracker::UNIQUIFY;
240 #endif 243 #endif
241 should_notify_extensions_ = true; 244 should_notify_extensions_ = true;
242 } else { 245 } else {
243 virtual_path_ = download_->GetForcedFilePath(); 246 virtual_path_ = last_target_path;
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698