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