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 #include "content/public/test/download_test_observer.h" | 5 #include "content/public/test/download_test_observer.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 void DenyDangerousDownload(scoped_refptr<DownloadManager> download_manager, | 37 void DenyDangerousDownload(scoped_refptr<DownloadManager> download_manager, |
38 int32 download_id) { | 38 int32 download_id) { |
39 DownloadItem* download = download_manager->GetDownloadItem(download_id); | 39 DownloadItem* download = download_manager->GetDownloadItem(download_id); |
40 ASSERT_TRUE(download->IsPartialDownload()); | 40 ASSERT_TRUE(download->IsPartialDownload()); |
41 download->Cancel(true); | 41 download->Cancel(true); |
42 download->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 42 download->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
43 } | 43 } |
44 | 44 |
45 } // namespace | 45 } // namespace |
46 | 46 |
| 47 DownloadUpdatedObserver::DownloadUpdatedObserver( |
| 48 DownloadItem* item, DownloadUpdatedObserver::EventFilter filter) |
| 49 : item_(item), |
| 50 filter_(filter), |
| 51 waiting_(false), |
| 52 event_seen_(false) { |
| 53 item->AddObserver(this); |
| 54 } |
| 55 |
| 56 DownloadUpdatedObserver::~DownloadUpdatedObserver() { |
| 57 if (item_) |
| 58 item_->RemoveObserver(this); |
| 59 } |
| 60 |
| 61 bool DownloadUpdatedObserver::WaitForEvent() { |
| 62 if (item_ && filter_.Run(item_)) |
| 63 event_seen_ = true; |
| 64 if (event_seen_) |
| 65 return true; |
| 66 |
| 67 waiting_ = true; |
| 68 RunMessageLoop(); |
| 69 waiting_ = false; |
| 70 return event_seen_; |
| 71 } |
| 72 |
| 73 void DownloadUpdatedObserver::OnDownloadUpdated(DownloadItem* item) { |
| 74 DCHECK_EQ(item_, item); |
| 75 if (filter_.Run(item_)) |
| 76 event_seen_ = true; |
| 77 if (waiting_ && event_seen_) |
| 78 MessageLoopForUI::current()->Quit(); |
| 79 } |
| 80 |
| 81 void DownloadUpdatedObserver::OnDownloadDestroyed(DownloadItem* item) { |
| 82 DCHECK_EQ(item_, item); |
| 83 item_->RemoveObserver(this); |
| 84 item_ = NULL; |
| 85 if (waiting_) |
| 86 MessageLoopForUI::current()->Quit(); |
| 87 } |
| 88 |
47 DownloadTestObserver::DownloadTestObserver( | 89 DownloadTestObserver::DownloadTestObserver( |
48 DownloadManager* download_manager, | 90 DownloadManager* download_manager, |
49 size_t wait_count, | 91 size_t wait_count, |
50 DangerousDownloadAction dangerous_download_action) | 92 DangerousDownloadAction dangerous_download_action) |
51 : download_manager_(download_manager), | 93 : download_manager_(download_manager), |
52 wait_count_(wait_count), | 94 wait_count_(wait_count), |
53 finished_downloads_at_construction_(0), | 95 finished_downloads_at_construction_(0), |
54 waiting_(false), | 96 waiting_(false), |
55 dangerous_download_action_(dangerous_download_action) { | 97 dangerous_download_action_(dangerous_download_action) { |
56 } | 98 } |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 MessageLoopForUI::current()->Quit(); | 418 MessageLoopForUI::current()->Quit(); |
377 } | 419 } |
378 | 420 |
379 const DownloadUrlParameters::OnStartedCallback | 421 const DownloadUrlParameters::OnStartedCallback |
380 DownloadTestItemCreationObserver::callback() { | 422 DownloadTestItemCreationObserver::callback() { |
381 return base::Bind( | 423 return base::Bind( |
382 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); | 424 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); |
383 } | 425 } |
384 | 426 |
385 } // namespace content | 427 } // namespace content |
OLD | NEW |