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..ec2611d1e0f36a07de8242e3fd7c78fc599e2f4f 100644 |
--- a/content/public/test/download_test_observer.cc |
+++ b/content/public/test/download_test_observer.cc |
@@ -106,7 +106,13 @@ DownloadTestObserver::~DownloadTestObserver() { |
} |
void DownloadTestObserver::Init() { |
- download_manager_->AddObserver(this); // Will call initial ModelChanged(). |
+ download_manager_->AddObserver(this); |
+ std::vector<DownloadItem*> downloads; |
+ download_manager_->GetAllDownloads(&downloads); |
+ for (std::vector<DownloadItem*>::iterator it = downloads.begin(); |
+ it != downloads.end(); ++it) { |
+ OnDownloadCreated(download_manager_, *it); |
+ } |
finished_downloads_at_construction_ = finished_downloads_.size(); |
states_observed_.clear(); |
} |
@@ -173,37 +179,26 @@ void DownloadTestObserver::OnDownloadUpdated(DownloadItem* download) { |
DownloadInFinalState(download); |
} |
-void DownloadTestObserver::ModelChanged(DownloadManager* manager) { |
+void DownloadTestObserver::OnDownloadCreated( |
+ DownloadManager* manager, DownloadItem* item) { |
DCHECK_EQ(manager, download_manager_); |
+ OnDownloadUpdated(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); |
+ DownloadSet::const_iterator finished_it(finished_downloads_.find(item)); |
+ DownloadSet::iterator observed_it(downloads_observed_.find(item)); |
- 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 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); |
+ } |
- // 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 is finished and we are observing it, stop. |
+ if (finished_it != finished_downloads_.end() && |
+ observed_it != downloads_observed_.end()) { |
+ item->RemoveObserver(this); |
+ downloads_observed_.erase(observed_it); |
} |
} |
@@ -283,7 +278,8 @@ DownloadTestObserverInProgress::~DownloadTestObserverInProgress() { |
bool DownloadTestObserverInProgress::IsDownloadInFinalState( |
DownloadItem* download) { |
- return (download->GetState() == DownloadItem::IN_PROGRESS); |
+ return (download->GetState() == DownloadItem::IN_PROGRESS) && |
+ !download->GetTargetFilePath().empty(); |
Randy Smith (Not in Mondays)
2012/09/24 18:03:25
It's in test code, so I don't have strong feelings
benjhayden
2012/09/24 20:12:11
Could this CL (DownloadHistory-is-a-Observer) wait
Randy Smith (Not in Mondays)
2012/11/02 23:31:24
I suppose, if you're volunteering. But how would
benjhayden
2012/11/06 20:01:14
Sorry, I don't know what I was thinking.
Yes, this
|
} |
DownloadTestFlushObserver::DownloadTestFlushObserver( |