[Downloads] Allow acquiring dangerous download file.
A dangerous download can be accepted by the user or rejected. If
rejected, the downloaded file used to be deleted. This change adds
DownloadItem::AcquireFileAndDeleteDownload() which allows the caller to
acquire the dangerous file.
The intended consumer of this feature is SafeBrowsing where the caller
may want to acquire a dangerous file that's being discarded for the
purpose of further analysis.
Also change the logic during shutdown to no longer delete dangerous
downloads, but to cancel them.
TBR=rdsmith
BUG=244604
Review URL: https://chromiumcodereview.appspot.com/14947007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202925 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/content/browser/download/download_manager_impl.cc b/content/browser/download/download_manager_impl.cc
index 16d1b29..7a2336e1 100644
--- a/content/browser/download/download_manager_impl.cc
+++ b/content/browser/download/download_manager_impl.cc
@@ -335,35 +335,16 @@
FOR_EACH_OBSERVER(Observer, observers_, ManagerGoingDown(this));
// TODO(benjhayden): Consider clearing observers_.
- // Go through all downloads in downloads_. Dangerous ones we need to
- // remove on disk, and in progress ones we need to cancel.
- for (DownloadMap::iterator it = downloads_.begin(); it != downloads_.end();) {
+ // If there are in-progress downloads, cancel them. This also goes for
+ // dangerous downloads which will remain in history if they aren't explicitly
+ // accepted or discarded. Canceling will remove the intermediate download
+ // file.
+ for (DownloadMap::iterator it = downloads_.begin(); it != downloads_.end();
+ ++it) {
DownloadItemImpl* download = it->second;
-
- // Save iterator from potential erases in this set done by called code.
- // Iterators after an erasure point are still valid for lists and
- // associative containers such as sets.
- it++;
-
- if (download->IsDangerous() && download->IsPartialDownload()) {
- // The user hasn't accepted it, so we need to remove it
- // from the disk. This may or may not result in it being
- // removed from the DownloadManager queues and deleted
- // (specifically, DownloadManager::DownloadRemoved only
- // removes and deletes it if it's known to the history service)
- // so the only thing we know after calling this function is that
- // the download was deleted if-and-only-if it was removed
- // from all queues.
- download->Delete(DownloadItem::DELETE_DUE_TO_BROWSER_SHUTDOWN);
- } else if (download->IsPartialDownload()) {
+ if (download->GetState() == DownloadItem::IN_PROGRESS)
download->Cancel(false);
- }
}
-
- // At this point, all dangerous downloads have had their files removed
- // and all in progress downloads have been cancelled. We can now delete
- // anything left.
-
STLDeleteValues(&downloads_);
downloads_.clear();