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

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

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 | « chrome/browser/download/download_browsertest.cc ('k') | content/public/test/download_test_observer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/test/download_test_observer.h
diff --git a/content/public/test/download_test_observer.h b/content/public/test/download_test_observer.h
index 8df29882e721d00190c21ea4411ac1582457f614..02299cc476d5866ebcc458ad966976ba3d5fa305 100644
--- a/content/public/test/download_test_observer.h
+++ b/content/public/test/download_test_observer.h
@@ -9,6 +9,7 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/callback_forward.h"
#include "base/memory/ref_counted.h"
#include "content/public/browser/download_item.h"
#include "content/public/browser/download_manager.h"
@@ -17,6 +18,36 @@
namespace content {
+// Detects an arbitrary change on a download item.
+// TODO: Rewrite other observers to use this (or be replaced by it).
+class DownloadUpdatedObserver : public DownloadItem::Observer {
+ public:
+ typedef base::Callback<bool(DownloadItem*)> EventFilter;
+
+ // The filter passed may be called multiple times, even after it
+ // returns true.
+ DownloadUpdatedObserver(DownloadItem* item, EventFilter filter);
+ virtual ~DownloadUpdatedObserver();
+
+ // Returns when either the event has been seen (at least once since
+ // object construction) or the item is destroyed. Return value indicates
+ // if the wait ended because the item was seen (true) or the object
+ // destroyed (false).
+ bool WaitForEvent();
+
+ private:
+ // DownloadItem::Observer
+ virtual void OnDownloadUpdated(DownloadItem* item) OVERRIDE;
+ virtual void OnDownloadDestroyed(DownloadItem* item) OVERRIDE;
+
+ DownloadItem* item_;
+ EventFilter filter_;
+ bool waiting_;
+ bool event_seen_;
+
+ DISALLOW_COPY_AND_ASSIGN(DownloadUpdatedObserver);
+};
+
// Detects changes to the downloads after construction.
// Finishes when one of the following happens:
// - A specified number of downloads change to a terminal state (defined
« no previous file with comments | « chrome/browser/download/download_browsertest.cc ('k') | content/public/test/download_test_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698