OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_TEST_DOWNLOAD_TEST_OBSERVER_H_ | 5 #ifndef CONTENT_TEST_DOWNLOAD_TEST_OBSERVER_H_ |
6 #define CONTENT_TEST_DOWNLOAD_TEST_OBSERVER_H_ | 6 #define CONTENT_TEST_DOWNLOAD_TEST_OBSERVER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback_forward.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "content/public/browser/download_item.h" | 14 #include "content/public/browser/download_item.h" |
14 #include "content/public/browser/download_manager.h" | 15 #include "content/public/browser/download_manager.h" |
15 #include "content/public/browser/download_url_parameters.h" | 16 #include "content/public/browser/download_url_parameters.h" |
16 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
| 21 // Detects an arbitrary change on a download item. |
| 22 // TODO: Rewrite other observers to use this (or be replaced by it). |
| 23 class DownloadUpdatedObserver : public DownloadItem::Observer { |
| 24 public: |
| 25 typedef base::Callback<bool(DownloadItem*)> EventFilter; |
| 26 |
| 27 // The filter passed may be called multiple times, even after it |
| 28 // returns true. |
| 29 DownloadUpdatedObserver(DownloadItem* item, EventFilter filter); |
| 30 virtual ~DownloadUpdatedObserver(); |
| 31 |
| 32 // Returns when either the event has been seen (at least once since |
| 33 // object construction) or the item is destroyed. Return value indicates |
| 34 // if the wait ended because the item was seen (true) or the object |
| 35 // destroyed (false). |
| 36 bool WaitForEvent(); |
| 37 |
| 38 private: |
| 39 // DownloadItem::Observer |
| 40 virtual void OnDownloadUpdated(DownloadItem* item) OVERRIDE; |
| 41 virtual void OnDownloadDestroyed(DownloadItem* item) OVERRIDE; |
| 42 |
| 43 DownloadItem* item_; |
| 44 EventFilter filter_; |
| 45 bool waiting_; |
| 46 bool event_seen_; |
| 47 |
| 48 DISALLOW_COPY_AND_ASSIGN(DownloadUpdatedObserver); |
| 49 }; |
| 50 |
20 // Detects changes to the downloads after construction. | 51 // Detects changes to the downloads after construction. |
21 // Finishes when one of the following happens: | 52 // Finishes when one of the following happens: |
22 // - A specified number of downloads change to a terminal state (defined | 53 // - A specified number of downloads change to a terminal state (defined |
23 // in derived classes). | 54 // in derived classes). |
24 // - Specific events, such as a select file dialog. | 55 // - Specific events, such as a select file dialog. |
25 // Callers may either probe for the finished state, or wait on it. | 56 // Callers may either probe for the finished state, or wait on it. |
26 // | 57 // |
27 // TODO(rdsmith): Detect manager going down, remove pointer to | 58 // TODO(rdsmith): Detect manager going down, remove pointer to |
28 // DownloadManager, transition to finished. (For right now we | 59 // DownloadManager, transition to finished. (For right now we |
29 // just use a scoped_refptr<> to keep it around, but that may cause | 60 // just use a scoped_refptr<> to keep it around, but that may cause |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 285 |
255 // We are in the message loop. | 286 // We are in the message loop. |
256 bool waiting_; | 287 bool waiting_; |
257 | 288 |
258 DISALLOW_COPY_AND_ASSIGN(DownloadTestItemCreationObserver); | 289 DISALLOW_COPY_AND_ASSIGN(DownloadTestItemCreationObserver); |
259 }; | 290 }; |
260 | 291 |
261 } // namespace content` | 292 } // namespace content` |
262 | 293 |
263 #endif // CONTENT_TEST_DOWNLOAD_TEST_OBSERVER_H_ | 294 #endif // CONTENT_TEST_DOWNLOAD_TEST_OBSERVER_H_ |
OLD | NEW |