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

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

Issue 12662032: Merge SavePackageFilePicker{,ChromeOS} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r202870 Created 7 years, 6 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 | Annotate | Revision Log
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/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 52 }
53 53
54 } // namespace 54 } // namespace
55 55
56 DownloadTargetDeterminerDelegate::~DownloadTargetDeterminerDelegate() { 56 DownloadTargetDeterminerDelegate::~DownloadTargetDeterminerDelegate() {
57 } 57 }
58 58
59 DownloadTargetDeterminer::DownloadTargetDeterminer( 59 DownloadTargetDeterminer::DownloadTargetDeterminer(
60 DownloadItem* download, 60 DownloadItem* download,
61 DownloadPrefs* download_prefs, 61 DownloadPrefs* download_prefs,
62 const base::FilePath& last_selected_directory,
63 DownloadTargetDeterminerDelegate* delegate, 62 DownloadTargetDeterminerDelegate* delegate,
64 const content::DownloadTargetCallback& callback) 63 const content::DownloadTargetCallback& callback)
65 : next_state_(STATE_GENERATE_TARGET_PATH), 64 : next_state_(STATE_GENERATE_TARGET_PATH),
66 should_prompt_(false), 65 should_prompt_(false),
67 create_directory_(false), 66 create_directory_(false),
68 conflict_action_(download->GetForcedFilePath().empty() ? 67 conflict_action_(download->GetForcedFilePath().empty() ?
69 DownloadPathReservationTracker::UNIQUIFY : 68 DownloadPathReservationTracker::UNIQUIFY :
70 DownloadPathReservationTracker::OVERWRITE), 69 DownloadPathReservationTracker::OVERWRITE),
71 danger_type_(download->GetDangerType()), 70 danger_type_(download->GetDangerType()),
72 download_(download), 71 download_(download),
73 download_prefs_(download_prefs), 72 download_prefs_(download_prefs),
74 delegate_(delegate), 73 delegate_(delegate),
75 last_selected_directory_(last_selected_directory),
76 completion_callback_(callback), 74 completion_callback_(callback),
77 weak_ptr_factory_(this) { 75 weak_ptr_factory_(this) {
78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
79 DCHECK(download_); 77 DCHECK(download_);
80 DCHECK(delegate); 78 DCHECK(delegate);
81 download_->AddObserver(this); 79 download_->AddObserver(this);
82 80
83 DoLoop(); 81 DoLoop();
84 } 82 }
85 83
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); 150 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME));
153 base::FilePath generated_filename = net::GenerateFileName( 151 base::FilePath generated_filename = net::GenerateFileName(
154 download_->GetURL(), 152 download_->GetURL(),
155 download_->GetContentDisposition(), 153 download_->GetContentDisposition(),
156 GetProfile()->GetPrefs()->GetString(prefs::kDefaultCharset), 154 GetProfile()->GetPrefs()->GetString(prefs::kDefaultCharset),
157 download_->GetSuggestedFilename(), 155 download_->GetSuggestedFilename(),
158 download_->GetMimeType(), 156 download_->GetMimeType(),
159 default_filename); 157 default_filename);
160 should_prompt_ = ShouldPromptForDownload(generated_filename); 158 should_prompt_ = ShouldPromptForDownload(generated_filename);
161 base::FilePath target_directory; 159 base::FilePath target_directory;
162 if (should_prompt_ && !last_selected_directory_.empty()) { 160 if (should_prompt_) {
163 DCHECK(!download_prefs_->IsDownloadPathManaged()); 161 DCHECK(!download_prefs_->IsDownloadPathManaged());
164 // If the user is going to be prompted and the user has been prompted 162 // If the user is going to be prompted and the user has been prompted
165 // before, then always prefer the last directory that the user selected. 163 // before, then always prefer the last directory that the user selected.
166 target_directory = last_selected_directory_; 164 target_directory = download_prefs_->SaveFilePath();
167 } else { 165 } else {
168 target_directory = download_prefs_->DownloadPath(); 166 target_directory = download_prefs_->DownloadPath();
169 } 167 }
170 virtual_path_ = target_directory.Append(generated_filename); 168 virtual_path_ = target_directory.Append(generated_filename);
171 } else { 169 } else {
172 DCHECK(!should_prompt_); 170 DCHECK(!should_prompt_);
173 virtual_path_ = download_->GetForcedFilePath(); 171 virtual_path_ = download_->GetForcedFilePath();
174 } 172 }
175 DCHECK(virtual_path_.IsAbsolute()); 173 DCHECK(virtual_path_.IsAbsolute());
176 DVLOG(20) << "Generated virtual path: " << virtual_path_.AsUTF8Unsafe(); 174 DVLOG(20) << "Generated virtual path: " << virtual_path_.AsUTF8Unsafe();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 275
278 void DownloadTargetDeterminer::PromptUserForDownloadPathDone( 276 void DownloadTargetDeterminer::PromptUserForDownloadPathDone(
279 const base::FilePath& virtual_path) { 277 const base::FilePath& virtual_path) {
280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
281 DVLOG(20) << "User selected path:" << virtual_path.AsUTF8Unsafe(); 279 DVLOG(20) << "User selected path:" << virtual_path.AsUTF8Unsafe();
282 if (virtual_path.empty()) { 280 if (virtual_path.empty()) {
283 CancelOnFailureAndDeleteSelf(); 281 CancelOnFailureAndDeleteSelf();
284 return; 282 return;
285 } 283 }
286 virtual_path_ = virtual_path; 284 virtual_path_ = virtual_path;
285 download_prefs_->SetSaveFilePath(virtual_path_.DirName());
287 DoLoop(); 286 DoLoop();
288 } 287 }
289 288
290 DownloadTargetDeterminer::Result 289 DownloadTargetDeterminer::Result
291 DownloadTargetDeterminer::DoDetermineLocalPath() { 290 DownloadTargetDeterminer::DoDetermineLocalPath() {
292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
293 DCHECK(!virtual_path_.empty()); 292 DCHECK(!virtual_path_.empty());
294 DCHECK(local_path_.empty()); 293 DCHECK(local_path_.empty());
295 294
296 next_state_ = STATE_CHECK_DOWNLOAD_URL; 295 next_state_ = STATE_CHECK_DOWNLOAD_URL;
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 DownloadItem* download) { 577 DownloadItem* download) {
579 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 578 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
580 DCHECK_EQ(download_, download); 579 DCHECK_EQ(download_, download);
581 CancelOnFailureAndDeleteSelf(); 580 CancelOnFailureAndDeleteSelf();
582 } 581 }
583 582
584 // static 583 // static
585 void DownloadTargetDeterminer::Start( 584 void DownloadTargetDeterminer::Start(
586 content::DownloadItem* download, 585 content::DownloadItem* download,
587 DownloadPrefs* download_prefs, 586 DownloadPrefs* download_prefs,
588 const base::FilePath& last_selected_directory,
589 DownloadTargetDeterminerDelegate* delegate, 587 DownloadTargetDeterminerDelegate* delegate,
590 const content::DownloadTargetCallback& callback) { 588 const content::DownloadTargetCallback& callback) {
591 // DownloadTargetDeterminer owns itself and will self destruct when the job is 589 // DownloadTargetDeterminer owns itself and will self destruct when the job is
592 // complete or the download item is destroyed. The callback is always invoked 590 // complete or the download item is destroyed. The callback is always invoked
593 // asynchronously. 591 // asynchronously.
594 new DownloadTargetDeterminer(download, download_prefs, 592 new DownloadTargetDeterminer(download, download_prefs, delegate, callback);
595 last_selected_directory, delegate, callback);
596 } 593 }
597 594
598 // static 595 // static
599 base::FilePath DownloadTargetDeterminer::GetCrDownloadPath( 596 base::FilePath DownloadTargetDeterminer::GetCrDownloadPath(
600 const base::FilePath& suggested_path) { 597 const base::FilePath& suggested_path) {
601 return base::FilePath(suggested_path.value() + 598 return base::FilePath(suggested_path.value() +
602 FILE_PATH_LITERAL(".crdownload")); 599 FILE_PATH_LITERAL(".crdownload"));
603 } 600 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_target_determiner.h ('k') | chrome/browser/download/download_target_determiner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698