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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 // instead. In this case, it's because of |IsDownloadInFinalState()|. | 248 // instead. In this case, it's because of |IsDownloadInFinalState()|. |
249 Init(); | 249 Init(); |
250 } | 250 } |
251 | 251 |
252 DownloadTestObserverTerminal::~DownloadTestObserverTerminal() { | 252 DownloadTestObserverTerminal::~DownloadTestObserverTerminal() { |
253 } | 253 } |
254 | 254 |
255 | 255 |
256 bool DownloadTestObserverTerminal::IsDownloadInFinalState( | 256 bool DownloadTestObserverTerminal::IsDownloadInFinalState( |
257 DownloadItem* download) { | 257 DownloadItem* download) { |
258 return (download->GetState() != DownloadItem::IN_PROGRESS); | 258 return download->IsDone(); |
259 } | 259 } |
260 | 260 |
261 DownloadTestObserverInProgress::DownloadTestObserverInProgress( | 261 DownloadTestObserverInProgress::DownloadTestObserverInProgress( |
262 DownloadManager* download_manager, | 262 DownloadManager* download_manager, |
263 size_t wait_count) | 263 size_t wait_count) |
264 : DownloadTestObserver(download_manager, | 264 : DownloadTestObserver(download_manager, |
265 wait_count, | 265 wait_count, |
266 ON_DANGEROUS_DOWNLOAD_ACCEPT) { | 266 ON_DANGEROUS_DOWNLOAD_ACCEPT) { |
267 // You can't override virtual functions in a base class constructor; the | 267 // You can't override virtual functions in a base class constructor; the |
268 // virtual function table hasn't been set up yet. So, we have to do any | 268 // virtual function table hasn't been set up yet. So, we have to do any |
269 // work that depends on those functions in the derived class constructor | 269 // work that depends on those functions in the derived class constructor |
270 // instead. In this case, it's because of |IsDownloadInFinalState()|. | 270 // instead. In this case, it's because of |IsDownloadInFinalState()|. |
271 Init(); | 271 Init(); |
272 } | 272 } |
273 | 273 |
274 DownloadTestObserverInProgress::~DownloadTestObserverInProgress() { | 274 DownloadTestObserverInProgress::~DownloadTestObserverInProgress() { |
275 } | 275 } |
276 | 276 |
277 | 277 |
278 bool DownloadTestObserverInProgress::IsDownloadInFinalState( | 278 bool DownloadTestObserverInProgress::IsDownloadInFinalState( |
279 DownloadItem* download) { | 279 DownloadItem* download) { |
280 return (download->GetState() == DownloadItem::IN_PROGRESS) && | 280 return (download->GetState() == DownloadItem::IN_PROGRESS) && |
281 !download->GetTargetFilePath().empty(); | 281 !download->GetTargetFilePath().empty(); |
282 } | 282 } |
283 | 283 |
| 284 DownloadTestObserverInterrupted::DownloadTestObserverInterrupted( |
| 285 DownloadManager* download_manager, |
| 286 size_t wait_count, |
| 287 DangerousDownloadAction dangerous_download_action) |
| 288 : DownloadTestObserver(download_manager, |
| 289 wait_count, |
| 290 dangerous_download_action) { |
| 291 // You can't rely on overriden virtual functions in a base class constructor; |
| 292 // the virtual function table hasn't been set up yet. So, we have to do any |
| 293 // work that depends on those functions in the derived class constructor |
| 294 // instead. In this case, it's because of |IsDownloadInFinalState()|. |
| 295 Init(); |
| 296 } |
| 297 |
| 298 DownloadTestObserverInterrupted::~DownloadTestObserverInterrupted() { |
| 299 } |
| 300 |
| 301 |
| 302 bool DownloadTestObserverInterrupted::IsDownloadInFinalState( |
| 303 DownloadItem* download) { |
| 304 return download->GetState() == DownloadItem::INTERRUPTED; |
| 305 } |
| 306 |
284 DownloadTestFlushObserver::DownloadTestFlushObserver( | 307 DownloadTestFlushObserver::DownloadTestFlushObserver( |
285 DownloadManager* download_manager) | 308 DownloadManager* download_manager) |
286 : download_manager_(download_manager), | 309 : download_manager_(download_manager), |
287 waiting_for_zero_inprogress_(true) {} | 310 waiting_for_zero_inprogress_(true) {} |
288 | 311 |
289 void DownloadTestFlushObserver::WaitForFlush() { | 312 void DownloadTestFlushObserver::WaitForFlush() { |
290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
291 download_manager_->AddObserver(this); | 314 download_manager_->AddObserver(this); |
292 // The wait condition may have been met before WaitForFlush() was called. | 315 // The wait condition may have been met before WaitForFlush() was called. |
293 CheckDownloadsInProgress(true); | 316 CheckDownloadsInProgress(true); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 base::MessageLoopForUI::current()->Quit(); | 442 base::MessageLoopForUI::current()->Quit(); |
420 } | 443 } |
421 | 444 |
422 const DownloadUrlParameters::OnStartedCallback | 445 const DownloadUrlParameters::OnStartedCallback |
423 DownloadTestItemCreationObserver::callback() { | 446 DownloadTestItemCreationObserver::callback() { |
424 return base::Bind( | 447 return base::Bind( |
425 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); | 448 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); |
426 } | 449 } |
427 | 450 |
428 } // namespace content | 451 } // namespace content |
OLD | NEW |