Commit 101ea13d authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Commit Bot

Ensures BluetoothAdapterWinrt initialisation runs on foreground thread

PerformSlowInitTasks should be scheduled (BEST_EFFORT) but once it
starts executing it needs to be on a foreground thread to avoid
priority inversion.

From this crash/312ca3b6fb0c2131
  Thread 28 ThreadPoolBackgroundWorker

  LoadLibraryExW
  [...]
  RoGetActivationFactory
  device::BluetoothAdapterWinrt::PerformSlowInitTasks()
  [...]
  base::internal::WorkerThread::RunBackgroundPooledWorker()

This is blocking other threads.

R=joenotcharles@google.com

Bug: 973868
Change-Id: Ic7512ad567bc4e3a5fc549dd9c408db0047a45fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2377904Reviewed-by: default avatarJoe Mason <joenotcharles@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802019}
parent cf2d8c16
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/task/task_traits.h" #include "base/task/task_traits.h"
#include "base/task/thread_pool.h" #include "base/task/thread_pool.h"
#include "base/threading/scoped_thread_priority.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/win/core_winrt_util.h" #include "base/win/core_winrt_util.h"
#include "base/win/post_async_results.h" #include "base/win/post_async_results.h"
...@@ -660,7 +659,9 @@ void BluetoothAdapterWinrt::Initialize(base::OnceClosure init_callback) { ...@@ -660,7 +659,9 @@ void BluetoothAdapterWinrt::Initialize(base::OnceClosure init_callback) {
// Some of the initialization work requires loading libraries and should not // Some of the initialization work requires loading libraries and should not
// be run on the browser main thread. // be run on the browser main thread.
base::ThreadPool::PostTaskAndReplyWithResult( base::ThreadPool::PostTaskAndReplyWithResult(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT}, FROM_HERE,
{base::MayBlock(), base::TaskPriority::BEST_EFFORT,
base::ThreadPolicy::MUST_USE_FOREGROUND},
base::BindOnce(&BluetoothAdapterWinrt::PerformSlowInitTasks), base::BindOnce(&BluetoothAdapterWinrt::PerformSlowInitTasks),
base::BindOnce(&BluetoothAdapterWinrt::CompleteInitAgile, base::BindOnce(&BluetoothAdapterWinrt::CompleteInitAgile,
weak_ptr_factory_.GetWeakPtr(), std::move(init_callback))); weak_ptr_factory_.GetWeakPtr(), std::move(init_callback)));
...@@ -700,10 +701,6 @@ void BluetoothAdapterWinrt::InitForTests( ...@@ -700,10 +701,6 @@ void BluetoothAdapterWinrt::InitForTests(
// static // static
BluetoothAdapterWinrt::StaticsInterfaces BluetoothAdapterWinrt::StaticsInterfaces
BluetoothAdapterWinrt::PerformSlowInitTasks() { BluetoothAdapterWinrt::PerformSlowInitTasks() {
// Mitigate the issues caused by loading DLLs on a background thread
// (http://crbug/973868).
SCOPED_MAY_LOAD_LIBRARY_AT_BACKGROUND_PRIORITY();
if (!ResolveCoreWinRT()) if (!ResolveCoreWinRT())
return BluetoothAdapterWinrt::StaticsInterfaces(); return BluetoothAdapterWinrt::StaticsInterfaces();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment