From 3b08736ae2737c5fedd1114ee6069a72b924c65d Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 9 Mar 2020 16:13:59 +0000 Subject: [PATCH] refactor: migrate base::ThreadPool() as trait to base::ThreadPool:: API (#22555) --- shell/browser/api/electron_api_content_tracing.cc | 7 +++---- shell/browser/api/electron_api_net_log.cc | 5 +++-- shell/browser/api/electron_api_web_contents.cc | 5 ++--- shell/browser/common_web_contents_delegate.cc | 5 +++-- shell/browser/electron_download_manager_delegate.cc | 4 ++-- shell/browser/net/asar/asar_url_loader.cc | 5 +++-- shell/browser/ui/views/electron_views_delegate_win.cc | 6 ++---- shell/common/platform_util_win.cc | 11 ++++++----- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/shell/browser/api/electron_api_content_tracing.cc b/shell/browser/api/electron_api_content_tracing.cc index aaedaa2a798..25f95fbebe7 100644 --- a/shell/browser/api/electron_api_content_tracing.cc +++ b/shell/browser/api/electron_api_content_tracing.cc @@ -8,6 +8,7 @@ #include "base/files/file_util.h" #include "base/optional.h" +#include "base/task/thread_pool.h" #include "base/threading/thread_restrictions.h" #include "content/public/browser/tracing_controller.h" #include "shell/common/gin_converters/callback_converter.h" @@ -86,10 +87,8 @@ v8::Local StopRecording(gin_helper::Arguments* args) { StopTracing(std::move(promise), base::make_optional(path)); } else { // use a temporary file. - base::PostTaskAndReplyWithResult( - FROM_HERE, - {base::ThreadPool(), base::MayBlock(), - base::TaskPriority::USER_VISIBLE}, + base::ThreadPool::PostTaskAndReplyWithResult( + FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE}, base::BindOnce(CreateTemporaryFileOnIO), base::BindOnce(StopTracing, std::move(promise))); } diff --git a/shell/browser/api/electron_api_net_log.cc b/shell/browser/api/electron_api_net_log.cc index 5cb58b9cc23..5f89710c9cc 100644 --- a/shell/browser/api/electron_api_net_log.cc +++ b/shell/browser/api/electron_api_net_log.cc @@ -7,6 +7,7 @@ #include #include "base/command_line.h" +#include "base/task/thread_pool.h" #include "chrome/browser/browser_process.h" #include "components/net_log/chrome_net_log.h" #include "content/public/browser/storage_partition.h" @@ -52,8 +53,8 @@ scoped_refptr CreateFileTaskRunner() { // // These operations can be skipped on shutdown since FileNetLogObserver's API // doesn't require things to have completed until notified of completion. - return base::CreateSequencedTaskRunner( - {base::ThreadPool(), base::MayBlock(), base::TaskPriority::USER_VISIBLE, + return base::ThreadPool::CreateSequencedTaskRunner( + {base::MayBlock(), base::TaskPriority::USER_VISIBLE, base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}); } diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index 197742ea669..e130d91b3c9 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -1949,9 +1949,8 @@ void WebContents::Print(gin_helper::Arguments* args) { settings.SetIntKey(printing::kSettingDpiVertical, dpi); } - base::PostTaskAndReplyWithResult( - FROM_HERE, - {base::ThreadPool(), base::MayBlock(), base::TaskPriority::USER_BLOCKING}, + base::ThreadPool::PostTaskAndReplyWithResult( + FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_BLOCKING}, base::BindOnce(&GetDefaultPrinterAsync), base::BindOnce(&WebContents::OnGetDefaultPrinter, weak_factory_.GetWeakPtr(), std::move(settings), diff --git a/shell/browser/common_web_contents_delegate.cc b/shell/browser/common_web_contents_delegate.cc index 9669cba9ef5..a50c037bdfc 100644 --- a/shell/browser/common_web_contents_delegate.cc +++ b/shell/browser/common_web_contents_delegate.cc @@ -13,6 +13,7 @@ #include "base/files/file_util.h" #include "base/json/json_reader.h" #include "base/task/post_task.h" +#include "base/task/thread_pool.h" #include "base/threading/scoped_blocking_call.h" #include "base/threading/sequenced_task_runner_handle.h" #include "chrome/browser/ssl/security_state_tab_helper.h" @@ -183,8 +184,8 @@ bool IsDevToolsFileSystemAdded(content::WebContents* web_contents, CommonWebContentsDelegate::CommonWebContentsDelegate() : devtools_file_system_indexer_(new DevToolsFileSystemIndexer), - file_task_runner_(base::CreateSequencedTaskRunner( - {base::ThreadPool(), base::MayBlock()})), + file_task_runner_( + base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()})), weak_factory_(this) {} CommonWebContentsDelegate::~CommonWebContentsDelegate() = default; diff --git a/shell/browser/electron_download_manager_delegate.cc b/shell/browser/electron_download_manager_delegate.cc index bc469ee94ec..068c7f4d10b 100644 --- a/shell/browser/electron_download_manager_delegate.cc +++ b/shell/browser/electron_download_manager_delegate.cc @@ -226,9 +226,9 @@ bool ElectronDownloadManagerDelegate::DetermineDownloadTarget( base::FilePath default_download_path = browser_context->prefs()->GetFilePath(prefs::kDownloadDefaultDirectory); - base::PostTaskAndReplyWithResult( + base::ThreadPool::PostTaskAndReplyWithResult( FROM_HERE, - {base::ThreadPool(), base::MayBlock(), base::TaskPriority::BEST_EFFORT, + {base::MayBlock(), base::TaskPriority::BEST_EFFORT, base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}, base::BindOnce(&CreateDownloadPath, download->GetURL(), download->GetContentDisposition(), diff --git a/shell/browser/net/asar/asar_url_loader.cc b/shell/browser/net/asar/asar_url_loader.cc index 8ca3a474208..a5b61df3f8d 100644 --- a/shell/browser/net/asar/asar_url_loader.cc +++ b/shell/browser/net/asar/asar_url_loader.cc @@ -11,6 +11,7 @@ #include "base/strings/stringprintf.h" #include "base/task/post_task.h" +#include "base/task/thread_pool.h" #include "content/public/browser/file_url_loader.h" #include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/remote.h" @@ -304,8 +305,8 @@ void CreateAsarURLLoader( network::mojom::URLLoaderRequest loader, mojo::PendingRemote client, scoped_refptr extra_response_headers) { - auto task_runner = base::CreateSequencedTaskRunner( - {base::ThreadPool(), base::MayBlock(), base::TaskPriority::USER_VISIBLE, + auto task_runner = base::ThreadPool::CreateSequencedTaskRunner( + {base::MayBlock(), base::TaskPriority::USER_VISIBLE, base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}); task_runner->PostTask( FROM_HERE, diff --git a/shell/browser/ui/views/electron_views_delegate_win.cc b/shell/browser/ui/views/electron_views_delegate_win.cc index ff2c6f0274d..70a411cf0c3 100644 --- a/shell/browser/ui/views/electron_views_delegate_win.cc +++ b/shell/browser/ui/views/electron_views_delegate_win.cc @@ -131,10 +131,8 @@ int ViewsDelegate::GetAppbarAutohideEdges(HMONITOR monitor, if (monitor && !in_autohide_edges_callback_) { // TODO(robliao): Annotate this task with .WithCOM() once supported. // https://crbug.com/662122 - base::PostTaskAndReplyWithResult( - FROM_HERE, - {base::ThreadPool(), base::MayBlock(), - base::TaskPriority::USER_BLOCKING}, + base::ThreadPool::PostTaskAndReplyWithResult( + FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_BLOCKING}, base::BindOnce(&GetAppbarAutohideEdgesOnWorkerThread, monitor), base::BindOnce(&ViewsDelegate::OnGotAppbarAutohideEdges, weak_factory_.GetWeakPtr(), std::move(callback), monitor, diff --git a/shell/common/platform_util_win.cc b/shell/common/platform_util_win.cc index 02dd3ad7907..853666e0046 100644 --- a/shell/common/platform_util_win.cc +++ b/shell/common/platform_util_win.cc @@ -24,6 +24,7 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "base/task/post_task.h" +#include "base/task/thread_pool.h" #include "base/threading/scoped_blocking_call.h" #include "base/win/registry.h" #include "base/win/scoped_co_mem.h" @@ -317,8 +318,8 @@ std::string OpenPathOnThread(const base::FilePath& full_path) { namespace platform_util { void ShowItemInFolder(const base::FilePath& full_path) { - base::CreateCOMSTATaskRunner( - {base::ThreadPool(), base::MayBlock(), base::TaskPriority::USER_BLOCKING}) + base::ThreadPool::CreateSingleThreadTaskRunner( + {base::MayBlock(), base::TaskPriority::USER_BLOCKING}) ->PostTask(FROM_HERE, base::BindOnce(&ShowItemInFolderOnWorkerThread, full_path)); } @@ -327,7 +328,7 @@ void OpenPath(const base::FilePath& full_path, OpenCallback callback) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); base::PostTaskAndReplyWithResult( - base::CreateCOMSTATaskRunner({base::ThreadPool(), base::MayBlock(), + base::ThreadPool::CreateSingleThreadTaskRunner(({base::MayBlock(), base::TaskPriority::USER_BLOCKING}) .get(), FROM_HERE, base::BindOnce(&OpenPathOnThread, full_path), @@ -338,8 +339,8 @@ void OpenExternal(const GURL& url, const OpenExternalOptions& options, OpenCallback callback) { base::PostTaskAndReplyWithResult( - base::CreateCOMSTATaskRunner({base::ThreadPool(), base::MayBlock(), - base::TaskPriority::USER_BLOCKING}) + base::ThreadPool::CreateCOMSTATaskRunner( + {base::MayBlock(), base::TaskPriority::USER_BLOCKING}) .get(), FROM_HERE, base::BindOnce(&OpenExternalOnWorkerThread, url, options), std::move(callback));