Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(980)

Unified Diff: content/browser/download/download_item_impl.cc

Issue 2890853002: Downloads: replace BrowserThread::FILE with task scheduler. (Closed)
Patch Set: Address Avi's comments. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..3f4ceef2022b845045c5eeb40bf25195cba791d7 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,
+ base::PostTaskAndReplyWithResult(
+ 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,
+ base::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,
+ base::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
« no previous file with comments | « content/browser/download/download_item_impl.h ('k') | content/browser/download/download_item_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698