| 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 ~DownloadUpdatedObserver(); |
| 31 |
| 32 // Returns false if the waiting ended because of the destruction of the |
| 33 // DownloadItem rather than because of the expected event occuring. |
| 34 bool WaitForEvent(); |
| 35 |
| 36 private: |
| 37 // DownloadItem::Observer |
| 38 void OnDownloadUpdated(DownloadItem* item) OVERRIDE; |
| 39 void OnDownloadDestroyed(DownloadItem* item) OVERRIDE; |
| 40 |
| 41 DownloadItem* item_; |
| 42 EventFilter filter_; |
| 43 bool waiting_; |
| 44 bool event_seen_; |
| 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(DownloadUpdatedObserver); |
| 47 }; |
| 48 |
| 20 // Detects changes to the downloads after construction. | 49 // Detects changes to the downloads after construction. |
| 21 // Finishes when one of the following happens: | 50 // Finishes when one of the following happens: |
| 22 // - A specified number of downloads change to a terminal state (defined | 51 // - A specified number of downloads change to a terminal state (defined |
| 23 // in derived classes). | 52 // in derived classes). |
| 24 // - Specific events, such as a select file dialog. | 53 // - Specific events, such as a select file dialog. |
| 25 // Callers may either probe for the finished state, or wait on it. | 54 // Callers may either probe for the finished state, or wait on it. |
| 26 // | 55 // |
| 27 // TODO(rdsmith): Detect manager going down, remove pointer to | 56 // TODO(rdsmith): Detect manager going down, remove pointer to |
| 28 // DownloadManager, transition to finished. (For right now we | 57 // DownloadManager, transition to finished. (For right now we |
| 29 // just use a scoped_refptr<> to keep it around, but that may cause | 58 // 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 | 283 |
| 255 // We are in the message loop. | 284 // We are in the message loop. |
| 256 bool waiting_; | 285 bool waiting_; |
| 257 | 286 |
| 258 DISALLOW_COPY_AND_ASSIGN(DownloadTestItemCreationObserver); | 287 DISALLOW_COPY_AND_ASSIGN(DownloadTestItemCreationObserver); |
| 259 }; | 288 }; |
| 260 | 289 |
| 261 } // namespace content` | 290 } // namespace content` |
| 262 | 291 |
| 263 #endif // CONTENT_TEST_DOWNLOAD_TEST_OBSERVER_H_ | 292 #endif // CONTENT_TEST_DOWNLOAD_TEST_OBSERVER_H_ |
| OLD | NEW |