Index: content/public/test/download_test_observer.cc |
diff --git a/content/public/test/download_test_observer.cc b/content/public/test/download_test_observer.cc |
index 17d763efb5a33e8bc2a1b7f1e01a5b84cdb71ab4..7817f8355d93dd3cb0470273935e82b692856eca 100644 |
--- a/content/public/test/download_test_observer.cc |
+++ b/content/public/test/download_test_observer.cc |
@@ -18,6 +18,33 @@ |
namespace content { |
+namespace { |
+ |
+// These functions take scoped_refptr's to DownloadManager because they |
+// are posted to message queues, and hence may execute arbitrarily after |
+// their actual posting. Once posted, there is no connection between |
+// these routines and the DownloadTestObserver class from which |
+// they came, so the DownloadTestObserver's reference to the |
+// DownloadManager cannot be counted on to keep the DownloadManager around. |
+ |
+// Fake user click on "Accept". |
+void AcceptDangerousDownload(scoped_refptr<DownloadManager> download_manager, |
+ int32 download_id) { |
+ DownloadItem* download = download_manager->GetDownload(download_id); |
+ if (download && (download->GetState() == DownloadItem::IN_PROGRESS)) |
+ download->ValidateDangerousDownload(); |
+} |
+ |
+// Fake user click on "Deny". |
+void DenyDangerousDownload(scoped_refptr<DownloadManager> download_manager, |
+ int32 download_id) { |
+ DownloadItem* download = download_manager->GetDownload(download_id); |
+ if (download && (download->GetState() == DownloadItem::IN_PROGRESS)) |
+ download->Remove(); |
+} |
+ |
+} // namespace |
+ |
DownloadUpdatedObserver::DownloadUpdatedObserver( |
DownloadItem* item, DownloadUpdatedObserver::EventFilter filter) |
: item_(item), |
@@ -141,7 +168,7 @@ void DownloadTestObserver::OnDownloadUpdated(DownloadItem* download) { |
!ContainsKey(dangerous_downloads_seen_, download->GetId())) { |
dangerous_downloads_seen_.insert(download->GetId()); |
- // Calling DangerousDownloadValidated() at this point will |
+ // Calling ValidateDangerousDownload() at this point will |
// cause the download to be completed twice. Do what the real UI |
// code does: make the call as a delayed task. |
switch (dangerous_download_action_) { |
@@ -222,7 +249,7 @@ void DownloadTestObserver::AcceptDangerousDownload(int32 download_id) { |
return; |
DownloadItem* download = download_manager_->GetDownload(download_id); |
if (download && (download->GetState() == DownloadItem::IN_PROGRESS)) |
- download->DangerousDownloadValidated(); |
+ download->ValidateDangerousDownload(); |
} |
void DownloadTestObserver::DenyDangerousDownload(int32 download_id) { |
@@ -232,8 +259,7 @@ void DownloadTestObserver::DenyDangerousDownload(int32 download_id) { |
return; |
DownloadItem* download = download_manager_->GetDownload(download_id); |
if (download && (download->GetState() == DownloadItem::IN_PROGRESS)) { |
- download->Cancel(true); |
- download->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
+ download->Remove(); |
} |
} |