| 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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 // Waits for a callback indicating that the DownloadItem is about to be created, | 274 // Waits for a callback indicating that the DownloadItem is about to be created, |
| 275 // or that an error occurred and it won't be created. | 275 // or that an error occurred and it won't be created. |
| 276 class DownloadTestItemCreationObserver | 276 class DownloadTestItemCreationObserver |
| 277 : public base::RefCountedThreadSafe<DownloadTestItemCreationObserver> { | 277 : public base::RefCountedThreadSafe<DownloadTestItemCreationObserver> { |
| 278 public: | 278 public: |
| 279 DownloadTestItemCreationObserver(); | 279 DownloadTestItemCreationObserver(); |
| 280 | 280 |
| 281 void WaitForDownloadItemCreation(); | 281 void WaitForDownloadItemCreation(); |
| 282 | 282 |
| 283 uint32 download_id() const { return download_id_; } | 283 uint32 download_id() const { return download_id_; } |
| 284 net::Error error() const { return error_; } | 284 DownloadInterruptReason interrupt_reason() const { return interrupt_reason_; } |
| 285 bool started() const { return called_back_count_ > 0; } | 285 bool started() const { return called_back_count_ > 0; } |
| 286 bool succeeded() const { return started() && (error_ == net::OK); } | 286 bool succeeded() const { |
| 287 return started() && interrupt_reason_ == DOWNLOAD_INTERRUPT_REASON_NONE; |
| 288 } |
| 287 | 289 |
| 288 const DownloadUrlParameters::OnStartedCallback callback(); | 290 const DownloadUrlParameters::OnStartedCallback callback(); |
| 289 | 291 |
| 290 private: | 292 private: |
| 291 friend class base::RefCountedThreadSafe<DownloadTestItemCreationObserver>; | 293 friend class base::RefCountedThreadSafe<DownloadTestItemCreationObserver>; |
| 292 | 294 |
| 293 ~DownloadTestItemCreationObserver(); | 295 ~DownloadTestItemCreationObserver(); |
| 294 | 296 |
| 295 void DownloadItemCreationCallback(DownloadItem* item, net::Error error); | 297 void DownloadItemCreationCallback(DownloadItem* item, |
| 298 DownloadInterruptReason interrupt_reason); |
| 296 | 299 |
| 297 // The download creation information we received. | 300 // The download creation information we received. |
| 298 uint32 download_id_; | 301 uint32 download_id_; |
| 299 net::Error error_; | 302 DownloadInterruptReason interrupt_reason_; |
| 300 | 303 |
| 301 // Count of callbacks. | 304 // Count of callbacks. |
| 302 size_t called_back_count_; | 305 size_t called_back_count_; |
| 303 | 306 |
| 304 // We are in the message loop. | 307 // We are in the message loop. |
| 305 bool waiting_; | 308 bool waiting_; |
| 306 | 309 |
| 307 DISALLOW_COPY_AND_ASSIGN(DownloadTestItemCreationObserver); | 310 DISALLOW_COPY_AND_ASSIGN(DownloadTestItemCreationObserver); |
| 308 }; | 311 }; |
| 309 | 312 |
| 310 } // namespace content` | 313 } // namespace content` |
| 311 | 314 |
| 312 #endif // CONTENT_TEST_DOWNLOAD_TEST_OBSERVER_H_ | 315 #endif // CONTENT_TEST_DOWNLOAD_TEST_OBSERVER_H_ |
| OLD | NEW |