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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 void DownloadTestFlushObserver::PingIOThread(int cycle) { | 353 void DownloadTestFlushObserver::PingIOThread(int cycle) { |
354 if (--cycle) { | 354 if (--cycle) { |
355 BrowserThread::PostTask( | 355 BrowserThread::PostTask( |
356 BrowserThread::UI, FROM_HERE, | 356 BrowserThread::UI, FROM_HERE, |
357 base::Bind(&DownloadTestFlushObserver::PingFileThread, this, cycle)); | 357 base::Bind(&DownloadTestFlushObserver::PingFileThread, this, cycle)); |
358 } else { | 358 } else { |
359 BrowserThread::PostTask( | 359 BrowserThread::PostTask( |
360 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure()); | 360 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure()); |
361 } | 361 } |
362 } | 362 } |
| 363 |
| 364 DownloadTestItemCreationObserver::DownloadTestItemCreationObserver() |
| 365 : download_id_(content::DownloadId::Invalid()), |
| 366 error_(net::OK), |
| 367 called_back_count_(0), |
| 368 waiting_(false) { |
| 369 } |
| 370 |
| 371 DownloadTestItemCreationObserver::~DownloadTestItemCreationObserver() { |
| 372 } |
| 373 |
| 374 void DownloadTestItemCreationObserver::WaitForDownloadItemCreation() { |
| 375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 376 |
| 377 if (called_back_count_ == 0) { |
| 378 waiting_ = true; |
| 379 ui_test_utils::RunMessageLoop(); |
| 380 waiting_ = false; |
| 381 } |
| 382 } |
| 383 |
| 384 void DownloadTestItemCreationObserver::DownloadItemCreationCallback( |
| 385 content::DownloadId download_id, net::Error error) { |
| 386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 387 |
| 388 download_id_ = download_id; |
| 389 error_ = error; |
| 390 ++called_back_count_; |
| 391 DCHECK_EQ(1u, called_back_count_); |
| 392 |
| 393 if (waiting_) |
| 394 MessageLoopForUI::current()->Quit(); |
| 395 } |
| 396 |
| 397 const content::DownloadManager::OnStartedCallback |
| 398 DownloadTestItemCreationObserver::callback() { |
| 399 return base::Bind( |
| 400 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); |
| 401 } |
| 402 |
OLD | NEW |