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/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 Loading... | |
| 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 Loading... | |
| 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_ && !download_prefs_->IsDownloadPathManaged()) { |
|
asanka
2013/05/07 15:15:12
The DCHECK() was to assert that we don't try to pr
benjhayden
2013/05/17 20:31:54
Done.
| |
| 163 DCHECK(!download_prefs_->IsDownloadPathManaged()); | |
| 164 // If the user is going to be prompted and the user has been prompted | 161 // 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. | 162 // before, then always prefer the last directory that the user selected. |
| 166 target_directory = last_selected_directory_; | 163 target_directory = download_prefs_->SaveFilePath(); |
| 167 } else { | 164 } else { |
| 168 target_directory = download_prefs_->DownloadPath(); | 165 target_directory = download_prefs_->DownloadPath(); |
| 169 } | 166 } |
| 170 virtual_path_ = target_directory.Append(generated_filename); | 167 virtual_path_ = target_directory.Append(generated_filename); |
| 171 } else { | 168 } else { |
| 172 DCHECK(!should_prompt_); | 169 DCHECK(!should_prompt_); |
| 173 virtual_path_ = download_->GetForcedFilePath(); | 170 virtual_path_ = download_->GetForcedFilePath(); |
| 174 } | 171 } |
| 175 DCHECK(virtual_path_.IsAbsolute()); | 172 DCHECK(virtual_path_.IsAbsolute()); |
| 176 DVLOG(20) << "Generated virtual path: " << virtual_path_.AsUTF8Unsafe(); | 173 DVLOG(20) << "Generated virtual path: " << virtual_path_.AsUTF8Unsafe(); |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 DownloadItem* download) { | 575 DownloadItem* download) { |
| 579 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 576 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 580 DCHECK_EQ(download_, download); | 577 DCHECK_EQ(download_, download); |
| 581 CancelOnFailureAndDeleteSelf(); | 578 CancelOnFailureAndDeleteSelf(); |
| 582 } | 579 } |
| 583 | 580 |
| 584 // static | 581 // static |
| 585 void DownloadTargetDeterminer::Start( | 582 void DownloadTargetDeterminer::Start( |
| 586 content::DownloadItem* download, | 583 content::DownloadItem* download, |
| 587 DownloadPrefs* download_prefs, | 584 DownloadPrefs* download_prefs, |
| 588 const base::FilePath& last_selected_directory, | |
| 589 DownloadTargetDeterminerDelegate* delegate, | 585 DownloadTargetDeterminerDelegate* delegate, |
| 590 const content::DownloadTargetCallback& callback) { | 586 const content::DownloadTargetCallback& callback) { |
| 591 // DownloadTargetDeterminer owns itself and will self destruct when the job is | 587 // DownloadTargetDeterminer owns itself and will self destruct when the job is |
| 592 // complete or the download item is destroyed. The callback is always invoked | 588 // complete or the download item is destroyed. The callback is always invoked |
| 593 // asynchronously. | 589 // asynchronously. |
| 594 new DownloadTargetDeterminer(download, download_prefs, | 590 new DownloadTargetDeterminer(download, download_prefs, delegate, callback); |
| 595 last_selected_directory, delegate, callback); | |
| 596 } | 591 } |
| OLD | NEW |