Index: content/browser/download/save_package.cc |
diff --git a/content/browser/download/save_package.cc b/content/browser/download/save_package.cc |
index b6b6bd454ff1ab1cffd36f55fa8f70cc32dbe66c..cd6f1a079f0bff256aadaa1e2dc6ff0175ddc8ab 100644 |
--- a/content/browser/download/save_package.cc |
+++ b/content/browser/download/save_package.cc |
@@ -20,13 +20,16 @@ |
#include "base/strings/string_split.h" |
#include "base/strings/sys_string_conversions.h" |
#include "base/strings/utf_string_conversions.h" |
+#include "base/task_runner_util.h" |
#include "base/threading/thread.h" |
+#include "base/threading/thread_restrictions.h" |
#include "build/build_config.h" |
#include "components/url_formatter/url_formatter.h" |
#include "content/browser/bad_message.h" |
#include "content/browser/download/download_item_impl.h" |
#include "content/browser/download/download_manager_impl.h" |
#include "content/browser/download/download_stats.h" |
+#include "content/browser/download/download_task_runner.h" |
#include "content/browser/download/save_file.h" |
#include "content/browser/download/save_file_manager.h" |
#include "content/browser/download/save_item.h" |
@@ -632,10 +635,9 @@ void SavePackage::Stop(bool cancel_download_item) { |
for (const auto& it : saved_failed_items_) |
save_item_ids.push_back(it.first); |
- BrowserThread::PostTask( |
- BrowserThread::FILE, FROM_HERE, |
- base::Bind(&SaveFileManager::RemoveSavedFileFromFileMap, file_manager_, |
- save_item_ids)); |
+ GetDownloadTaskRunner()->PostTask( |
+ FROM_HERE, base::Bind(&SaveFileManager::RemoveSavedFileFromFileMap, |
+ file_manager_, save_item_ids)); |
finished_ = true; |
wait_state_ = FAILED; |
@@ -661,15 +663,11 @@ void SavePackage::CheckFinish() { |
for (const auto& it : saved_success_items_) |
final_names.insert(std::make_pair(it.first, it.second->full_path())); |
- BrowserThread::PostTask( |
- BrowserThread::FILE, FROM_HERE, |
- base::Bind(&SaveFileManager::RenameAllFiles, |
- file_manager_, |
- final_names, |
- dir, |
- web_contents()->GetRenderProcessHost()->GetID(), |
- web_contents()->GetMainFrame()->GetRoutingID(), |
- id())); |
+ GetDownloadTaskRunner()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&SaveFileManager::RenameAllFiles, file_manager_, final_names, |
+ dir, web_contents()->GetRenderProcessHost()->GetID(), |
+ web_contents()->GetMainFrame()->GetRoutingID(), id())); |
} |
// Successfully finished all items of this SavePackage. |
@@ -701,10 +699,9 @@ void SavePackage::Finish() { |
list_of_failed_save_item_ids.push_back(save_item->id()); |
} |
- BrowserThread::PostTask( |
- BrowserThread::FILE, FROM_HERE, |
- base::Bind(&SaveFileManager::RemoveSavedFileFromFileMap, file_manager_, |
- list_of_failed_save_item_ids)); |
+ GetDownloadTaskRunner()->PostTask( |
+ FROM_HERE, base::Bind(&SaveFileManager::RemoveSavedFileFromFileMap, |
+ file_manager_, list_of_failed_save_item_ids)); |
if (download_) { |
if (save_type_ != SAVE_PAGE_TYPE_AS_MHTML) { |
@@ -768,8 +765,8 @@ void SavePackage::SaveFinished(SaveItemId save_item_id, |
void SavePackage::SaveCanceled(const SaveItem* save_item) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
file_manager_->RemoveSaveFile(save_item->id(), this); |
- BrowserThread::PostTask( |
- BrowserThread::FILE, FROM_HERE, |
+ GetDownloadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&SaveFileManager::CancelSave, file_manager_, save_item->id())); |
} |
@@ -929,10 +926,9 @@ void SavePackage::GetSerializedHtmlWithLocalLinks() { |
number_of_frames_pending_response_++; |
} else { |
// Notify SaveFileManager about the failure to save this SaveItem. |
- BrowserThread::PostTask( |
- BrowserThread::FILE, FROM_HERE, |
- base::Bind(&SaveFileManager::SaveFinished, file_manager_, |
- save_item->id(), id(), false)); |
+ GetDownloadTaskRunner()->PostTask( |
+ FROM_HERE, base::Bind(&SaveFileManager::SaveFinished, file_manager_, |
+ save_item->id(), id(), false)); |
} |
} |
if (number_of_frames_pending_response_ == 0) { |
@@ -1043,8 +1039,8 @@ void SavePackage::OnSerializedHtmlWithLocalLinksResponse( |
memcpy(new_data->data(), data.data(), data.size()); |
// Call write file functionality in FILE thread. |
- BrowserThread::PostTask( |
- BrowserThread::FILE, FROM_HERE, |
+ GetDownloadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&SaveFileManager::UpdateSaveProgress, file_manager_, |
save_item->id(), base::RetainedRef(new_data), |
static_cast<int>(data.size()))); |
@@ -1054,10 +1050,9 @@ void SavePackage::OnSerializedHtmlWithLocalLinksResponse( |
if (end_of_data) { |
DVLOG(20) << __func__ << "() save_item_id = " << save_item->id() |
<< " url = \"" << save_item->url().spec() << "\""; |
- BrowserThread::PostTask( |
- BrowserThread::FILE, FROM_HERE, |
- base::Bind(&SaveFileManager::SaveFinished, file_manager_, |
- save_item->id(), id(), true)); |
+ GetDownloadTaskRunner()->PostTask( |
+ FROM_HERE, base::Bind(&SaveFileManager::SaveFinished, file_manager_, |
+ save_item->id(), id(), true)); |
number_of_frames_pending_response_--; |
DCHECK_LE(0, number_of_frames_pending_response_); |
} |
@@ -1289,7 +1284,7 @@ base::FilePath SavePackage::GetSuggestedNameForSaveAs( |
// static |
base::FilePath SavePackage::EnsureHtmlExtension(const base::FilePath& name) { |
- DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
+ base::ThreadRestrictions::AssertIOAllowed(); |
base::FilePath::StringType ext = name.Extension(); |
if (!ext.empty()) |
@@ -1306,7 +1301,7 @@ base::FilePath SavePackage::EnsureHtmlExtension(const base::FilePath& name) { |
// static |
base::FilePath SavePackage::EnsureMimeExtension(const base::FilePath& name, |
const std::string& contents_mime_type) { |
- DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
+ base::ThreadRestrictions::AssertIOAllowed(); |
// Start extension at 1 to skip over period if non-empty. |
base::FilePath::StringType ext = name.Extension(); |
@@ -1359,8 +1354,8 @@ void SavePackage::GetSaveInfo() { |
} |
std::string mime_type = web_contents()->GetContentsMimeType(); |
bool can_save_as_complete = CanSaveAsComplete(mime_type); |
- BrowserThread::PostTaskAndReplyWithResult( |
- BrowserThread::FILE, FROM_HERE, |
+ PostTaskAndReplyWithResult( |
+ GetDownloadTaskRunner().get(), FROM_HERE, |
base::Bind(&SavePackage::CreateDirectoryOnFileThread, title_, page_url_, |
can_save_as_complete, mime_type, website_save_dir, |
download_save_dir, skip_dir_check), |
@@ -1377,7 +1372,7 @@ base::FilePath SavePackage::CreateDirectoryOnFileThread( |
const base::FilePath& website_save_dir, |
const base::FilePath& download_save_dir, |
bool skip_dir_check) { |
- DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
+ DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence()); |
base::FilePath suggested_filename = GetSuggestedNameForSaveAs( |
title, page_url, can_save_as_complete, mime_type); |