Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(875)

Unified Diff: content/public/test/download_test_observer.cc

Issue 10918136: Make web store resilient against download completion happening before opening. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated comment. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/public/test/download_test_observer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..974f6446456b5e4241b696616c05650093929453 100644
--- a/content/public/test/download_test_observer.cc
+++ b/content/public/test/download_test_observer.cc
@@ -44,6 +44,48 @@ void DenyDangerousDownload(scoped_refptr<DownloadManager> download_manager,
} // namespace
+DownloadUpdatedObserver::DownloadUpdatedObserver(
+ DownloadItem* item, DownloadUpdatedObserver::EventFilter filter)
+ : item_(item),
+ filter_(filter),
+ waiting_(false),
+ event_seen_(false) {
+ item->AddObserver(this);
+}
+
+DownloadUpdatedObserver::~DownloadUpdatedObserver() {
+ if (item_)
+ item_->RemoveObserver(this);
+}
+
+bool DownloadUpdatedObserver::WaitForEvent() {
+ if (item_ && filter_.Run(item_))
+ event_seen_ = true;
+ if (event_seen_)
+ return true;
+
+ waiting_ = true;
+ RunMessageLoop();
+ waiting_ = false;
+ return event_seen_;
+}
+
+void DownloadUpdatedObserver::OnDownloadUpdated(DownloadItem* item) {
+ DCHECK_EQ(item_, item);
+ if (filter_.Run(item_))
+ event_seen_ = true;
+ if (waiting_ && event_seen_)
+ 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,
« no previous file with comments | « content/public/test/download_test_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698