Chromium Code Reviews| 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 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 DownloadPathReservationTracker::GetReservedPath( | 617 DownloadPathReservationTracker::GetReservedPath( |
| 618 download, target_path, default_download_path, should_uniquify_path, | 618 download, target_path, default_download_path, should_uniquify_path, |
| 619 callback); | 619 callback); |
| 620 } | 620 } |
| 621 | 621 |
| 622 void ChromeDownloadManagerDelegate::CheckDownloadUrlDone( | 622 void ChromeDownloadManagerDelegate::CheckDownloadUrlDone( |
| 623 int32 download_id, | 623 int32 download_id, |
| 624 const content::DownloadTargetCallback& callback, | 624 const content::DownloadTargetCallback& callback, |
| 625 DownloadProtectionService::DownloadCheckResult result) { | 625 DownloadProtectionService::DownloadCheckResult result) { |
| 626 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 626 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 627 DownloadItem* download = | 627 DownloadItem* download = download_manager_->GetDownload(download_id); |
|
Randy Smith (Not in Mondays)
2012/09/11 19:02:21
So this seems like a behavior change that I don't
benjhayden
2012/09/12 18:17:25
Done.
| |
| 628 download_manager_->GetActiveDownloadItem(download_id); | |
| 629 if (!download) | 628 if (!download) |
| 630 return; | 629 return; |
| 631 | 630 |
| 632 VLOG(2) << __FUNCTION__ << "() download = " << download->DebugString(false) | 631 VLOG(2) << __FUNCTION__ << "() download = " << download->DebugString(false) |
| 633 << " verdict = " << result; | 632 << " verdict = " << result; |
| 634 content::DownloadDangerType danger_type = download->GetDangerType(); | 633 content::DownloadDangerType danger_type = download->GetDangerType(); |
| 635 if (result != DownloadProtectionService::SAFE) | 634 if (result != DownloadProtectionService::SAFE) |
| 636 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL; | 635 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL; |
| 637 | 636 |
| 638 download_history_->CheckVisitedReferrerBefore( | 637 download_history_->CheckVisitedReferrerBefore( |
| 639 download_id, download->GetReferrerUrl(), | 638 download_id, download->GetReferrerUrl(), |
| 640 base::Bind(&ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone, | 639 base::Bind(&ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone, |
| 641 this, download_id, callback, danger_type)); | 640 this, download_id, callback, danger_type)); |
| 642 } | 641 } |
| 643 | 642 |
| 644 void ChromeDownloadManagerDelegate::CheckClientDownloadDone( | 643 void ChromeDownloadManagerDelegate::CheckClientDownloadDone( |
| 645 int32 download_id, | 644 int32 download_id, |
| 646 DownloadProtectionService::DownloadCheckResult result) { | 645 DownloadProtectionService::DownloadCheckResult result) { |
| 647 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); | 646 DownloadItem* item = download_manager_->GetDownload(download_id); |
| 648 if (!item) | 647 if (!item) |
| 649 return; | 648 return; |
| 650 | 649 |
| 651 VLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false) | 650 VLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false) |
| 652 << " verdict = " << result; | 651 << " verdict = " << result; |
| 653 // We only mark the content as being dangerous if the download's safety state | 652 // We only mark the content as being dangerous if the download's safety state |
| 654 // has not been set to DANGEROUS yet. We don't want to show two warnings. | 653 // has not been set to DANGEROUS yet. We don't want to show two warnings. |
| 655 if (item->GetSafetyState() == DownloadItem::SAFE) { | 654 if (item->GetSafetyState() == DownloadItem::SAFE) { |
| 656 switch (result) { | 655 switch (result) { |
| 657 case DownloadProtectionService::SAFE: | 656 case DownloadProtectionService::SAFE: |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 682 | 681 |
| 683 registrar_.Remove(this, | 682 registrar_.Remove(this, |
| 684 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 683 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 685 source); | 684 source); |
| 686 | 685 |
| 687 scoped_refptr<extensions::CrxInstaller> installer = | 686 scoped_refptr<extensions::CrxInstaller> installer = |
| 688 content::Source<extensions::CrxInstaller>(source).ptr(); | 687 content::Source<extensions::CrxInstaller>(source).ptr(); |
| 689 int download_id = crx_installers_[installer]; | 688 int download_id = crx_installers_[installer]; |
| 690 crx_installers_.erase(installer.get()); | 689 crx_installers_.erase(installer.get()); |
| 691 | 690 |
| 692 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); | 691 DownloadItem* item = download_manager_->GetDownload(download_id); |
| 693 if (item) | 692 if (item) |
| 694 item->DelayedDownloadOpened(installer->did_handle_successfully()); | 693 item->DelayedDownloadOpened(installer->did_handle_successfully()); |
| 695 } | 694 } |
| 696 | 695 |
| 697 void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( | 696 void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( |
| 698 int32 download_id, | 697 int32 download_id, |
| 699 const content::DownloadTargetCallback& callback, | 698 const content::DownloadTargetCallback& callback, |
| 700 content::DownloadDangerType danger_type, | 699 content::DownloadDangerType danger_type, |
| 701 bool visited_referrer_before) { | 700 bool visited_referrer_before) { |
| 702 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 701 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 703 | 702 |
| 704 DownloadItem* download = | 703 DownloadItem* download = |
| 705 download_manager_->GetActiveDownloadItem(download_id); | 704 download_manager_->GetDownload(download_id); |
| 706 if (!download) | 705 if (!download) |
| 707 return; | 706 return; |
| 708 | 707 |
| 709 bool should_prompt = (download->GetTargetDisposition() == | 708 bool should_prompt = (download->GetTargetDisposition() == |
| 710 DownloadItem::TARGET_DISPOSITION_PROMPT); | 709 DownloadItem::TARGET_DISPOSITION_PROMPT); |
| 711 bool is_forced_path = !download->GetForcedFilePath().empty(); | 710 bool is_forced_path = !download->GetForcedFilePath().empty(); |
| 712 FilePath suggested_path; | 711 FilePath suggested_path; |
| 713 | 712 |
| 714 // Check whether this download is for an extension install or not. | 713 // Check whether this download is for an extension install or not. |
| 715 // Allow extensions to be explicitly saved. | 714 // Allow extensions to be explicitly saved. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 806 // TODO(asanka): Merge this logic with the logic in DownloadFilePickerChromeOS. | 805 // TODO(asanka): Merge this logic with the logic in DownloadFilePickerChromeOS. |
| 807 void ChromeDownloadManagerDelegate::SubstituteDriveDownloadPathCallback( | 806 void ChromeDownloadManagerDelegate::SubstituteDriveDownloadPathCallback( |
| 808 int32 download_id, | 807 int32 download_id, |
| 809 const content::DownloadTargetCallback& callback, | 808 const content::DownloadTargetCallback& callback, |
| 810 bool should_prompt, | 809 bool should_prompt, |
| 811 bool is_forced_path, | 810 bool is_forced_path, |
| 812 content::DownloadDangerType danger_type, | 811 content::DownloadDangerType danger_type, |
| 813 const FilePath& suggested_path) { | 812 const FilePath& suggested_path) { |
| 814 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 813 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 815 DownloadItem* download = | 814 DownloadItem* download = |
| 816 download_manager_->GetActiveDownloadItem(download_id); | 815 download_manager_->GetDownload(download_id); |
| 817 if (!download) | 816 if (!download) |
| 818 return; | 817 return; |
| 819 | 818 |
| 820 GetReservedPath( | 819 GetReservedPath( |
| 821 *download, suggested_path, download_prefs_->DownloadPath(), | 820 *download, suggested_path, download_prefs_->DownloadPath(), |
| 822 !is_forced_path, | 821 !is_forced_path, |
| 823 base::Bind(&ChromeDownloadManagerDelegate::OnPathReservationAvailable, | 822 base::Bind(&ChromeDownloadManagerDelegate::OnPathReservationAvailable, |
| 824 this, download->GetId(), callback, should_prompt, | 823 this, download->GetId(), callback, should_prompt, |
| 825 danger_type)); | 824 danger_type)); |
| 826 } | 825 } |
| 827 #endif | 826 #endif |
| 828 | 827 |
| 829 void ChromeDownloadManagerDelegate::OnPathReservationAvailable( | 828 void ChromeDownloadManagerDelegate::OnPathReservationAvailable( |
| 830 int32 download_id, | 829 int32 download_id, |
| 831 const content::DownloadTargetCallback& callback, | 830 const content::DownloadTargetCallback& callback, |
| 832 bool should_prompt, | 831 bool should_prompt, |
| 833 content::DownloadDangerType danger_type, | 832 content::DownloadDangerType danger_type, |
| 834 const FilePath& reserved_path, | 833 const FilePath& reserved_path, |
| 835 bool reserved_path_verified) { | 834 bool reserved_path_verified) { |
| 836 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 835 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 837 DownloadItem* download = | 836 DownloadItem* download = |
| 838 download_manager_->GetActiveDownloadItem(download_id); | 837 download_manager_->GetDownload(download_id); |
| 839 if (!download) | 838 if (!download) |
| 840 return; | 839 return; |
| 841 if (should_prompt || !reserved_path_verified) { | 840 if (should_prompt || !reserved_path_verified) { |
| 842 // If the target path could not be verified then the path was non-existant, | 841 // If the target path could not be verified then the path was non-existant, |
| 843 // non writeable or could not be uniquified. Prompt the user. | 842 // non writeable or could not be uniquified. Prompt the user. |
| 844 ChooseDownloadPath( | 843 ChooseDownloadPath( |
| 845 download, reserved_path, | 844 download, reserved_path, |
| 846 base::Bind(&ChromeDownloadManagerDelegate::OnTargetPathDetermined, | 845 base::Bind(&ChromeDownloadManagerDelegate::OnTargetPathDetermined, |
| 847 this, download_id, callback, | 846 this, download_id, callback, |
| 848 DownloadItem::TARGET_DISPOSITION_PROMPT, danger_type)); | 847 DownloadItem::TARGET_DISPOSITION_PROMPT, danger_type)); |
| 849 } else { | 848 } else { |
| 850 OnTargetPathDetermined(download_id, callback, | 849 OnTargetPathDetermined(download_id, callback, |
| 851 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 850 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 852 danger_type, reserved_path); | 851 danger_type, reserved_path); |
| 853 } | 852 } |
| 854 } | 853 } |
| 855 | 854 |
| 856 void ChromeDownloadManagerDelegate::OnTargetPathDetermined( | 855 void ChromeDownloadManagerDelegate::OnTargetPathDetermined( |
| 857 int32 download_id, | 856 int32 download_id, |
| 858 const content::DownloadTargetCallback& callback, | 857 const content::DownloadTargetCallback& callback, |
| 859 DownloadItem::TargetDisposition disposition, | 858 DownloadItem::TargetDisposition disposition, |
| 860 content::DownloadDangerType danger_type, | 859 content::DownloadDangerType danger_type, |
| 861 const FilePath& target_path) { | 860 const FilePath& target_path) { |
| 862 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 861 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 863 FilePath intermediate_path; | 862 FilePath intermediate_path; |
| 864 DownloadItem* download = | 863 DownloadItem* download = |
| 865 download_manager_->GetActiveDownloadItem(download_id); | 864 download_manager_->GetDownload(download_id); |
| 866 if (!download) | 865 if (!download) |
| 867 return; | 866 return; |
| 868 | 867 |
| 869 // If |target_path| is empty, then that means that the user wants to cancel | 868 // If |target_path| is empty, then that means that the user wants to cancel |
| 870 // the download. | 869 // the download. |
| 871 if (!target_path.empty()) { | 870 if (!target_path.empty()) { |
| 872 intermediate_path = GetIntermediatePath(target_path, danger_type); | 871 intermediate_path = GetIntermediatePath(target_path, danger_type); |
| 873 | 872 |
| 874 // Retain the last directory. Exclude temporary downloads since the path | 873 // Retain the last directory. Exclude temporary downloads since the path |
| 875 // likely points at the location of a temporary file. | 874 // likely points at the location of a temporary file. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 888 int32 download_id, int64 db_handle) { | 887 int32 download_id, int64 db_handle) { |
| 889 // It's not immediately obvious, but HistoryBackend::CreateDownload() can | 888 // It's not immediately obvious, but HistoryBackend::CreateDownload() can |
| 890 // call this function with an invalid |db_handle|. For instance, this can | 889 // call this function with an invalid |db_handle|. For instance, this can |
| 891 // happen when the history database is offline. We cannot have multiple | 890 // happen when the history database is offline. We cannot have multiple |
| 892 // DownloadItems with the same invalid db_handle, so we need to assign a | 891 // DownloadItems with the same invalid db_handle, so we need to assign a |
| 893 // unique |db_handle| here. | 892 // unique |db_handle| here. |
| 894 if (db_handle == DownloadItem::kUninitializedHandle) | 893 if (db_handle == DownloadItem::kUninitializedHandle) |
| 895 db_handle = download_history_->GetNextFakeDbHandle(); | 894 db_handle = download_history_->GetNextFakeDbHandle(); |
| 896 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); | 895 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); |
| 897 } | 896 } |
| OLD | NEW |