Move away from BrowserThread::FILE
* Migrate TtsPlatformImplLinux away from using BrowserThread::FILE. https://chromium-review.googlesource.com/c/chromium/src/+/570022 * Move PdfConverter off the FILE thread. https://chromium-review.googlesource.com/c/chromium/src/+/592393 * https://chromium.googlesource.com/chromium/src/+/master/docs/task_scheduler_migration.md
This commit is contained in:
parent
6d241e972b
commit
e3c580e905
6 changed files with 124 additions and 100 deletions
|
@ -14,6 +14,7 @@
|
|||
#include "atom/common/options_switches.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/task_scheduler/post_task.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "content/public/browser/browser_context.h"
|
||||
|
@ -26,15 +27,11 @@ namespace atom {
|
|||
namespace {
|
||||
|
||||
// Generate default file path to save the download.
|
||||
void CreateDownloadPath(
|
||||
const GURL& url,
|
||||
const std::string& content_disposition,
|
||||
const std::string& suggested_filename,
|
||||
const std::string& mime_type,
|
||||
const base::FilePath& default_download_path,
|
||||
const AtomDownloadManagerDelegate::CreateDownloadPathCallback& callback) {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
|
||||
|
||||
base::FilePath CreateDownloadPath(const GURL& url,
|
||||
const std::string& content_disposition,
|
||||
const std::string& suggested_filename,
|
||||
const std::string& mime_type,
|
||||
const base::FilePath& default_download_path) {
|
||||
auto generated_name =
|
||||
net::GenerateFileName(url, content_disposition, std::string(),
|
||||
suggested_filename, mime_type, "download");
|
||||
|
@ -42,9 +39,7 @@ void CreateDownloadPath(
|
|||
if (!base::PathExists(default_download_path))
|
||||
base::CreateDirectory(default_download_path);
|
||||
|
||||
base::FilePath path(default_download_path.Append(generated_name));
|
||||
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
|
||||
base::BindOnce(callback, path));
|
||||
return default_download_path.Append(generated_name);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -161,16 +156,17 @@ bool AtomDownloadManagerDelegate::DetermineDownloadTarget(
|
|||
base::FilePath default_download_path =
|
||||
browser_context->prefs()->GetFilePath(prefs::kDownloadDefaultDirectory);
|
||||
|
||||
CreateDownloadPathCallback download_path_callback =
|
||||
base::Bind(&AtomDownloadManagerDelegate::OnDownloadPathGenerated,
|
||||
weak_ptr_factory_.GetWeakPtr(), download->GetId(), callback);
|
||||
|
||||
content::BrowserThread::PostTask(
|
||||
content::BrowserThread::FILE, FROM_HERE,
|
||||
base::PostTaskWithTraitsAndReplyWithResult(
|
||||
FROM_HERE,
|
||||
{base::MayBlock(), base::TaskPriority::BACKGROUND,
|
||||
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
|
||||
base::BindOnce(&CreateDownloadPath, download->GetURL(),
|
||||
download->GetContentDisposition(),
|
||||
download->GetSuggestedFilename(), download->GetMimeType(),
|
||||
default_download_path, download_path_callback));
|
||||
default_download_path),
|
||||
base::BindOnce(&AtomDownloadManagerDelegate::OnDownloadPathGenerated,
|
||||
weak_ptr_factory_.GetWeakPtr(), download->GetId(),
|
||||
callback));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue