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

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

Issue 10912183: Remove DownloadManager::GetDownloadItem in favor of GetDownload() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 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 (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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 DownloadPathReservationTracker::GetReservedPath( 631 DownloadPathReservationTracker::GetReservedPath(
632 download, target_path, default_download_path, should_uniquify_path, 632 download, target_path, default_download_path, should_uniquify_path,
633 callback); 633 callback);
634 } 634 }
635 635
636 void ChromeDownloadManagerDelegate::CheckDownloadUrlDone( 636 void ChromeDownloadManagerDelegate::CheckDownloadUrlDone(
637 int32 download_id, 637 int32 download_id,
638 const content::DownloadTargetCallback& callback, 638 const content::DownloadTargetCallback& callback,
639 DownloadProtectionService::DownloadCheckResult result) { 639 DownloadProtectionService::DownloadCheckResult result) {
640 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 640 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
641 DownloadItem* download = 641 DownloadItem* download = download_manager_->GetDownload(download_id);
642 download_manager_->GetActiveDownloadItem(download_id); 642 if (!download || (download->GetState() != DownloadItem::IN_PROGRESS))
643 if (!download)
644 return; 643 return;
645 644
646 VLOG(2) << __FUNCTION__ << "() download = " << download->DebugString(false) 645 VLOG(2) << __FUNCTION__ << "() download = " << download->DebugString(false)
647 << " verdict = " << result; 646 << " verdict = " << result;
648 content::DownloadDangerType danger_type = download->GetDangerType(); 647 content::DownloadDangerType danger_type = download->GetDangerType();
649 if (result != DownloadProtectionService::SAFE) 648 if (result != DownloadProtectionService::SAFE)
650 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL; 649 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL;
651 650
652 download_history_->CheckVisitedReferrerBefore( 651 download_history_->CheckVisitedReferrerBefore(
653 download_id, download->GetReferrerUrl(), 652 download_id, download->GetReferrerUrl(),
654 base::Bind(&ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone, 653 base::Bind(&ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone,
655 this, download_id, callback, danger_type)); 654 this, download_id, callback, danger_type));
656 } 655 }
657 656
658 void ChromeDownloadManagerDelegate::CheckClientDownloadDone( 657 void ChromeDownloadManagerDelegate::CheckClientDownloadDone(
659 int32 download_id, 658 int32 download_id,
660 DownloadProtectionService::DownloadCheckResult result) { 659 DownloadProtectionService::DownloadCheckResult result) {
661 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); 660 DownloadItem* item = download_manager_->GetDownload(download_id);
662 if (!item) 661 if (!item || (item->GetState() != DownloadItem::IN_PROGRESS))
663 return; 662 return;
664 663
665 VLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false) 664 VLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false)
666 << " verdict = " << result; 665 << " verdict = " << result;
667 // We only mark the content as being dangerous if the download's safety state 666 // We only mark the content as being dangerous if the download's safety state
668 // has not been set to DANGEROUS yet. We don't want to show two warnings. 667 // has not been set to DANGEROUS yet. We don't want to show two warnings.
669 if (item->GetSafetyState() == DownloadItem::SAFE) { 668 if (item->GetSafetyState() == DownloadItem::SAFE) {
670 switch (result) { 669 switch (result) {
671 case DownloadProtectionService::SAFE: 670 case DownloadProtectionService::SAFE:
672 // Do nothing. 671 // Do nothing.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 } 708 }
710 709
711 void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( 710 void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone(
712 int32 download_id, 711 int32 download_id,
713 const content::DownloadTargetCallback& callback, 712 const content::DownloadTargetCallback& callback,
714 content::DownloadDangerType danger_type, 713 content::DownloadDangerType danger_type,
715 bool visited_referrer_before) { 714 bool visited_referrer_before) {
716 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 715 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
717 716
718 DownloadItem* download = 717 DownloadItem* download =
719 download_manager_->GetActiveDownloadItem(download_id); 718 download_manager_->GetDownload(download_id);
720 if (!download) 719 if (!download || (download->GetState() != DownloadItem::IN_PROGRESS))
721 return; 720 return;
722 721
723 bool should_prompt = (download->GetTargetDisposition() == 722 bool should_prompt = (download->GetTargetDisposition() ==
724 DownloadItem::TARGET_DISPOSITION_PROMPT); 723 DownloadItem::TARGET_DISPOSITION_PROMPT);
725 bool is_forced_path = !download->GetForcedFilePath().empty(); 724 bool is_forced_path = !download->GetForcedFilePath().empty();
726 FilePath suggested_path; 725 FilePath suggested_path;
727 726
728 // Check whether this download is for an extension install or not. 727 // Check whether this download is for an extension install or not.
729 // Allow extensions to be explicitly saved. 728 // Allow extensions to be explicitly saved.
730 if (!is_forced_path) { 729 if (!is_forced_path) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 // TODO(asanka): Merge this logic with the logic in DownloadFilePickerChromeOS. 819 // TODO(asanka): Merge this logic with the logic in DownloadFilePickerChromeOS.
821 void ChromeDownloadManagerDelegate::SubstituteDriveDownloadPathCallback( 820 void ChromeDownloadManagerDelegate::SubstituteDriveDownloadPathCallback(
822 int32 download_id, 821 int32 download_id,
823 const content::DownloadTargetCallback& callback, 822 const content::DownloadTargetCallback& callback,
824 bool should_prompt, 823 bool should_prompt,
825 bool is_forced_path, 824 bool is_forced_path,
826 content::DownloadDangerType danger_type, 825 content::DownloadDangerType danger_type,
827 const FilePath& suggested_path) { 826 const FilePath& suggested_path) {
828 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 827 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
829 DownloadItem* download = 828 DownloadItem* download =
830 download_manager_->GetActiveDownloadItem(download_id); 829 download_manager_->GetDownload(download_id);
831 if (!download) 830 if (!download || (download->GetState() != DownloadItem::IN_PROGRESS))
832 return; 831 return;
833 832
834 GetReservedPath( 833 GetReservedPath(
835 *download, suggested_path, download_prefs_->DownloadPath(), 834 *download, suggested_path, download_prefs_->DownloadPath(),
836 !is_forced_path, 835 !is_forced_path,
837 base::Bind(&ChromeDownloadManagerDelegate::OnPathReservationAvailable, 836 base::Bind(&ChromeDownloadManagerDelegate::OnPathReservationAvailable,
838 this, download->GetId(), callback, should_prompt, 837 this, download->GetId(), callback, should_prompt,
839 danger_type)); 838 danger_type));
840 } 839 }
841 #endif 840 #endif
842 841
843 void ChromeDownloadManagerDelegate::OnPathReservationAvailable( 842 void ChromeDownloadManagerDelegate::OnPathReservationAvailable(
844 int32 download_id, 843 int32 download_id,
845 const content::DownloadTargetCallback& callback, 844 const content::DownloadTargetCallback& callback,
846 bool should_prompt, 845 bool should_prompt,
847 content::DownloadDangerType danger_type, 846 content::DownloadDangerType danger_type,
848 const FilePath& reserved_path, 847 const FilePath& reserved_path,
849 bool reserved_path_verified) { 848 bool reserved_path_verified) {
850 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 849 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
851 DownloadItem* download = 850 DownloadItem* download =
852 download_manager_->GetActiveDownloadItem(download_id); 851 download_manager_->GetDownload(download_id);
853 if (!download) 852 if (!download || (download->GetState() != DownloadItem::IN_PROGRESS))
854 return; 853 return;
855 if (should_prompt || !reserved_path_verified) { 854 if (should_prompt || !reserved_path_verified) {
856 // If the target path could not be verified then the path was non-existant, 855 // If the target path could not be verified then the path was non-existant,
857 // non writeable or could not be uniquified. Prompt the user. 856 // non writeable or could not be uniquified. Prompt the user.
858 ChooseDownloadPath( 857 ChooseDownloadPath(
859 download, reserved_path, 858 download, reserved_path,
860 base::Bind(&ChromeDownloadManagerDelegate::OnTargetPathDetermined, 859 base::Bind(&ChromeDownloadManagerDelegate::OnTargetPathDetermined,
861 this, download_id, callback, 860 this, download_id, callback,
862 DownloadItem::TARGET_DISPOSITION_PROMPT, danger_type)); 861 DownloadItem::TARGET_DISPOSITION_PROMPT, danger_type));
863 } else { 862 } else {
864 OnTargetPathDetermined(download_id, callback, 863 OnTargetPathDetermined(download_id, callback,
865 DownloadItem::TARGET_DISPOSITION_OVERWRITE, 864 DownloadItem::TARGET_DISPOSITION_OVERWRITE,
866 danger_type, reserved_path); 865 danger_type, reserved_path);
867 } 866 }
868 } 867 }
869 868
870 void ChromeDownloadManagerDelegate::OnTargetPathDetermined( 869 void ChromeDownloadManagerDelegate::OnTargetPathDetermined(
871 int32 download_id, 870 int32 download_id,
872 const content::DownloadTargetCallback& callback, 871 const content::DownloadTargetCallback& callback,
873 DownloadItem::TargetDisposition disposition, 872 DownloadItem::TargetDisposition disposition,
874 content::DownloadDangerType danger_type, 873 content::DownloadDangerType danger_type,
875 const FilePath& target_path) { 874 const FilePath& target_path) {
876 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 875 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
877 FilePath intermediate_path; 876 FilePath intermediate_path;
878 DownloadItem* download = 877 DownloadItem* download =
879 download_manager_->GetActiveDownloadItem(download_id); 878 download_manager_->GetDownload(download_id);
880 if (!download) 879 if (!download || (download->GetState() != DownloadItem::IN_PROGRESS))
881 return; 880 return;
882 881
883 // If |target_path| is empty, then that means that the user wants to cancel 882 // If |target_path| is empty, then that means that the user wants to cancel
884 // the download. 883 // the download.
885 if (!target_path.empty()) { 884 if (!target_path.empty()) {
886 intermediate_path = GetIntermediatePath(target_path, danger_type); 885 intermediate_path = GetIntermediatePath(target_path, danger_type);
887 886
888 // Retain the last directory. Exclude temporary downloads since the path 887 // Retain the last directory. Exclude temporary downloads since the path
889 // likely points at the location of a temporary file. 888 // likely points at the location of a temporary file.
890 // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a 889 // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a
(...skipping 11 matching lines...) Expand all
902 int32 download_id, int64 db_handle) { 901 int32 download_id, int64 db_handle) {
903 // It's not immediately obvious, but HistoryBackend::CreateDownload() can 902 // It's not immediately obvious, but HistoryBackend::CreateDownload() can
904 // call this function with an invalid |db_handle|. For instance, this can 903 // call this function with an invalid |db_handle|. For instance, this can
905 // happen when the history database is offline. We cannot have multiple 904 // happen when the history database is offline. We cannot have multiple
906 // DownloadItems with the same invalid db_handle, so we need to assign a 905 // DownloadItems with the same invalid db_handle, so we need to assign a
907 // unique |db_handle| here. 906 // unique |db_handle| here.
908 if (db_handle == DownloadItem::kUninitializedHandle) 907 if (db_handle == DownloadItem::kUninitializedHandle)
909 db_handle = download_history_->GetNextFakeDbHandle(); 908 db_handle = download_history_->GetNextFakeDbHandle();
910 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); 909 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle);
911 } 910 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698