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/callback_forward.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "content/public/browser/download_interrupt_reasons.h" |
14 #include "content/public/browser/download_item.h" | 15 #include "content/public/browser/download_item.h" |
15 #include "content/public/browser/download_manager.h" | 16 #include "content/public/browser/download_manager.h" |
16 #include "content/public/browser/download_url_parameters.h" | 17 #include "content/public/browser/download_url_parameters.h" |
17 #include "net/base/net_errors.h" | |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
21 // Detects an arbitrary change on a download item. | 21 // Detects an arbitrary change on a download item. |
22 // TODO: Rewrite other observers to use this (or be replaced by it). | 22 // TODO: Rewrite other observers to use this (or be replaced by it). |
23 class DownloadUpdatedObserver : public DownloadItem::Observer { | 23 class DownloadUpdatedObserver : public DownloadItem::Observer { |
24 public: | 24 public: |
25 typedef base::Callback<bool(DownloadItem*)> EventFilter; | 25 typedef base::Callback<bool(DownloadItem*)> EventFilter; |
26 | 26 |
27 // The filter passed may be called multiple times, even after it | 27 // The filter passed may be called multiple times, even after it |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 // Waits for a callback indicating that the DownloadItem is about to be created, | 275 // Waits for a callback indicating that the DownloadItem is about to be created, |
276 // or that an error occurred and it won't be created. | 276 // or that an error occurred and it won't be created. |
277 class DownloadTestItemCreationObserver | 277 class DownloadTestItemCreationObserver |
278 : public base::RefCountedThreadSafe<DownloadTestItemCreationObserver> { | 278 : public base::RefCountedThreadSafe<DownloadTestItemCreationObserver> { |
279 public: | 279 public: |
280 DownloadTestItemCreationObserver(); | 280 DownloadTestItemCreationObserver(); |
281 | 281 |
282 void WaitForDownloadItemCreation(); | 282 void WaitForDownloadItemCreation(); |
283 | 283 |
284 uint32 download_id() const { return download_id_; } | 284 uint32 download_id() const { return download_id_; } |
285 net::Error error() const { return error_; } | 285 DownloadInterruptReason interrupt_reason() const { return interrupt_reason_; } |
286 bool started() const { return called_back_count_ > 0; } | 286 bool started() const { return called_back_count_ > 0; } |
287 bool succeeded() const { return started() && (error_ == net::OK); } | 287 bool succeeded() const { |
| 288 return started() && interrupt_reason_ == DOWNLOAD_INTERRUPT_REASON_NONE; |
| 289 } |
288 | 290 |
289 const DownloadUrlParameters::OnStartedCallback callback(); | 291 const DownloadUrlParameters::OnStartedCallback callback(); |
290 | 292 |
291 private: | 293 private: |
292 friend class base::RefCountedThreadSafe<DownloadTestItemCreationObserver>; | 294 friend class base::RefCountedThreadSafe<DownloadTestItemCreationObserver>; |
293 | 295 |
294 ~DownloadTestItemCreationObserver(); | 296 ~DownloadTestItemCreationObserver(); |
295 | 297 |
296 void DownloadItemCreationCallback(DownloadItem* item, net::Error error); | 298 void DownloadItemCreationCallback(DownloadItem* item, |
| 299 DownloadInterruptReason interrupt_reason); |
297 | 300 |
298 // The download creation information we received. | 301 // The download creation information we received. |
299 uint32 download_id_; | 302 uint32 download_id_; |
300 net::Error error_; | 303 DownloadInterruptReason interrupt_reason_; |
301 | 304 |
302 // Count of callbacks. | 305 // Count of callbacks. |
303 size_t called_back_count_; | 306 size_t called_back_count_; |
304 | 307 |
305 // We are in the message loop. | 308 // We are in the message loop. |
306 bool waiting_; | 309 bool waiting_; |
307 | 310 |
308 DISALLOW_COPY_AND_ASSIGN(DownloadTestItemCreationObserver); | 311 DISALLOW_COPY_AND_ASSIGN(DownloadTestItemCreationObserver); |
309 }; | 312 }; |
310 | 313 |
311 } // namespace content` | 314 } // namespace content` |
312 | 315 |
313 #endif // CONTENT_TEST_DOWNLOAD_TEST_OBSERVER_H_ | 316 #endif // CONTENT_TEST_DOWNLOAD_TEST_OBSERVER_H_ |
OLD | NEW |