Put in CHECK() statements confirm DownloadItem threading and destruction.

BUG=85408
TEST=Try bots.


Review URL: http://codereview.chromium.org/7104091

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88717 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc
index 7475915..8724641 100644
--- a/chrome/browser/download/download_manager.cc
+++ b/chrome/browser/download/download_manager.cc
@@ -114,14 +114,19 @@
   // 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.
-  STLDeleteElements(&downloads_);
 
-  // And clear all non-owning containers.
+  // Copy downloads_ to separate container so as not to set off checks
+  // in DownloadItem destruction.
+  DownloadSet downloads_to_delete;
+  downloads_to_delete.swap(downloads_);
+
   in_progress_.clear();
   active_downloads_.clear();
+  history_downloads_.clear();
 #if !defined(NDEBUG)
   save_page_as_downloads_.clear();
 #endif
+  STLDeleteElements(&downloads_to_delete);
 
   file_manager_ = NULL;
 
@@ -639,6 +644,14 @@
            << active_downloads_[download_id]->GetURL().spec();
 }
 
+void DownloadManager::AssertNotInQueues(DownloadItem* download) {
+  // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
+  CHECK(!ContainsKey(downloads_, download));
+  CHECK(!ContainsKey(active_downloads_, download->id()));
+  CHECK(!ContainsKey(in_progress_, download->id()));
+  CHECK(!ContainsKey(history_downloads_, download->db_handle()));
+}
+
 bool DownloadManager::IsDownloadReadyForCompletion(DownloadItem* download) {
   // If we don't have all the data, the download is not ready for
   // completion.