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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 content::RunMessageLoop(); | 78 content::RunMessageLoop(); |
79 waiting_ = false; | 79 waiting_ = false; |
80 } | 80 } |
81 } | 81 } |
82 | 82 |
83 bool DownloadTestObserver::IsFinished() const { | 83 bool DownloadTestObserver::IsFinished() const { |
84 return (finished_downloads_.size() - finished_downloads_at_construction_ >= | 84 return (finished_downloads_.size() - finished_downloads_at_construction_ >= |
85 wait_count_); | 85 wait_count_); |
86 } | 86 } |
87 | 87 |
| 88 void DownloadTestObserver::OnDownloadDestroyed(DownloadItem* download) { |
| 89 // Stop observing. Do not do anything with it, as it is about to be gone. |
| 90 DownloadSet::iterator it = downloads_observed_.find(download); |
| 91 ASSERT_TRUE(it != downloads_observed_.end()); |
| 92 downloads_observed_.erase(it); |
| 93 download->RemoveObserver(this); |
| 94 } |
| 95 |
88 void DownloadTestObserver::OnDownloadUpdated(DownloadItem* download) { | 96 void DownloadTestObserver::OnDownloadUpdated(DownloadItem* download) { |
89 // The REMOVING state indicates that the download is being destroyed. | |
90 // Stop observing. Do not do anything with it, as it is about to be gone. | |
91 if (download->GetState() == DownloadItem::REMOVING) { | |
92 DownloadSet::iterator it = downloads_observed_.find(download); | |
93 ASSERT_TRUE(it != downloads_observed_.end()); | |
94 downloads_observed_.erase(it); | |
95 download->RemoveObserver(this); | |
96 return; | |
97 } | |
98 | |
99 // Real UI code gets the user's response after returning from the observer. | 97 // Real UI code gets the user's response after returning from the observer. |
100 if (download->GetSafetyState() == DownloadItem::DANGEROUS && | 98 if (download->GetSafetyState() == DownloadItem::DANGEROUS && |
101 !ContainsKey(dangerous_downloads_seen_, download->GetId())) { | 99 !ContainsKey(dangerous_downloads_seen_, download->GetId())) { |
102 dangerous_downloads_seen_.insert(download->GetId()); | 100 dangerous_downloads_seen_.insert(download->GetId()); |
103 | 101 |
104 // Calling DangerousDownloadValidated() at this point will | 102 // Calling DangerousDownloadValidated() at this point will |
105 // cause the download to be completed twice. Do what the real UI | 103 // cause the download to be completed twice. Do what the real UI |
106 // code does: make the call as a delayed task. | 104 // code does: make the call as a delayed task. |
107 switch (dangerous_download_action_) { | 105 switch (dangerous_download_action_) { |
108 case ON_DANGEROUS_DOWNLOAD_ACCEPT: | 106 case ON_DANGEROUS_DOWNLOAD_ACCEPT: |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
262 download_manager_->AddObserver(this); | 260 download_manager_->AddObserver(this); |
263 content::RunMessageLoop(); | 261 content::RunMessageLoop(); |
264 } | 262 } |
265 | 263 |
266 void DownloadTestFlushObserver::ModelChanged(DownloadManager* manager) { | 264 void DownloadTestFlushObserver::ModelChanged(DownloadManager* manager) { |
267 // Model has changed, so there may be more DownloadItems to observe. | 265 // Model has changed, so there may be more DownloadItems to observe. |
268 CheckDownloadsInProgress(true); | 266 CheckDownloadsInProgress(true); |
269 } | 267 } |
270 | 268 |
| 269 void DownloadTestFlushObserver::OnDownloadDestroyed(DownloadItem* download) { |
| 270 // Stop observing. Do not do anything with it, as it is about to be gone. |
| 271 DownloadSet::iterator it = downloads_observed_.find(download); |
| 272 ASSERT_TRUE(it != downloads_observed_.end()); |
| 273 downloads_observed_.erase(it); |
| 274 download->RemoveObserver(this); |
| 275 } |
| 276 |
271 void DownloadTestFlushObserver::OnDownloadUpdated(DownloadItem* download) { | 277 void DownloadTestFlushObserver::OnDownloadUpdated(DownloadItem* download) { |
272 // The REMOVING state indicates that the download is being destroyed. | |
273 // Stop observing. Do not do anything with it, as it is about to be gone. | |
274 if (download->GetState() == DownloadItem::REMOVING) { | |
275 DownloadSet::iterator it = downloads_observed_.find(download); | |
276 ASSERT_TRUE(it != downloads_observed_.end()); | |
277 downloads_observed_.erase(it); | |
278 download->RemoveObserver(this); | |
279 return; | |
280 } | |
281 | |
282 // No change in DownloadItem set on manager. | 278 // No change in DownloadItem set on manager. |
283 CheckDownloadsInProgress(false); | 279 CheckDownloadsInProgress(false); |
284 } | 280 } |
285 | 281 |
286 DownloadTestFlushObserver::~DownloadTestFlushObserver() { | 282 DownloadTestFlushObserver::~DownloadTestFlushObserver() { |
287 download_manager_->RemoveObserver(this); | 283 download_manager_->RemoveObserver(this); |
288 for (DownloadSet::iterator it = downloads_observed_.begin(); | 284 for (DownloadSet::iterator it = downloads_observed_.begin(); |
289 it != downloads_observed_.end(); ++it) { | 285 it != downloads_observed_.end(); ++it) { |
290 (*it)->RemoveObserver(this); | 286 (*it)->RemoveObserver(this); |
291 } | 287 } |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 DownloadTestFileChooserObserver::~DownloadTestFileChooserObserver() { | 441 DownloadTestFileChooserObserver::~DownloadTestFileChooserObserver() { |
446 } | 442 } |
447 | 443 |
448 void DownloadTestFileChooserObserver::EnableFileChooser(bool enable) { | 444 void DownloadTestFileChooserObserver::EnableFileChooser(bool enable) { |
449 test_delegate_->EnableFileChooser(enable); | 445 test_delegate_->EnableFileChooser(enable); |
450 } | 446 } |
451 | 447 |
452 bool DownloadTestFileChooserObserver::TestAndResetDidShowFileChooser() { | 448 bool DownloadTestFileChooserObserver::TestAndResetDidShowFileChooser() { |
453 return test_delegate_->TestAndResetDidShowFileChooser(); | 449 return test_delegate_->TestAndResetDidShowFileChooser(); |
454 } | 450 } |
OLD | NEW |