Index: content/browser/download/download_browsertest.cc |
diff --git a/content/browser/download/download_browsertest.cc b/content/browser/download/download_browsertest.cc |
index c85b7d515dd67dbfb526b40ec76adf89fa87c5ac..6579aaa7ac054ea5a76b2b77e7d8c8b3ec60c480 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" |
@@ -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, |
@@ -275,12 +276,9 @@ DownloadFile* DownloadFileWithDelayFactory::CreateFile( |
std::unique_ptr<ByteStreamReader> stream, |
const net::NetLogWithSource& net_log, |
base::WeakPtr<DownloadDestinationObserver> observer) { |
- return new DownloadFileWithDelay(std::move(save_info), |
- default_download_directory, |
- std::move(stream), |
- net_log, |
- observer, |
- weak_ptr_factory_.GetWeakPtr()); |
+ return new DownloadFileWithDelay( |
+ std::move(save_info), default_download_directory, std::move(stream), |
+ net_log, observer, weak_ptr_factory_.GetWeakPtr()); |
} |
void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) { |
@@ -321,7 +319,7 @@ class CountingDownloadFile : public DownloadFileImpl { |
observer) {} |
~CountingDownloadFile() override { |
- DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
+ DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence()); |
active_files_--; |
} |
@@ -330,14 +328,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 +343,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(); |
@@ -374,9 +372,7 @@ class CountingDownloadFileFactory : public DownloadFileFactory { |
base::WeakPtr<DownloadDestinationObserver> observer) override { |
return new CountingDownloadFile(std::move(save_info), |
default_downloads_directory, |
- std::move(stream), |
- net_log, |
- observer); |
+ std::move(stream), net_log, observer); |
} |
}; |
@@ -908,7 +904,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()); |
@@ -1076,7 +1072,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; |
@@ -1497,8 +1493,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, RecoverFromInitFileError) { |
// 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(); |
+ RunAllBlockingPoolTasksUntilIdle(); |
// Clear the old errors list. |
injector->ClearError(); |
@@ -1540,8 +1535,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, |
// 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(); |
+ RunAllBlockingPoolTasksUntilIdle(); |
// Clear the old errors list. |
injector->ClearError(); |
@@ -1578,8 +1572,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, RecoverFromFinalRenameError) { |
// 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. |
gab
2017/06/21 19:42:24
update reference to "file thread"
Sigurður Ásgeirsson
2017/06/22 14:50:06
Done.
|
- RunAllPendingInMessageLoop(BrowserThread::FILE); |
- RunAllPendingInMessageLoop(); |
+ RunAllBlockingPoolTasksUntilIdle(); |
// Clear the old errors list. |
injector->ClearError(); |
@@ -1657,8 +1650,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)); |
@@ -1679,8 +1671,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)); |
@@ -1701,8 +1692,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)); |
@@ -1741,8 +1731,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(); |
@@ -1791,9 +1780,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelResumingDownload) { |
request_start_handler.RespondWith(std::string(), net::OK); |
// The intermediate file should now be gone. |
- RunAllPendingInMessageLoop(BrowserThread::IO); |
- RunAllPendingInMessageLoop(BrowserThread::FILE); |
- RunAllPendingInMessageLoop(); |
+ RunAllBlockingPoolTasksUntilIdle(); |
EXPECT_FALSE(PathExists(intermediate_path)); |
parameters.ClearInjectedErrors(); |
@@ -1835,8 +1822,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()); |
@@ -1868,8 +1854,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()); |