OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chrome_download_manager_delegate.h" | 5 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingState); | 99 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingState); |
100 }; | 100 }; |
101 | 101 |
102 SafeBrowsingState::~SafeBrowsingState() {} | 102 SafeBrowsingState::~SafeBrowsingState() {} |
103 | 103 |
104 } // namespace | 104 } // namespace |
105 | 105 |
106 ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile) | 106 ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile) |
107 : profile_(profile), | 107 : profile_(profile), |
108 next_download_id_(0), | 108 next_download_id_(0), |
109 download_prefs_(new DownloadPrefs(profile->GetPrefs())) { | 109 download_prefs_(new DownloadPrefs(profile)) { |
110 } | 110 } |
111 | 111 |
112 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { | 112 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { |
113 } | 113 } |
114 | 114 |
115 void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { | 115 void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { |
116 download_manager_ = dm; | 116 download_manager_ = dm; |
117 download_history_.reset(new DownloadHistory(profile_)); | 117 download_history_.reset(new DownloadHistory(profile_)); |
118 download_history_->Load( | 118 download_history_->Load( |
119 base::Bind(&DownloadManager::OnPersistentStoreQueryComplete, | 119 base::Bind(&DownloadManager::OnPersistentStoreQueryComplete, |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 if (download_prefs_->IsDownloadPathManaged()) | 653 if (download_prefs_->IsDownloadPathManaged()) |
654 should_prompt = false; | 654 should_prompt = false; |
655 | 655 |
656 // Determine the proper path for a download, by either one of the following: | 656 // Determine the proper path for a download, by either one of the following: |
657 // 1) using the default download directory. | 657 // 1) using the default download directory. |
658 // 2) prompting the user. | 658 // 2) prompting the user. |
659 FilePath target_directory; | 659 FilePath target_directory; |
660 if (should_prompt && !download_manager_->LastDownloadPath().empty()) | 660 if (should_prompt && !download_manager_->LastDownloadPath().empty()) |
661 target_directory = download_manager_->LastDownloadPath(); | 661 target_directory = download_manager_->LastDownloadPath(); |
662 else | 662 else |
663 target_directory = download_prefs_->download_path(); | 663 target_directory = download_prefs_->DownloadPath(); |
664 suggested_path = target_directory.Append(generated_name); | 664 suggested_path = target_directory.Append(generated_name); |
665 } else { | 665 } else { |
666 DCHECK(!should_prompt); | 666 DCHECK(!should_prompt); |
667 suggested_path = download->GetForcedFilePath(); | 667 suggested_path = download->GetForcedFilePath(); |
668 } | 668 } |
669 | 669 |
670 // If the download hasn't already been marked dangerous (could be | 670 // If the download hasn't already been marked dangerous (could be |
671 // DANGEROUS_URL), check if it is a dangerous file. | 671 // DANGEROUS_URL), check if it is a dangerous file. |
672 if (danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { | 672 if (danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { |
673 if (!should_prompt && !is_forced_path && | 673 if (!should_prompt && !is_forced_path && |
(...skipping 23 matching lines...) Expand all Loading... |
697 } | 697 } |
698 | 698 |
699 #if defined (OS_CHROMEOS) | 699 #if defined (OS_CHROMEOS) |
700 gdata::GDataDownloadObserver::SubstituteGDataDownloadPath( | 700 gdata::GDataDownloadObserver::SubstituteGDataDownloadPath( |
701 profile_, suggested_path, download, | 701 profile_, suggested_path, download, |
702 base::Bind( | 702 base::Bind( |
703 &ChromeDownloadManagerDelegate::SubstituteGDataDownloadPathCallback, | 703 &ChromeDownloadManagerDelegate::SubstituteGDataDownloadPathCallback, |
704 this, download->GetId(), should_prompt, is_forced_path, danger_type)); | 704 this, download->GetId(), should_prompt, is_forced_path, danger_type)); |
705 #else | 705 #else |
706 GetReservedPath( | 706 GetReservedPath( |
707 *download, suggested_path, download_prefs_->download_path(), | 707 *download, suggested_path, download_prefs_->DownloadPath(), |
708 !is_forced_path, | 708 !is_forced_path, |
709 base::Bind(&ChromeDownloadManagerDelegate::OnPathReservationAvailable, | 709 base::Bind(&ChromeDownloadManagerDelegate::OnPathReservationAvailable, |
710 this, download->GetId(), should_prompt, danger_type)); | 710 this, download->GetId(), should_prompt, danger_type)); |
711 #endif | 711 #endif |
712 } | 712 } |
713 | 713 |
714 #if defined (OS_CHROMEOS) | 714 #if defined (OS_CHROMEOS) |
715 void ChromeDownloadManagerDelegate::SubstituteGDataDownloadPathCallback( | 715 void ChromeDownloadManagerDelegate::SubstituteGDataDownloadPathCallback( |
716 int32 download_id, | 716 int32 download_id, |
717 bool should_prompt, | 717 bool should_prompt, |
718 bool is_forced_path, | 718 bool is_forced_path, |
719 content::DownloadDangerType danger_type, | 719 content::DownloadDangerType danger_type, |
720 const FilePath& suggested_path) { | 720 const FilePath& suggested_path) { |
721 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 721 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
722 DownloadItem* download = | 722 DownloadItem* download = |
723 download_manager_->GetActiveDownloadItem(download_id); | 723 download_manager_->GetActiveDownloadItem(download_id); |
724 if (!download) | 724 if (!download) |
725 return; | 725 return; |
726 | 726 |
727 GetReservedPath( | 727 GetReservedPath( |
728 *download, suggested_path, download_prefs_->download_path(), | 728 *download, suggested_path, download_prefs_->DownloadPath(), |
729 !is_forced_path, | 729 !is_forced_path, |
730 base::Bind(&ChromeDownloadManagerDelegate::OnPathReservationAvailable, | 730 base::Bind(&ChromeDownloadManagerDelegate::OnPathReservationAvailable, |
731 this, download->GetId(), should_prompt, danger_type)); | 731 this, download->GetId(), should_prompt, danger_type)); |
732 } | 732 } |
733 #endif | 733 #endif |
734 | 734 |
735 void ChromeDownloadManagerDelegate::OnPathReservationAvailable( | 735 void ChromeDownloadManagerDelegate::OnPathReservationAvailable( |
736 int32 download_id, | 736 int32 download_id, |
737 bool should_prompt, | 737 bool should_prompt, |
738 content::DownloadDangerType danger_type, | 738 content::DownloadDangerType danger_type, |
(...skipping 19 matching lines...) Expand all Loading... |
758 int32 download_id, int64 db_handle) { | 758 int32 download_id, int64 db_handle) { |
759 // It's not immediately obvious, but HistoryBackend::CreateDownload() can | 759 // It's not immediately obvious, but HistoryBackend::CreateDownload() can |
760 // call this function with an invalid |db_handle|. For instance, this can | 760 // call this function with an invalid |db_handle|. For instance, this can |
761 // happen when the history database is offline. We cannot have multiple | 761 // happen when the history database is offline. We cannot have multiple |
762 // DownloadItems with the same invalid db_handle, so we need to assign a | 762 // DownloadItems with the same invalid db_handle, so we need to assign a |
763 // unique |db_handle| here. | 763 // unique |db_handle| here. |
764 if (db_handle == DownloadItem::kUninitializedHandle) | 764 if (db_handle == DownloadItem::kUninitializedHandle) |
765 db_handle = download_history_->GetNextFakeDbHandle(); | 765 db_handle = download_history_->GetNextFakeDbHandle(); |
766 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); | 766 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); |
767 } | 767 } |
OLD | NEW |