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), filter_(filter), waiting_(false) { | |
50 item->AddObserver(this); | |
51 } | |
52 | |
53 DownloadUpdatedObserver::~DownloadUpdatedObserver() { | |
54 if (item_) | |
55 item_->RemoveObserver(this); | |
56 } | |
57 | |
58 bool DownloadUpdatedObserver::WaitForEvent() { | |
59 if (item_ && filter_.Run(item_)) | |
60 return true; | |
61 | |
62 waiting_ = true; | |
63 RunMessageLoop(); | |
64 waiting_ = false; | |
65 | |
66 if (!item_) | |
benjhayden
2012/09/12 21:01:01
What happened to event_seen_?
Randy Smith (Not in Mondays)
2012/09/13 20:15:12
I think that's a merge failure/I haven't merged in
| |
67 return false; | |
68 | |
69 return true; | |
70 } | |
71 | |
72 void DownloadUpdatedObserver::OnDownloadUpdated(DownloadItem* item) { | |
73 DCHECK_EQ(item_, item); | |
74 if (waiting_ && filter_.Run(item_)) | |
75 MessageLoopForUI::current()->Quit(); | |
76 } | |
77 | |
78 void DownloadUpdatedObserver::OnDownloadDestroyed(DownloadItem* item) { | |
79 DCHECK_EQ(item_, item); | |
80 item_->RemoveObserver(this); | |
81 item_ = NULL; | |
82 if (waiting_) | |
83 MessageLoopForUI::current()->Quit(); | |
84 } | |
85 | |
47 DownloadTestObserver::DownloadTestObserver( | 86 DownloadTestObserver::DownloadTestObserver( |
48 DownloadManager* download_manager, | 87 DownloadManager* download_manager, |
49 size_t wait_count, | 88 size_t wait_count, |
50 DangerousDownloadAction dangerous_download_action) | 89 DangerousDownloadAction dangerous_download_action) |
51 : download_manager_(download_manager), | 90 : download_manager_(download_manager), |
52 wait_count_(wait_count), | 91 wait_count_(wait_count), |
53 finished_downloads_at_construction_(0), | 92 finished_downloads_at_construction_(0), |
54 waiting_(false), | 93 waiting_(false), |
55 dangerous_download_action_(dangerous_download_action) { | 94 dangerous_download_action_(dangerous_download_action) { |
56 } | 95 } |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 MessageLoopForUI::current()->Quit(); | 415 MessageLoopForUI::current()->Quit(); |
377 } | 416 } |
378 | 417 |
379 const DownloadUrlParameters::OnStartedCallback | 418 const DownloadUrlParameters::OnStartedCallback |
380 DownloadTestItemCreationObserver::callback() { | 419 DownloadTestItemCreationObserver::callback() { |
381 return base::Bind( | 420 return base::Bind( |
382 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); | 421 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); |
383 } | 422 } |
384 | 423 |
385 } // namespace content | 424 } // namespace content |
OLD | NEW |