| 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 3d918255c6d8f5bbd7e87f9b93dd3513e04d93c3..b8a9d1a75a79a042fece4cfe3a11365fbbfbc19b 100644
|
| --- a/content/public/test/download_test_observer.cc
|
| +++ b/content/public/test/download_test_observer.cc
|
| @@ -18,35 +18,6 @@
|
|
|
| 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->DangerousDownloadValidated();
|
| -}
|
| -
|
| -// 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->Cancel(true);
|
| - download->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
|
| - }
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| DownloadUpdatedObserver::DownloadUpdatedObserver(
|
| DownloadItem* item, DownloadUpdatedObserver::EventFilter filter)
|
| : item_(item),
|
| @@ -97,7 +68,8 @@ DownloadTestObserver::DownloadTestObserver(
|
| wait_count_(wait_count),
|
| finished_downloads_at_construction_(0),
|
| waiting_(false),
|
| - dangerous_download_action_(dangerous_download_action) {
|
| + dangerous_download_action_(dangerous_download_action),
|
| + weak_factory_(this) {
|
| }
|
|
|
| DownloadTestObserver::~DownloadTestObserver() {
|
| @@ -148,6 +120,11 @@ void DownloadTestObserver::OnDownloadCreated(
|
| }
|
| }
|
|
|
| +void DownloadTestObserver::ManagerGoingDown(DownloadManager* manager) {
|
| + ASSERT_TRUE(manager == download_manager_);
|
| + download_manager_ = NULL;
|
| +}
|
| +
|
| void DownloadTestObserver::OnDownloadDestroyed(DownloadItem* download) {
|
| // Stop observing. Do not do anything with it, as it is about to be gone.
|
| DownloadSet::iterator it = downloads_observed_.find(download);
|
| @@ -171,8 +148,8 @@ void DownloadTestObserver::OnDownloadUpdated(DownloadItem* download) {
|
| // real UI would.
|
| BrowserThread::PostTask(
|
| BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&AcceptDangerousDownload, download_manager_,
|
| - download->GetId()));
|
| + base::Bind(&DownloadTestObserver::AcceptDangerousDownload,
|
| + weak_factory_.GetWeakPtr(), download->GetId()));
|
| break;
|
|
|
| case ON_DANGEROUS_DOWNLOAD_DENY:
|
| @@ -180,8 +157,8 @@ void DownloadTestObserver::OnDownloadUpdated(DownloadItem* download) {
|
| // real UI would.
|
| BrowserThread::PostTask(
|
| BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&DenyDangerousDownload, download_manager_,
|
| - download->GetId()));
|
| + base::Bind(&DownloadTestObserver::DenyDangerousDownload,
|
| + weak_factory_.GetWeakPtr(), download->GetId()));
|
| break;
|
|
|
| case ON_DANGEROUS_DOWNLOAD_FAIL:
|
| @@ -234,6 +211,28 @@ void DownloadTestObserver::SignalIfFinished() {
|
| base::MessageLoopForUI::current()->Quit();
|
| }
|
|
|
| +void DownloadTestObserver::AcceptDangerousDownload(int32_t download_id) {
|
| + // Download manager was shutdown before the UI thread could accept
|
| + // the download.
|
| + if (!download_manager_)
|
| + return;
|
| + DownloadItem* download = download_manager_->GetDownload(download_id);
|
| + if (download && (download->GetState() == DownloadItem::IN_PROGRESS))
|
| + download->DangerousDownloadValidated();
|
| +}
|
| +
|
| +void DownloadTestObserver::DenyDangerousDownload(int32_t download_id) {
|
| + // Download manager was shutdown before the UI thread could deny the
|
| + // download.
|
| + if (!download_manager_)
|
| + 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);
|
| + }
|
| +}
|
| +
|
| DownloadTestObserverTerminal::DownloadTestObserverTerminal(
|
| DownloadManager* download_manager,
|
| size_t wait_count,
|
|
|