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