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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 BrowserThread::UI, FROM_HERE, | 406 BrowserThread::UI, FROM_HERE, |
407 base::Bind(&DownloadTestFlushObserver::PingFileThread, this, cycle)); | 407 base::Bind(&DownloadTestFlushObserver::PingFileThread, this, cycle)); |
408 } else { | 408 } else { |
409 BrowserThread::PostTask( | 409 BrowserThread::PostTask( |
410 BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure()); | 410 BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure()); |
411 } | 411 } |
412 } | 412 } |
413 | 413 |
414 DownloadTestItemCreationObserver::DownloadTestItemCreationObserver() | 414 DownloadTestItemCreationObserver::DownloadTestItemCreationObserver() |
415 : download_id_(DownloadItem::kInvalidId), | 415 : download_id_(DownloadItem::kInvalidId), |
416 error_(net::OK), | 416 interrupt_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), |
417 called_back_count_(0), | 417 called_back_count_(0), |
418 waiting_(false) { | 418 waiting_(false) { |
419 } | 419 } |
420 | 420 |
421 DownloadTestItemCreationObserver::~DownloadTestItemCreationObserver() { | 421 DownloadTestItemCreationObserver::~DownloadTestItemCreationObserver() { |
422 } | 422 } |
423 | 423 |
424 void DownloadTestItemCreationObserver::WaitForDownloadItemCreation() { | 424 void DownloadTestItemCreationObserver::WaitForDownloadItemCreation() { |
425 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 425 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
426 | 426 |
427 if (called_back_count_ == 0) { | 427 if (called_back_count_ == 0) { |
428 waiting_ = true; | 428 waiting_ = true; |
429 RunMessageLoop(); | 429 RunMessageLoop(); |
430 waiting_ = false; | 430 waiting_ = false; |
431 } | 431 } |
432 } | 432 } |
433 | 433 |
434 void DownloadTestItemCreationObserver::DownloadItemCreationCallback( | 434 void DownloadTestItemCreationObserver::DownloadItemCreationCallback( |
435 DownloadItem* item, | 435 DownloadItem* item, |
436 net::Error error) { | 436 DownloadInterruptReason interrupt_reason) { |
437 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 437 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
438 | 438 |
439 if (item) | 439 if (item) |
440 download_id_ = item->GetId(); | 440 download_id_ = item->GetId(); |
441 error_ = error; | 441 interrupt_reason_ = interrupt_reason; |
442 ++called_back_count_; | 442 ++called_back_count_; |
443 DCHECK_EQ(1u, called_back_count_); | 443 DCHECK_EQ(1u, called_back_count_); |
444 | 444 |
445 if (waiting_) | 445 if (waiting_) |
446 base::MessageLoopForUI::current()->Quit(); | 446 base::MessageLoopForUI::current()->Quit(); |
447 } | 447 } |
448 | 448 |
449 const DownloadUrlParameters::OnStartedCallback | 449 const DownloadUrlParameters::OnStartedCallback |
450 DownloadTestItemCreationObserver::callback() { | 450 DownloadTestItemCreationObserver::callback() { |
451 return base::Bind( | 451 return base::Bind( |
452 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); | 452 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); |
453 } | 453 } |
454 | 454 |
455 } // namespace content | 455 } // namespace content |
OLD | NEW |