| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 size_t DownloadTestObserver::NumDownloadsSeenInState( | 192 size_t DownloadTestObserver::NumDownloadsSeenInState( |
| 193 DownloadItem::DownloadState state) const { | 193 DownloadItem::DownloadState state) const { |
| 194 StateMap::const_iterator it = states_observed_.find(state); | 194 StateMap::const_iterator it = states_observed_.find(state); |
| 195 | 195 |
| 196 if (it == states_observed_.end()) | 196 if (it == states_observed_.end()) |
| 197 return 0; | 197 return 0; |
| 198 | 198 |
| 199 return it->second; | 199 return it->second; |
| 200 } | 200 } |
| 201 | 201 |
| 202 DownloadManager* DownloadTestObserver::download_manager() { |
| 203 return download_manager_; |
| 204 } |
| 205 |
| 206 DownloadTestObserver::DangerousDownloadAction |
| 207 DownloadTestObserver::dangerous_download_action() { |
| 208 return dangerous_download_action_; |
| 209 } |
| 210 |
| 211 std::set<uint32_t>& DownloadTestObserver::dangerous_downloads_seen() { |
| 212 return dangerous_downloads_seen_; |
| 213 } |
| 214 |
| 202 void DownloadTestObserver::DownloadInFinalState(DownloadItem* download) { | 215 void DownloadTestObserver::DownloadInFinalState(DownloadItem* download) { |
| 203 if (finished_downloads_.find(download) != finished_downloads_.end()) { | 216 if (finished_downloads_.find(download) != finished_downloads_.end()) { |
| 204 // We've already seen the final state on this download. | 217 // We've already seen the final state on this download. |
| 205 return; | 218 return; |
| 206 } | 219 } |
| 207 | 220 |
| 208 // Record the transition. | 221 // Record the transition. |
| 209 finished_downloads_.insert(download); | 222 finished_downloads_.insert(download); |
| 210 | 223 |
| 211 // Record the state. | 224 // Record the state. |
| 212 states_observed_[download->GetState()]++; // Initializes to 0 the first time. | 225 states_observed_[download->GetState()]++; // Initializes to 0 the first time. |
| 213 | 226 |
| 214 SignalIfFinished(); | 227 SignalIfFinished(); |
| 215 } | 228 } |
| 216 | 229 |
| 217 void DownloadTestObserver::SignalIfFinished() { | 230 void DownloadTestObserver::SignalIfFinished() { |
| 218 if (waiting_ && IsFinished()) | 231 if (waiting_ && IsFinished()) |
| 219 base::MessageLoopForUI::current()->QuitWhenIdle(); | 232 base::MessageLoopForUI::current()->QuitWhenIdle(); |
| 220 } | 233 } |
| 221 | 234 |
| 222 void DownloadTestObserver::AcceptDangerousDownload(uint32_t download_id) { | 235 void DownloadTestObserver::AcceptDangerousDownload(uint32_t download_id) { |
| 223 // Download manager was shutdown before the UI thread could accept the | 236 // Download manager was shutdown before the UI thread could accept the |
| 224 // download. | 237 // download. |
| 225 if (!download_manager_) | 238 if (!download_manager_) |
| 226 return; | 239 return; |
| 227 DownloadItem* download = download_manager_->GetDownload(download_id); | 240 DownloadItem* download = download_manager_->GetDownload(download_id); |
| 228 if (download && !download->IsDone()) | 241 if (download && download->IsDangerous() && !download->IsDone()) |
| 229 download->ValidateDangerousDownload(); | 242 download->ValidateDangerousDownload(); |
| 230 } | 243 } |
| 231 | 244 |
| 232 void DownloadTestObserver::DenyDangerousDownload(uint32_t download_id) { | 245 void DownloadTestObserver::DenyDangerousDownload(uint32_t download_id) { |
| 233 // Download manager was shutdown before the UI thread could deny the | 246 // Download manager was shutdown before the UI thread could deny the |
| 234 // download. | 247 // download. |
| 235 if (!download_manager_) | 248 if (!download_manager_) |
| 236 return; | 249 return; |
| 237 DownloadItem* download = download_manager_->GetDownload(download_id); | 250 DownloadItem* download = download_manager_->GetDownload(download_id); |
| 238 if (download && !download->IsDone()) | 251 if (download && !download->IsDone()) |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 base::MessageLoopForUI::current()->QuitWhenIdle(); | 459 base::MessageLoopForUI::current()->QuitWhenIdle(); |
| 447 } | 460 } |
| 448 | 461 |
| 449 const DownloadUrlParameters::OnStartedCallback | 462 const DownloadUrlParameters::OnStartedCallback |
| 450 DownloadTestItemCreationObserver::callback() { | 463 DownloadTestItemCreationObserver::callback() { |
| 451 return base::Bind( | 464 return base::Bind( |
| 452 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); | 465 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); |
| 453 } | 466 } |
| 454 | 467 |
| 455 } // namespace content | 468 } // namespace content |
| OLD | NEW |