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 14 matching lines...) Expand all Loading... |
25 // their actual posting. Once posted, there is no connection between | 25 // their actual posting. Once posted, there is no connection between |
26 // these routines and the DownloadTestObserver class from which | 26 // these routines and the DownloadTestObserver class from which |
27 // they came, so the DownloadTestObserver's reference to the | 27 // they came, so the DownloadTestObserver's reference to the |
28 // DownloadManager cannot be counted on to keep the DownloadManager around. | 28 // DownloadManager cannot be counted on to keep the DownloadManager around. |
29 | 29 |
30 // Fake user click on "Accept". | 30 // Fake user click on "Accept". |
31 void AcceptDangerousDownload(scoped_refptr<DownloadManager> download_manager, | 31 void AcceptDangerousDownload(scoped_refptr<DownloadManager> download_manager, |
32 int32 download_id) { | 32 int32 download_id) { |
33 DownloadItem* download = download_manager->GetDownload(download_id); | 33 DownloadItem* download = download_manager->GetDownload(download_id); |
34 if (download && (download->GetState() == DownloadItem::IN_PROGRESS)) | 34 if (download && (download->GetState() == DownloadItem::IN_PROGRESS)) |
35 download->DangerousDownloadValidated(); | 35 download->ValidateDangerousDownload(); |
36 } | 36 } |
37 | 37 |
38 // Fake user click on "Deny". | 38 // Fake user click on "Deny". |
39 void DenyDangerousDownload(scoped_refptr<DownloadManager> download_manager, | 39 void DenyDangerousDownload(scoped_refptr<DownloadManager> download_manager, |
40 int32 download_id) { | 40 int32 download_id) { |
41 DownloadItem* download = download_manager->GetDownload(download_id); | 41 DownloadItem* download = download_manager->GetDownload(download_id); |
42 if (download && (download->GetState() == DownloadItem::IN_PROGRESS)) { | 42 if (download && (download->GetState() == DownloadItem::IN_PROGRESS)) { |
43 download->Cancel(true); | 43 download->Cancel(true); |
44 download->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 44 download->DiscardDangerousDownload(DownloadItem::DELETE_DUE_TO_USER_DISCARD, |
| 45 DownloadItem::AcquireFileCallback()); |
45 } | 46 } |
46 } | 47 } |
47 | 48 |
48 } // namespace | 49 } // namespace |
49 | 50 |
50 DownloadUpdatedObserver::DownloadUpdatedObserver( | 51 DownloadUpdatedObserver::DownloadUpdatedObserver( |
51 DownloadItem* item, DownloadUpdatedObserver::EventFilter filter) | 52 DownloadItem* item, DownloadUpdatedObserver::EventFilter filter) |
52 : item_(item), | 53 : item_(item), |
53 filter_(filter), | 54 filter_(filter), |
54 waiting_(false), | 55 waiting_(false), |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 downloads_observed_.erase(it); | 156 downloads_observed_.erase(it); |
156 download->RemoveObserver(this); | 157 download->RemoveObserver(this); |
157 } | 158 } |
158 | 159 |
159 void DownloadTestObserver::OnDownloadUpdated(DownloadItem* download) { | 160 void DownloadTestObserver::OnDownloadUpdated(DownloadItem* download) { |
160 // Real UI code gets the user's response after returning from the observer. | 161 // Real UI code gets the user's response after returning from the observer. |
161 if (download->IsDangerous() && | 162 if (download->IsDangerous() && |
162 !ContainsKey(dangerous_downloads_seen_, download->GetId())) { | 163 !ContainsKey(dangerous_downloads_seen_, download->GetId())) { |
163 dangerous_downloads_seen_.insert(download->GetId()); | 164 dangerous_downloads_seen_.insert(download->GetId()); |
164 | 165 |
165 // Calling DangerousDownloadValidated() at this point will | 166 // Calling ValidateDangerousDownload() at this point will |
166 // cause the download to be completed twice. Do what the real UI | 167 // cause the download to be completed twice. Do what the real UI |
167 // code does: make the call as a delayed task. | 168 // code does: make the call as a delayed task. |
168 switch (dangerous_download_action_) { | 169 switch (dangerous_download_action_) { |
169 case ON_DANGEROUS_DOWNLOAD_ACCEPT: | 170 case ON_DANGEROUS_DOWNLOAD_ACCEPT: |
170 // Fake user click on "Accept". Delay the actual click, as the | 171 // Fake user click on "Accept". Delay the actual click, as the |
171 // real UI would. | 172 // real UI would. |
172 BrowserThread::PostTask( | 173 BrowserThread::PostTask( |
173 BrowserThread::UI, FROM_HERE, | 174 BrowserThread::UI, FROM_HERE, |
174 base::Bind(&AcceptDangerousDownload, download_manager_, | 175 base::Bind(&AcceptDangerousDownload, download_manager_, |
175 download->GetId())); | 176 download->GetId())); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 base::MessageLoopForUI::current()->Quit(); | 419 base::MessageLoopForUI::current()->Quit(); |
419 } | 420 } |
420 | 421 |
421 const DownloadUrlParameters::OnStartedCallback | 422 const DownloadUrlParameters::OnStartedCallback |
422 DownloadTestItemCreationObserver::callback() { | 423 DownloadTestItemCreationObserver::callback() { |
423 return base::Bind( | 424 return base::Bind( |
424 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); | 425 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); |
425 } | 426 } |
426 | 427 |
427 } // namespace content | 428 } // namespace content |
OLD | NEW |