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