Chromium Code Reviews| 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 85caf410ade5d3706840c7ca8ac9ebf8c7d99b43..b35aa78889d2d9b5b4b01d67dedc009e49ee60ba 100644 |
| --- a/content/public/test/download_test_observer.cc |
| +++ b/content/public/test/download_test_observer.cc |
| @@ -44,6 +44,45 @@ void DenyDangerousDownload(scoped_refptr<DownloadManager> download_manager, |
| } // namespace |
| +DownloadUpdatedObserver::DownloadUpdatedObserver( |
| + DownloadItem* item, DownloadUpdatedObserver::EventFilter filter) |
| + : item_(item), filter_(filter), waiting_(false) { |
| + item->AddObserver(this); |
| +} |
| + |
| +DownloadUpdatedObserver::~DownloadUpdatedObserver() { |
| + if (item_) |
| + item_->RemoveObserver(this); |
| +} |
| + |
| +bool DownloadUpdatedObserver::WaitForEvent() { |
| + if (item_ && filter_.Run(item_)) |
| + return true; |
| + |
| + waiting_ = true; |
| + RunMessageLoop(); |
| + waiting_ = false; |
| + |
| + if (!item_) |
| + return false; |
| + |
| + return true; |
|
benjhayden
2012/09/10 14:48:52
Are you sure that OnDownloadDestroyed() will never
Randy Smith (Not in Mondays)
2012/09/10 17:16:42
I'm not quite sure the race you're protecting agai
|
| +} |
| + |
| +void DownloadUpdatedObserver::OnDownloadUpdated(DownloadItem* item) { |
| + DCHECK_EQ(item_, item); |
| + if (waiting_ && filter_.Run(item_)) |
| + MessageLoopForUI::current()->Quit(); |
| +} |
| + |
| +void DownloadUpdatedObserver::OnDownloadDestroyed(DownloadItem* item) { |
| + DCHECK_EQ(item_, item); |
| + item_->RemoveObserver(this); |
| + item_ = NULL; |
| + if (waiting_) |
| + MessageLoopForUI::current()->Quit(); |
| +} |
| + |
| DownloadTestObserver::DownloadTestObserver( |
| DownloadManager* download_manager, |
| size_t wait_count, |