Commit 226c6cce authored by Etienne Pierre-doray's avatar Etienne Pierre-doray Committed by Commit Bot

[TaskScheduler]: Use ScopedBlockingCall to mark blocking tasks.

This CL uses ScopedBlockingCall to mark blocking calls in /device.

This CL was created by replacing calls to AssertBlockingAllowed()
with instantiations of ScopedBlockingCall(MAY_BLOCK).
I kindly ask the reviewer to make sure of the following:
  - ScopedBlockingCall is instantiated in a scope with minimal CPU usage.
    If this is not the case, ScopedBlockingCall should be instantiated
    closer to the blocking call. See scoped_blocking_call.h for more
    info. Please let me know when/where the blocking call happens if this needs
    to be changed.
  - Parameter |blocking_type| matches expectation (MAY_BLOCK/WILL_BLOCK). See
    BlockingType for more info. While I assumed MAY_BLOCK by default, that might
    not be the best fit if we know that this callsite is guaranteed to block.
  - The ScopedBlockingCall's scope covers the entirety of the blocking operation
    previously asserted against by the AssertBlockingAllowed().

This CL was uploaded by git cl split.

R=reillyg@chromium.org

Bug: 874080
Change-Id: I1bad5e82040c40aa770c36d3825dfc14dd9aad0f
Reviewed-on: https://chromium-review.googlesource.com/1191813Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592887}
parent fbaa5f90
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/scoped_blocking_call.h"
#include "device/udev_linux/udev.h" #include "device/udev_linux/udev.h"
namespace device { namespace device {
...@@ -28,7 +28,7 @@ base::LazyInstance<DeviceMonitorLinux>::Leaky g_device_monitor_linux = ...@@ -28,7 +28,7 @@ base::LazyInstance<DeviceMonitorLinux>::Leaky g_device_monitor_linux =
} // namespace } // namespace
DeviceMonitorLinux::DeviceMonitorLinux() : monitor_fd_(-1) { DeviceMonitorLinux::DeviceMonitorLinux() : monitor_fd_(-1) {
base::AssertBlockingAllowed(); base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
udev_.reset(udev_new()); udev_.reset(udev_new());
if (!udev_) { if (!udev_) {
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/scoped_blocking_call.h"
namespace device { namespace device {
...@@ -41,7 +41,7 @@ SerialDeviceEnumeratorLinux::~SerialDeviceEnumeratorLinux() = default; ...@@ -41,7 +41,7 @@ SerialDeviceEnumeratorLinux::~SerialDeviceEnumeratorLinux() = default;
std::vector<mojom::SerialDeviceInfoPtr> std::vector<mojom::SerialDeviceInfoPtr>
SerialDeviceEnumeratorLinux::GetDevices() { SerialDeviceEnumeratorLinux::GetDevices() {
base::AssertBlockingAllowed(); base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
std::vector<mojom::SerialDeviceInfoPtr> devices; std::vector<mojom::SerialDeviceInfoPtr> devices;
ScopedUdevEnumeratePtr enumerate(udev_enumerate_new(udev_.get())); ScopedUdevEnumeratePtr enumerate(udev_enumerate_new(udev_.get()));
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include "base/strings/pattern.h" #include "base/strings/pattern.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/scoped_blocking_call.h"
namespace device { namespace device {
...@@ -104,7 +104,8 @@ int Clamp(int value, int min, int max) { ...@@ -104,7 +104,8 @@ int Clamp(int value, int min, int max) {
// about the devices than the old method. // about the devices than the old method.
std::vector<mojom::SerialDeviceInfoPtr> GetDevicesNew() { std::vector<mojom::SerialDeviceInfoPtr> GetDevicesNew() {
std::vector<mojom::SerialDeviceInfoPtr> devices; std::vector<mojom::SerialDeviceInfoPtr> devices;
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
// Make a service query to find all serial devices. // Make a service query to find all serial devices.
CFMutableDictionaryRef matchingDict = CFMutableDictionaryRef matchingDict =
IOServiceMatching(kIOSerialBSDServiceValue); IOServiceMatching(kIOSerialBSDServiceValue);
...@@ -182,6 +183,7 @@ std::vector<mojom::SerialDeviceInfoPtr> GetDevicesOld() { ...@@ -182,6 +183,7 @@ std::vector<mojom::SerialDeviceInfoPtr> GetDevicesOld() {
valid_patterns.insert("/dev/tty.*"); valid_patterns.insert("/dev/tty.*");
valid_patterns.insert("/dev/cu.*"); valid_patterns.insert("/dev/cu.*");
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
std::vector<mojom::SerialDeviceInfoPtr> devices; std::vector<mojom::SerialDeviceInfoPtr> devices;
base::FileEnumerator enumerator(kDevRoot, false, kFilesAndSymLinks); base::FileEnumerator enumerator(kDevRoot, false, kFilesAndSymLinks);
do { do {
...@@ -217,8 +219,6 @@ SerialDeviceEnumeratorMac::~SerialDeviceEnumeratorMac() {} ...@@ -217,8 +219,6 @@ SerialDeviceEnumeratorMac::~SerialDeviceEnumeratorMac() {}
std::vector<mojom::SerialDeviceInfoPtr> std::vector<mojom::SerialDeviceInfoPtr>
SerialDeviceEnumeratorMac::GetDevices() { SerialDeviceEnumeratorMac::GetDevices() {
base::AssertBlockingAllowed();
std::vector<mojom::SerialDeviceInfoPtr> devices = GetDevicesNew(); std::vector<mojom::SerialDeviceInfoPtr> devices = GetDevicesNew();
std::vector<mojom::SerialDeviceInfoPtr> old_devices = GetDevicesOld(); std::vector<mojom::SerialDeviceInfoPtr> old_devices = GetDevicesOld();
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/scoped_blocking_call.h"
#include "base/win/registry.h" #include "base/win/registry.h"
#include "third_party/re2/src/re2/re2.h" #include "third_party/re2/src/re2/re2.h"
...@@ -93,6 +93,7 @@ int Clamp(int value, int min, int max) { ...@@ -93,6 +93,7 @@ int Clamp(int value, int min, int max) {
std::vector<mojom::SerialDeviceInfoPtr> GetDevicesNew() { std::vector<mojom::SerialDeviceInfoPtr> GetDevicesNew() {
std::vector<mojom::SerialDeviceInfoPtr> devices; std::vector<mojom::SerialDeviceInfoPtr> devices;
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
// Make a device interface query to find all serial devices. // Make a device interface query to find all serial devices.
HDEVINFO dev_info = HDEVINFO dev_info =
SetupDiGetClassDevs(&GUID_DEVCLASS_PORTS, 0, 0, DIGCF_PRESENT); SetupDiGetClassDevs(&GUID_DEVCLASS_PORTS, 0, 0, DIGCF_PRESENT);
...@@ -143,6 +144,7 @@ std::vector<mojom::SerialDeviceInfoPtr> GetDevicesNew() { ...@@ -143,6 +144,7 @@ std::vector<mojom::SerialDeviceInfoPtr> GetDevicesNew() {
// enumerating serial devices (searching the registry). This old method gives // enumerating serial devices (searching the registry). This old method gives
// less information about the devices than the new method. // less information about the devices than the new method.
std::vector<mojom::SerialDeviceInfoPtr> GetDevicesOld() { std::vector<mojom::SerialDeviceInfoPtr> GetDevicesOld() {
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
base::win::RegistryValueIterator iter_key( base::win::RegistryValueIterator iter_key(
HKEY_LOCAL_MACHINE, L"HARDWARE\\DEVICEMAP\\SERIALCOMM\\"); HKEY_LOCAL_MACHINE, L"HARDWARE\\DEVICEMAP\\SERIALCOMM\\");
std::vector<mojom::SerialDeviceInfoPtr> devices; std::vector<mojom::SerialDeviceInfoPtr> devices;
...@@ -168,8 +170,6 @@ SerialDeviceEnumeratorWin::~SerialDeviceEnumeratorWin() {} ...@@ -168,8 +170,6 @@ SerialDeviceEnumeratorWin::~SerialDeviceEnumeratorWin() {}
std::vector<mojom::SerialDeviceInfoPtr> std::vector<mojom::SerialDeviceInfoPtr>
SerialDeviceEnumeratorWin::GetDevices() { SerialDeviceEnumeratorWin::GetDevices() {
base::AssertBlockingAllowed();
std::vector<mojom::SerialDeviceInfoPtr> devices = GetDevicesNew(); std::vector<mojom::SerialDeviceInfoPtr> devices = GetDevicesNew();
std::vector<mojom::SerialDeviceInfoPtr> old_devices = GetDevicesOld(); std::vector<mojom::SerialDeviceInfoPtr> old_devices = GetDevicesOld();
......
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