| 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 974f6446456b5e4241b696616c05650093929453..6455027ef6d6c9c32324d9d1a546879866a4d1bb 100644
|
| --- a/content/public/test/download_test_observer.cc
|
| +++ b/content/public/test/download_test_observer.cc
|
| @@ -29,17 +29,19 @@ namespace {
|
| // Fake user click on "Accept".
|
| void AcceptDangerousDownload(scoped_refptr<DownloadManager> download_manager,
|
| int32 download_id) {
|
| - DownloadItem* download = download_manager->GetDownloadItem(download_id);
|
| - download->DangerousDownloadValidated();
|
| + 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->GetDownloadItem(download_id);
|
| - ASSERT_TRUE(download->IsPartialDownload());
|
| - download->Cancel(true);
|
| - download->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
|
| + 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
|
| @@ -106,7 +108,27 @@ DownloadTestObserver::~DownloadTestObserver() {
|
| }
|
|
|
| void DownloadTestObserver::Init() {
|
| - download_manager_->AddObserver(this); // Will call initial ModelChanged().
|
| + download_manager_->AddObserver(this);
|
| + // Regenerate DownloadItem observers. If there are any download items
|
| + // in our final state, note them in |finished_downloads_|
|
| + // (done by |OnDownloadUpdated()|).
|
| + std::vector<DownloadItem*> downloads;
|
| + download_manager_->GetAllDownloads(&downloads);
|
| +
|
| + for (std::vector<DownloadItem*>::iterator it = downloads.begin();
|
| + it != downloads.end(); ++it) {
|
| + OnDownloadUpdated(*it); // Safe to call multiple times; checks state.
|
| +
|
| + DownloadSet::const_iterator finished_it(finished_downloads_.find(*it));
|
| + DownloadSet::iterator observed_it(downloads_observed_.find(*it));
|
| +
|
| + // If it isn't finished and we're aren't observing it, start.
|
| + if (finished_it == finished_downloads_.end() &&
|
| + observed_it == downloads_observed_.end()) {
|
| + (*it)->AddObserver(this);
|
| + downloads_observed_.insert(*it);
|
| + }
|
| + }
|
| finished_downloads_at_construction_ = finished_downloads_.size();
|
| states_observed_.clear();
|
| }
|
| @@ -173,37 +195,17 @@ void DownloadTestObserver::OnDownloadUpdated(DownloadItem* download) {
|
| DownloadInFinalState(download);
|
| }
|
|
|
| -void DownloadTestObserver::ModelChanged(DownloadManager* manager) {
|
| - DCHECK_EQ(manager, download_manager_);
|
| +void DownloadTestObserver::OnDownloadCreated(
|
| + DownloadManager* manager, DownloadItem* item) {
|
| + OnDownloadUpdated(item);
|
| + DownloadSet::const_iterator finished_it(finished_downloads_.find(item));
|
| + DownloadSet::iterator observed_it(downloads_observed_.find(item));
|
|
|
| - // Regenerate DownloadItem observers. If there are any download items
|
| - // in our final state, note them in |finished_downloads_|
|
| - // (done by |OnDownloadUpdated()|).
|
| - std::vector<DownloadItem*> downloads;
|
| - download_manager_->GetAllDownloads(&downloads);
|
| -
|
| - for (std::vector<DownloadItem*>::iterator it = downloads.begin();
|
| - it != downloads.end(); ++it) {
|
| - OnDownloadUpdated(*it); // Safe to call multiple times; checks state.
|
| -
|
| - DownloadSet::const_iterator finished_it(finished_downloads_.find(*it));
|
| - DownloadSet::iterator observed_it(downloads_observed_.find(*it));
|
| -
|
| - // If it isn't finished and we're aren't observing it, start.
|
| - if (finished_it == finished_downloads_.end() &&
|
| - observed_it == downloads_observed_.end()) {
|
| - (*it)->AddObserver(this);
|
| - downloads_observed_.insert(*it);
|
| - continue;
|
| - }
|
| -
|
| - // If it is finished and we are observing it, stop.
|
| - if (finished_it != finished_downloads_.end() &&
|
| - observed_it != downloads_observed_.end()) {
|
| - (*it)->RemoveObserver(this);
|
| - downloads_observed_.erase(observed_it);
|
| - continue;
|
| - }
|
| + // If it isn't finished and we're aren't observing it, start.
|
| + if (finished_it == finished_downloads_.end() &&
|
| + observed_it == downloads_observed_.end()) {
|
| + item->AddObserver(this);
|
| + downloads_observed_.insert(item);
|
| }
|
| }
|
|
|
| @@ -283,7 +285,8 @@ DownloadTestObserverInProgress::~DownloadTestObserverInProgress() {
|
|
|
| bool DownloadTestObserverInProgress::IsDownloadInFinalState(
|
| DownloadItem* download) {
|
| - return (download->GetState() == DownloadItem::IN_PROGRESS);
|
| + return (download->GetState() == DownloadItem::IN_PROGRESS) &&
|
| + !download->GetTargetFilePath().empty();
|
| }
|
|
|
| DownloadTestFlushObserver::DownloadTestFlushObserver(
|
|
|