| Index: content/browser/download/download_browsertest.cc
|
| diff --git a/content/browser/download/download_browsertest.cc b/content/browser/download/download_browsertest.cc
|
| index 5a8281a595299f073680d9d185a65e3411e078fa..8e353618e87a09d778dc29032b3058b188b0bc71 100644
|
| --- a/content/browser/download/download_browsertest.cc
|
| +++ b/content/browser/download/download_browsertest.cc
|
| @@ -37,6 +37,7 @@
|
| #include "content/browser/download/download_item_impl.h"
|
| #include "content/browser/download/download_manager_impl.h"
|
| #include "content/browser/download/download_resource_handler.h"
|
| +#include "content/browser/download/download_task_runner.h"
|
| #include "content/browser/download/parallel_download_utils.h"
|
| #include "content/browser/loader/resource_dispatcher_host_impl.h"
|
| #include "content/browser/web_contents/web_contents_impl.h"
|
| @@ -172,7 +173,7 @@ class DownloadFileWithDelay : public DownloadFileImpl {
|
| DownloadInterruptReason reason,
|
| const base::FilePath& path);
|
|
|
| - // This variable may only be read on the FILE thread, and may only be
|
| + // This variable may only be read on the download sequence, and may only be
|
| // indirected through (e.g. methods on DownloadFileWithDelayFactory called)
|
| // on the UI thread. This is because after construction,
|
| // DownloadFileWithDelay lives on the file thread, but
|
| @@ -229,7 +230,7 @@ DownloadFileWithDelay::~DownloadFileWithDelay() {}
|
| void DownloadFileWithDelay::RenameAndUniquify(
|
| const base::FilePath& full_path,
|
| const RenameCompletionCallback& callback) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE);
|
| + DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
|
| DownloadFileImpl::RenameAndUniquify(
|
| full_path, base::Bind(DownloadFileWithDelay::RenameCallbackWrapper,
|
| owner_, callback));
|
| @@ -241,7 +242,7 @@ void DownloadFileWithDelay::RenameAndAnnotate(
|
| const GURL& source_url,
|
| const GURL& referrer_url,
|
| const RenameCompletionCallback& callback) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE);
|
| + DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
|
| DownloadFileImpl::RenameAndAnnotate(
|
| full_path,
|
| client_guid,
|
| @@ -321,7 +322,7 @@ class CountingDownloadFile : public DownloadFileImpl {
|
| observer) {}
|
|
|
| ~CountingDownloadFile() override {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE);
|
| + DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
|
| active_files_--;
|
| }
|
|
|
| @@ -330,14 +331,14 @@ class CountingDownloadFile : public DownloadFileImpl {
|
| const CancelRequestCallback& cancel_request_callback,
|
| const DownloadItem::ReceivedSlices& received_slices,
|
| bool is_parallelizable) override {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE);
|
| + DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
|
| active_files_++;
|
| DownloadFileImpl::Initialize(callback, cancel_request_callback,
|
| received_slices, is_parallelizable);
|
| }
|
|
|
| static void GetNumberActiveFiles(int* result) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE);
|
| + DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
|
| *result = active_files_;
|
| }
|
|
|
| @@ -345,8 +346,8 @@ class CountingDownloadFile : public DownloadFileImpl {
|
| // until data is returned.
|
| static int GetNumberActiveFilesFromFileThread() {
|
| int result = -1;
|
| - BrowserThread::PostTaskAndReply(
|
| - BrowserThread::FILE, FROM_HERE,
|
| + GetDownloadTaskRunner()->PostTaskAndReply(
|
| + FROM_HERE,
|
| base::Bind(&CountingDownloadFile::GetNumberActiveFiles, &result),
|
| base::MessageLoop::current()->QuitWhenIdleClosure());
|
| base::RunLoop().Run();
|
| @@ -906,7 +907,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelAtFinalRename) {
|
| download_manager->GetAllDownloads(&items);
|
| ASSERT_EQ(1u, items.size());
|
| items[0]->Cancel(true);
|
| - RunAllPendingInMessageLoop();
|
| + RunAllBlockingPoolTasksUntilIdle();
|
|
|
| // Check state.
|
| EXPECT_EQ(DownloadItem::CANCELLED, items[0]->GetState());
|
| @@ -1074,7 +1075,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, ShutdownAtRelease) {
|
| ASSERT_EQ(1u, items.size());
|
| items[0]->Cancel(true);
|
| EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState());
|
| - RunAllPendingInMessageLoop();
|
| + RunAllBlockingPoolTasksUntilIdle();
|
| EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState());
|
|
|
| MockDownloadItemObserver observer;
|
| @@ -1494,9 +1495,8 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, RecoverFromInitFileError) {
|
| // We need to make sure that any cross-thread downloads communication has
|
| // quiesced before clearing and injecting the new errors, as the
|
| // InjectErrors() routine alters the currently in use download file
|
| - // factory, which is a file thread object.
|
| - RunAllPendingInMessageLoop(BrowserThread::FILE);
|
| - RunAllPendingInMessageLoop();
|
| + // factory.
|
| + RunAllBlockingPoolTasksUntilIdle();
|
|
|
| // Clear the old errors list.
|
| injector->ClearError();
|
| @@ -1537,9 +1537,8 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest,
|
| // We need to make sure that any cross-thread downloads communication has
|
| // quiesced before clearing and injecting the new errors, as the
|
| // InjectErrors() routine alters the currently in use download file
|
| - // factory, which is a file thread object.
|
| - RunAllPendingInMessageLoop(BrowserThread::FILE);
|
| - RunAllPendingInMessageLoop();
|
| + // factory.
|
| + RunAllBlockingPoolTasksUntilIdle();
|
|
|
| // Clear the old errors list.
|
| injector->ClearError();
|
| @@ -1575,9 +1574,8 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, RecoverFromFinalRenameError) {
|
| // We need to make sure that any cross-thread downloads communication has
|
| // quiesced before clearing and injecting the new errors, as the
|
| // InjectErrors() routine alters the currently in use download file
|
| - // factory, which is a file thread object.
|
| - RunAllPendingInMessageLoop(BrowserThread::FILE);
|
| - RunAllPendingInMessageLoop();
|
| + // factory, which is a download sequence object.
|
| + RunAllBlockingPoolTasksUntilIdle();
|
|
|
| // Clear the old errors list.
|
| injector->ClearError();
|
| @@ -1655,8 +1653,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelInterruptedDownload) {
|
| ASSERT_TRUE(PathExists(intermediate_path));
|
|
|
| download->Cancel(true /* user_cancel */);
|
| - RunAllPendingInMessageLoop(BrowserThread::FILE);
|
| - RunAllPendingInMessageLoop();
|
| + RunAllBlockingPoolTasksUntilIdle();
|
|
|
| // The intermediate file should now be gone.
|
| EXPECT_FALSE(PathExists(intermediate_path));
|
| @@ -1677,8 +1674,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveInterruptedDownload) {
|
| ASSERT_TRUE(PathExists(intermediate_path));
|
|
|
| download->Remove();
|
| - RunAllPendingInMessageLoop(BrowserThread::FILE);
|
| - RunAllPendingInMessageLoop();
|
| + RunAllBlockingPoolTasksUntilIdle();
|
|
|
| // The intermediate file should now be gone.
|
| EXPECT_FALSE(PathExists(intermediate_path));
|
| @@ -1699,8 +1695,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveCompletedDownload) {
|
| base::FilePath target_path(download->GetTargetFilePath());
|
| EXPECT_TRUE(PathExists(target_path));
|
| download->Remove();
|
| - RunAllPendingInMessageLoop(BrowserThread::FILE);
|
| - RunAllPendingInMessageLoop();
|
| + RunAllBlockingPoolTasksUntilIdle();
|
|
|
| // The file should still exist.
|
| EXPECT_TRUE(PathExists(target_path));
|
| @@ -1739,8 +1734,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveResumingDownload) {
|
| request_start_handler.RespondWith(std::string(), net::OK);
|
|
|
| // The intermediate file should now be gone.
|
| - RunAllPendingInMessageLoop(BrowserThread::FILE);
|
| - RunAllPendingInMessageLoop();
|
| + RunAllBlockingPoolTasksUntilIdle();
|
| EXPECT_FALSE(PathExists(intermediate_path));
|
|
|
| parameters.ClearInjectedErrors();
|
| @@ -1790,8 +1784,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelResumingDownload) {
|
|
|
| // The intermediate file should now be gone.
|
| RunAllPendingInMessageLoop(BrowserThread::IO);
|
| - RunAllPendingInMessageLoop(BrowserThread::FILE);
|
| - RunAllPendingInMessageLoop();
|
| + RunAllBlockingPoolTasksUntilIdle();
|
| EXPECT_FALSE(PathExists(intermediate_path));
|
|
|
| parameters.ClearInjectedErrors();
|
| @@ -1833,8 +1826,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveResumedDownload) {
|
| download->Remove();
|
|
|
| // The intermediate file should now be gone.
|
| - RunAllPendingInMessageLoop(BrowserThread::FILE);
|
| - RunAllPendingInMessageLoop();
|
| + RunAllBlockingPoolTasksUntilIdle();
|
| EXPECT_FALSE(PathExists(intermediate_path));
|
| EXPECT_FALSE(PathExists(target_path));
|
| EXPECT_TRUE(EnsureNoPendingDownloads());
|
| @@ -1866,8 +1858,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelResumedDownload) {
|
| download->Cancel(true);
|
|
|
| // The intermediate file should now be gone.
|
| - RunAllPendingInMessageLoop(BrowserThread::FILE);
|
| - RunAllPendingInMessageLoop();
|
| + RunAllBlockingPoolTasksUntilIdle();
|
| EXPECT_FALSE(PathExists(intermediate_path));
|
| EXPECT_FALSE(PathExists(target_path));
|
| EXPECT_TRUE(EnsureNoPendingDownloads());
|
|
|