Chromium Code Reviews| Index: content/browser/download/download_item_impl.cc |
| diff --git a/content/browser/download/download_item_impl.cc b/content/browser/download/download_item_impl.cc |
| index a5d7db8cef5fad91838d9b6860063d10a6408265..90cdb8e823378f886a3b21ff993b832e22ca86ff 100644 |
| --- a/content/browser/download/download_item_impl.cc |
| +++ b/content/browser/download/download_item_impl.cc |
| @@ -36,6 +36,7 @@ |
| #include "base/strings/string_util.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "base/task_runner_util.h" |
| #include "content/browser/download/download_create_info.h" |
| #include "content/browser/download/download_file.h" |
| #include "content/browser/download/download_interrupt_reasons_impl.h" |
| @@ -45,6 +46,7 @@ |
| #include "content/browser/download/download_net_log_parameters.h" |
| #include "content/browser/download/download_request_handle.h" |
| #include "content/browser/download/download_stats.h" |
| +#include "content/browser/download/download_task_runner.h" |
| #include "content/browser/download/parallel_download_utils.h" |
| #include "content/browser/renderer_host/render_view_host_impl.h" |
| #include "content/browser/web_contents/web_contents_impl.h" |
| @@ -69,7 +71,7 @@ namespace content { |
| namespace { |
| bool DeleteDownloadedFile(const base::FilePath& path) { |
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| + DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence()); |
| // Make sure we only delete files. |
| if (base::DirectoryExists(path)) |
| @@ -92,14 +94,14 @@ void DeleteDownloadedFileDone( |
| // at the end of the function. |
| static base::FilePath DownloadFileDetach( |
| std::unique_ptr<DownloadFile> download_file) { |
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| + DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence()); |
| base::FilePath full_path = download_file->FullPath(); |
| download_file->Detach(); |
| return full_path; |
| } |
| static base::FilePath MakeCopyOfDownloadFile(DownloadFile* download_file) { |
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| + DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence()); |
| base::FilePath temp_file_path; |
| if (base::CreateTemporaryFile(&temp_file_path) && |
| base::CopyFile(download_file->FullPath(), temp_file_path)) { |
| @@ -114,7 +116,7 @@ static base::FilePath MakeCopyOfDownloadFile(DownloadFile* download_file) { |
| } |
| static void DownloadFileCancel(std::unique_ptr<DownloadFile> download_file) { |
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| + DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence()); |
| download_file->Cancel(); |
| } |
| @@ -409,8 +411,8 @@ void DownloadItemImpl::StealDangerousDownload( |
| if (delete_file_afterward) { |
| if (download_file_) { |
| - BrowserThread::PostTaskAndReplyWithResult( |
| - BrowserThread::FILE, FROM_HERE, |
| + PostTaskAndReplyWithResult( |
|
boliu
2017/07/20 18:47:35
nit: I didn't see a "using base::PostTaskAndReplyW
Sigurður Ásgeirsson
2017/07/20 19:48:15
Yeah - that's weird. I've no idea where the declar
|
| + GetDownloadTaskRunner().get(), FROM_HERE, |
| base::Bind(&DownloadFileDetach, base::Passed(&download_file_)), |
| callback); |
| } else { |
| @@ -420,8 +422,8 @@ void DownloadItemImpl::StealDangerousDownload( |
| Remove(); |
| // Download item has now been deleted. |
| } else if (download_file_) { |
| - BrowserThread::PostTaskAndReplyWithResult( |
| - BrowserThread::FILE, FROM_HERE, |
| + PostTaskAndReplyWithResult( |
| + GetDownloadTaskRunner().get(), FROM_HERE, |
| base::Bind(&MakeCopyOfDownloadFile, download_file_.get()), callback); |
| } else { |
| callback.Run(GetFullPath()); |
| @@ -456,8 +458,8 @@ void DownloadItemImpl::Pause() { |
| job_->Pause(); |
| UpdateObservers(); |
| if (download_file_) { |
| - BrowserThread::PostTask( |
| - BrowserThread::FILE, FROM_HERE, |
| + GetDownloadTaskRunner()->PostTask( |
| + FROM_HERE, |
| base::Bind(&DownloadFile::WasPaused, |
| // Safe because we control download file lifetime. |
| base::Unretained(download_file_.get()))); |
| @@ -764,8 +766,8 @@ void DownloadItemImpl::DeleteFile(const base::Callback<void(bool)>& callback) { |
| base::WeakPtr<DownloadItemImpl>(), callback, true)); |
| return; |
| } |
| - BrowserThread::PostTaskAndReplyWithResult( |
| - BrowserThread::FILE, FROM_HERE, |
| + PostTaskAndReplyWithResult( |
| + GetDownloadTaskRunner().get(), FROM_HERE, |
| base::Bind(&DeleteDownloadedFile, GetFullPath()), |
| base::Bind(&DeleteDownloadedFileDone, weak_ptr_factory_.GetWeakPtr(), |
| callback)); |
| @@ -1494,12 +1496,11 @@ void DownloadItemImpl::OnDownloadTargetDetermined( |
| DownloadFile::RenameCompletionCallback callback = |
| base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName, |
| weak_ptr_factory_.GetWeakPtr()); |
| - BrowserThread::PostTask( |
| - BrowserThread::FILE, FROM_HERE, |
| - base::Bind(&DownloadFile::RenameAndUniquify, |
| - // Safe because we control download file lifetime. |
| - base::Unretained(download_file_.get()), |
| - intermediate_path, callback)); |
| + GetDownloadTaskRunner()->PostTask( |
| + FROM_HERE, base::Bind(&DownloadFile::RenameAndUniquify, |
| + // Safe because we control download file lifetime. |
| + base::Unretained(download_file_.get()), |
| + intermediate_path, callback)); |
| } |
| void DownloadItemImpl::OnDownloadRenamedToIntermediateName( |
| @@ -1605,16 +1606,12 @@ void DownloadItemImpl::OnDownloadCompleting() { |
| DownloadFile::RenameCompletionCallback callback = |
| base::Bind(&DownloadItemImpl::OnDownloadRenamedToFinalName, |
| weak_ptr_factory_.GetWeakPtr()); |
| - BrowserThread::PostTask( |
| - BrowserThread::FILE, |
| + GetDownloadTaskRunner()->PostTask( |
| FROM_HERE, |
| base::Bind(&DownloadFile::RenameAndAnnotate, |
| - base::Unretained(download_file_.get()), |
| - GetTargetFilePath(), |
| - delegate_->GetApplicationClientIdForFileScanning(), |
| - GetURL(), |
| - GetReferrerUrl(), |
| - callback)); |
| + base::Unretained(download_file_.get()), GetTargetFilePath(), |
| + delegate_->GetApplicationClientIdForFileScanning(), GetURL(), |
| + GetReferrerUrl(), callback)); |
| } |
| void DownloadItemImpl::OnDownloadRenamedToFinalName( |
| @@ -1796,10 +1793,9 @@ void DownloadItemImpl::InterruptWithPartialState( |
| // There is no download file and this is transitioning from INTERRUPTED |
| // to CANCELLED. The intermediate file is no longer usable, and should |
| // be deleted. |
| - BrowserThread::PostTask( |
| - BrowserThread::FILE, FROM_HERE, |
| - base::Bind(base::IgnoreResult(&DeleteDownloadedFile), |
| - GetFullPath())); |
| + GetDownloadTaskRunner()->PostTask( |
| + FROM_HERE, base::Bind(base::IgnoreResult(&DeleteDownloadedFile), |
| + GetFullPath())); |
| destination_info_.current_path.clear(); |
| } |
| break; |
| @@ -1896,8 +1892,8 @@ void DownloadItemImpl::ReleaseDownloadFile(bool destroy_file) { |
| DVLOG(20) << __func__ << "() destroy_file:" << destroy_file; |
| if (destroy_file) { |
| - BrowserThread::PostTask( |
| - BrowserThread::FILE, FROM_HERE, |
| + GetDownloadTaskRunner()->PostTask( |
| + FROM_HERE, |
| // Will be deleted at end of task execution. |
| base::Bind(&DownloadFileCancel, base::Passed(&download_file_))); |
| // Avoid attempting to reuse the intermediate file by clearing out |
| @@ -1905,12 +1901,10 @@ void DownloadItemImpl::ReleaseDownloadFile(bool destroy_file) { |
| destination_info_.current_path.clear(); |
| received_slices_.clear(); |
| } else { |
| - BrowserThread::PostTask( |
| - BrowserThread::FILE, |
| - FROM_HERE, |
| - base::Bind(base::IgnoreResult(&DownloadFileDetach), |
| - // Will be deleted at end of task execution. |
| - base::Passed(&download_file_))); |
| + GetDownloadTaskRunner()->PostTask( |
| + FROM_HERE, base::Bind(base::IgnoreResult(&DownloadFileDetach), |
| + // Will be deleted at end of task execution. |
| + base::Passed(&download_file_))); |
| } |
| // Don't accept any more messages from the DownloadFile, and null |
| // out any previous "all data received". This also breaks links to |