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

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

Powered by Google App Engine
This is Rietveld 408576698