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

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

Issue 2890853002: Downloads: replace BrowserThread::FILE with task scheduler. (Closed)
Patch Set: Add scoped COM initialization to quench a couple of assertion failures. 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/save_file_manager.cc
diff --git a/content/browser/download/save_file_manager.cc b/content/browser/download/save_file_manager.cc
index 982eeac812a8d050c0424a2184d12601e82e495c..9538a37b0289d94462c489bfc3b85c6f1abfff4a 100644
--- a/content/browser/download/save_file_manager.cc
+++ b/content/browser/download/save_file_manager.cc
@@ -13,6 +13,7 @@
#include "base/strings/string_util.h"
#include "base/threading/thread.h"
#include "content/browser/child_process_security_policy_impl.h"
+#include "content/browser/download/download_task_runner.h"
#include "content/browser/download/save_file.h"
#include "content/browser/download/save_file_resource_handler.h"
#include "content/browser/download/save_package.h"
@@ -60,19 +61,18 @@ SaveFileManager* SaveFileManager::Get() {
// Called during the browser shutdown process to clean up any state (open files,
// timers) that live on the saving thread (file thread).
void SaveFileManager::Shutdown() {
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- base::Bind(&SaveFileManager::OnShutdown, this));
+ GetDownloadTaskRunner()->PostTask(
+ FROM_HERE, base::Bind(&SaveFileManager::OnShutdown, this));
}
// Stop file thread operations.
void SaveFileManager::OnShutdown() {
- DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
save_file_map_.clear();
}
SaveFile* SaveFileManager::LookupSaveFile(SaveItemId save_item_id) {
- DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
auto it = save_file_map_.find(save_item_id);
return it == save_file_map_.end() ? nullptr : it->second.get();
}
@@ -120,9 +120,8 @@ void SaveFileManager::SaveURL(SaveItemId save_item_id,
// Since the data will come from render process, so we need to start
// this kind of save job by ourself.
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- base::Bind(&SaveFileManager::StartSave, this, info));
+ GetDownloadTaskRunner()->PostTask(
+ FROM_HERE, base::Bind(&SaveFileManager::StartSave, this, info));
}
}
@@ -161,18 +160,16 @@ SavePackage* SaveFileManager::GetSavePackageFromRenderIds(
void SaveFileManager::DeleteDirectoryOrFile(const base::FilePath& full_path,
bool is_dir) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- base::Bind(&SaveFileManager::OnDeleteDirectoryOrFile,
- this, full_path, is_dir));
+ GetDownloadTaskRunner()->PostTask(
+ FROM_HERE, base::Bind(&SaveFileManager::OnDeleteDirectoryOrFile, this,
+ full_path, is_dir));
}
void SaveFileManager::SendCancelRequest(SaveItemId save_item_id) {
// Cancel the request which has specific save id.
DCHECK(!save_item_id.is_null());
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- base::Bind(&SaveFileManager::CancelSave, this, save_item_id));
+ GetDownloadTaskRunner()->PostTask(
+ FROM_HERE, base::Bind(&SaveFileManager::CancelSave, this, save_item_id));
}
// Notifications sent from the IO thread and run on the file thread:
@@ -181,7 +178,7 @@ void SaveFileManager::SendCancelRequest(SaveItemId save_item_id) {
// to create a SaveFile which will hold and finally destroy |info|. It will
// then passes |info| to the UI thread for reporting saving status.
void SaveFileManager::StartSave(SaveFileCreateInfo* info) {
- DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
DCHECK(info);
// No need to calculate hash.
std::unique_ptr<SaveFile> save_file = base::MakeUnique<SaveFile>(info, false);
@@ -205,7 +202,7 @@ void SaveFileManager::StartSave(SaveFileCreateInfo* info) {
void SaveFileManager::UpdateSaveProgress(SaveItemId save_item_id,
net::IOBuffer* data,
int data_len) {
- DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
SaveFile* save_file = LookupSaveFile(save_item_id);
if (save_file) {
DCHECK(save_file->InProgress());
@@ -228,7 +225,7 @@ void SaveFileManager::SaveFinished(SaveItemId save_item_id,
DVLOG(20) << __func__ << "() save_item_id = " << save_item_id
<< " save_package_id = " << save_package_id
<< " is_success = " << is_success;
- DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
int64_t bytes_so_far = 0;
SaveFile* save_file = LookupSaveFile(save_item_id);
@@ -382,7 +379,7 @@ void SaveFileManager::ExecuteCancelSaveRequest(int render_process_id,
// sent from the UI thread, the saving job may have already completed and
// won't exist in our map.
void SaveFileManager::CancelSave(SaveItemId save_item_id) {
- DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
auto it = save_file_map_.find(save_item_id);
if (it != save_file_map_.end()) {
std::unique_ptr<SaveFile> save_file = std::move(it->second);
@@ -412,7 +409,7 @@ void SaveFileManager::CancelSave(SaveItemId save_item_id) {
void SaveFileManager::OnDeleteDirectoryOrFile(const base::FilePath& full_path,
bool is_dir) {
- DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
DCHECK(!full_path.empty());
base::DeleteFile(full_path, is_dir);
@@ -423,7 +420,7 @@ void SaveFileManager::RenameAllFiles(const FinalNamesMap& final_names,
int render_process_id,
int render_frame_routing_id,
SavePackageId save_package_id) {
- DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
if (!resource_dir.empty() && !base::PathExists(resource_dir))
base::CreateDirectory(resource_dir);
@@ -461,7 +458,7 @@ void SaveFileManager::OnFinishSavePageJob(int render_process_id,
void SaveFileManager::RemoveSavedFileFromFileMap(
const std::vector<SaveItemId>& save_item_ids) {
- DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
for (const SaveItemId save_item_id : save_item_ids) {
auto it = save_file_map_.find(save_item_id);

Powered by Google App Engine
This is Rietveld 408576698