Commit 5ccb18ee authored by Etienne Pierre-Doray's avatar Etienne Pierre-Doray Committed by Commit Bot

[TaskScheduler]: Migrate off of AssertBlockingAllowedDeprecated in /services/device

base::AssertBlockingAllowedDeprecated is deprecated in favor of
ScopedBlockingCall, which serves as a precise annotation of
the scope that may/will block.

Please 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: The call might block (e.g. file I/O that might hit in memory cache).
      WILL_BLOCK: The call will definitely block (e.g. cache already checked and now pinging
        server synchronously).
    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().
  - Calls to blocking //base APIs don't need to be annotated
    with ScopedBlockingCall. All blocking //base APIs (e.g. base::ReadFileToString, base::File::Read,
    base::SysInfo::AmountOfFreeDiskSpace, base::WaitableEvent::Wait, etc.) have their
    own internal annotations.

Refer to the top-level CL if necessary :
https://chromium-review.googlesource.com/c/chromium/src/+/1338391

Please CQ if LGTY!

This CL was uploaded by git cl split.

R=reillyg@chromium.org

Bug: 903957
Change-Id: I232ee84dfca8770994440c95abf2eb17f0780e83
Reviewed-on: https://chromium-review.googlesource.com/c/1338485
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610879}
parent 3ba29ef5
...@@ -84,6 +84,7 @@ void DeviceMonitorLinux::RemoveObserver(Observer* observer) { ...@@ -84,6 +84,7 @@ void DeviceMonitorLinux::RemoveObserver(Observer* observer) {
void DeviceMonitorLinux::Enumerate(const EnumerateCallback& callback) { void DeviceMonitorLinux::Enumerate(const EnumerateCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
ScopedUdevEnumeratePtr enumerate(udev_enumerate_new(udev_.get())); ScopedUdevEnumeratePtr enumerate(udev_enumerate_new(udev_.get()));
if (!enumerate) { if (!enumerate) {
...@@ -114,6 +115,7 @@ DeviceMonitorLinux::~DeviceMonitorLinux() { ...@@ -114,6 +115,7 @@ DeviceMonitorLinux::~DeviceMonitorLinux() {
void DeviceMonitorLinux::OnMonitorCanReadWithoutBlocking() { void DeviceMonitorLinux::OnMonitorCanReadWithoutBlocking() {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
ScopedUdevDevicePtr device(udev_monitor_receive_device(monitor_.get())); ScopedUdevDevicePtr device(udev_monitor_receive_device(monitor_.get()));
if (!device) if (!device)
return; return;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/threading/scoped_blocking_call.h"
namespace device { namespace device {
...@@ -16,6 +17,7 @@ void UdevWatcher::Observer::OnDeviceAdded(ScopedUdevDevicePtr device) {} ...@@ -16,6 +17,7 @@ void UdevWatcher::Observer::OnDeviceAdded(ScopedUdevDevicePtr device) {}
void UdevWatcher::Observer::OnDeviceRemoved(ScopedUdevDevicePtr device) {} void UdevWatcher::Observer::OnDeviceRemoved(ScopedUdevDevicePtr device) {}
std::unique_ptr<UdevWatcher> UdevWatcher::StartWatching(Observer* observer) { std::unique_ptr<UdevWatcher> UdevWatcher::StartWatching(Observer* observer) {
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
ScopedUdevPtr udev(udev_new()); ScopedUdevPtr udev(udev_new());
if (!udev) { if (!udev) {
LOG(ERROR) << "Failed to initialize udev."; LOG(ERROR) << "Failed to initialize udev.";
...@@ -50,6 +52,7 @@ UdevWatcher::~UdevWatcher() { ...@@ -50,6 +52,7 @@ UdevWatcher::~UdevWatcher() {
void UdevWatcher::EnumerateExistingDevices() { void UdevWatcher::EnumerateExistingDevices() {
DCHECK(sequence_checker_.CalledOnValidSequence()); DCHECK(sequence_checker_.CalledOnValidSequence());
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
ScopedUdevEnumeratePtr enumerate(udev_enumerate_new(udev_.get())); ScopedUdevEnumeratePtr enumerate(udev_enumerate_new(udev_.get()));
if (!enumerate) { if (!enumerate) {
LOG(ERROR) << "Failed to initialize a udev enumerator."; LOG(ERROR) << "Failed to initialize a udev enumerator.";
...@@ -84,6 +87,7 @@ UdevWatcher::UdevWatcher(ScopedUdevPtr udev, ...@@ -84,6 +87,7 @@ UdevWatcher::UdevWatcher(ScopedUdevPtr udev,
} }
void UdevWatcher::OnMonitorReadable() { void UdevWatcher::OnMonitorReadable() {
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
ScopedUdevDevicePtr device(udev_monitor_receive_device(udev_monitor_.get())); ScopedUdevDevicePtr device(udev_monitor_receive_device(udev_monitor_.get()));
if (!device) if (!device)
return; return;
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted_memory.h" #include "base/memory/ref_counted_memory.h"
#include "base/posix/eintr_wrapper.h" #include "base/posix/eintr_wrapper.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/scoped_blocking_call.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "components/device_event_log/device_event_log.h" #include "components/device_event_log/device_event_log.h"
#include "services/device/hid/hid_service.h" #include "services/device/hid/hid_service.h"
...@@ -52,7 +52,6 @@ class HidConnectionLinux::BlockingTaskHelper { ...@@ -52,7 +52,6 @@ class HidConnectionLinux::BlockingTaskHelper {
// Must be called on a thread that has a base::MessageLoopForIO. // Must be called on a thread that has a base::MessageLoopForIO.
void Start() { void Start() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::AssertBlockingAllowedDeprecated();
file_watcher_ = base::FileDescriptorWatcher::WatchReadable( file_watcher_ = base::FileDescriptorWatcher::WatchReadable(
fd_.get(), base::Bind(&BlockingTaskHelper::OnFileCanReadWithoutBlocking, fd_.get(), base::Bind(&BlockingTaskHelper::OnFileCanReadWithoutBlocking,
...@@ -62,6 +61,9 @@ class HidConnectionLinux::BlockingTaskHelper { ...@@ -62,6 +61,9 @@ class HidConnectionLinux::BlockingTaskHelper {
void Write(scoped_refptr<base::RefCountedBytes> buffer, void Write(scoped_refptr<base::RefCountedBytes> buffer,
WriteCallback callback) { WriteCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::ScopedBlockingCall scoped_blocking_call(
base::BlockingType::MAY_BLOCK);
ssize_t result = ssize_t result =
HANDLE_EINTR(write(fd_.get(), buffer->front(), buffer->size())); HANDLE_EINTR(write(fd_.get(), buffer->front(), buffer->size()));
if (result < 0) { if (result < 0) {
...@@ -82,6 +84,9 @@ class HidConnectionLinux::BlockingTaskHelper { ...@@ -82,6 +84,9 @@ class HidConnectionLinux::BlockingTaskHelper {
scoped_refptr<base::RefCountedBytes> buffer, scoped_refptr<base::RefCountedBytes> buffer,
ReadCallback callback) { ReadCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::ScopedBlockingCall scoped_blocking_call(
base::BlockingType::MAY_BLOCK);
int result = HANDLE_EINTR( int result = HANDLE_EINTR(
ioctl(fd_.get(), HIDIOCGFEATURE(buffer->size()), buffer->front())); ioctl(fd_.get(), HIDIOCGFEATURE(buffer->size()), buffer->front()));
if (result < 0) { if (result < 0) {
...@@ -109,6 +114,9 @@ class HidConnectionLinux::BlockingTaskHelper { ...@@ -109,6 +114,9 @@ class HidConnectionLinux::BlockingTaskHelper {
void SendFeatureReport(scoped_refptr<base::RefCountedBytes> buffer, void SendFeatureReport(scoped_refptr<base::RefCountedBytes> buffer,
WriteCallback callback) { WriteCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::ScopedBlockingCall scoped_blocking_call(
base::BlockingType::MAY_BLOCK);
int result = HANDLE_EINTR( int result = HANDLE_EINTR(
ioctl(fd_.get(), HIDIOCSFEATURE(buffer->size()), buffer->front())); ioctl(fd_.get(), HIDIOCSFEATURE(buffer->size()), buffer->front()));
if (result < 0) { if (result < 0) {
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/scoped_blocking_call.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/device_event_log/device_event_log.h" #include "components/device_event_log/device_event_log.h"
...@@ -80,7 +80,6 @@ class HidServiceLinux::BlockingTaskHelper : public UdevWatcher::Observer { ...@@ -80,7 +80,6 @@ class HidServiceLinux::BlockingTaskHelper : public UdevWatcher::Observer {
} }
void Start() { void Start() {
base::AssertBlockingAllowedDeprecated();
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
watcher_ = UdevWatcher::StartWatching(this); watcher_ = UdevWatcher::StartWatching(this);
...@@ -94,6 +93,9 @@ class HidServiceLinux::BlockingTaskHelper : public UdevWatcher::Observer { ...@@ -94,6 +93,9 @@ class HidServiceLinux::BlockingTaskHelper : public UdevWatcher::Observer {
// UdevWatcher::Observer // UdevWatcher::Observer
void OnDeviceAdded(ScopedUdevDevicePtr device) override { void OnDeviceAdded(ScopedUdevDevicePtr device) override {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::ScopedBlockingCall scoped_blocking_call(
base::BlockingType::MAY_BLOCK);
const char* device_path = udev_device_get_syspath(device.get()); const char* device_path = udev_device_get_syspath(device.get());
if (!device_path) if (!device_path)
return; return;
...@@ -168,6 +170,9 @@ class HidServiceLinux::BlockingTaskHelper : public UdevWatcher::Observer { ...@@ -168,6 +170,9 @@ class HidServiceLinux::BlockingTaskHelper : public UdevWatcher::Observer {
void OnDeviceRemoved(ScopedUdevDevicePtr device) override { void OnDeviceRemoved(ScopedUdevDevicePtr device) override {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::ScopedBlockingCall scoped_blocking_call(
base::BlockingType::MAY_BLOCK);
const char* device_path = udev_device_get_syspath(device.get()); const char* device_path = udev_device_get_syspath(device.get());
if (device_path) { if (device_path) {
task_runner_->PostTask( task_runner_->PostTask(
...@@ -266,7 +271,7 @@ void HidServiceLinux::OnPathOpenError(const std::string& device_path, ...@@ -266,7 +271,7 @@ void HidServiceLinux::OnPathOpenError(const std::string& device_path,
// static // static
void HidServiceLinux::OpenOnBlockingThread( void HidServiceLinux::OpenOnBlockingThread(
std::unique_ptr<ConnectParams> params) { std::unique_ptr<ConnectParams> params) {
base::AssertBlockingAllowedDeprecated(); base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
scoped_refptr<base::SequencedTaskRunner> task_runner = params->task_runner; scoped_refptr<base::SequencedTaskRunner> task_runner = params->task_runner;
base::FilePath device_path(params->device_info->device_node()); base::FilePath device_path(params->device_info->device_node());
...@@ -299,7 +304,6 @@ void HidServiceLinux::OpenOnBlockingThread( ...@@ -299,7 +304,6 @@ void HidServiceLinux::OpenOnBlockingThread(
// static // static
void HidServiceLinux::FinishOpen(std::unique_ptr<ConnectParams> params) { void HidServiceLinux::FinishOpen(std::unique_ptr<ConnectParams> params) {
base::AssertBlockingAllowedDeprecated();
scoped_refptr<base::SequencedTaskRunner> task_runner = params->task_runner; scoped_refptr<base::SequencedTaskRunner> task_runner = params->task_runner;
if (!base::SetNonBlocking(params->fd.get())) { if (!base::SetNonBlocking(params->fd.get())) {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/scoped_blocking_call.h"
#include "device/base/device_monitor_linux.h" #include "device/base/device_monitor_linux.h"
#include "device/udev_linux/udev.h" #include "device/udev_linux/udev.h"
...@@ -101,8 +101,6 @@ class InputServiceLinuxImpl : public InputServiceLinux, ...@@ -101,8 +101,6 @@ class InputServiceLinuxImpl : public InputServiceLinux,
}; };
InputServiceLinuxImpl::InputServiceLinuxImpl() : observer_(this) { InputServiceLinuxImpl::InputServiceLinuxImpl() : observer_(this) {
base::AssertBlockingAllowedDeprecated();
DeviceMonitorLinux* monitor = DeviceMonitorLinux::GetInstance(); DeviceMonitorLinux* monitor = DeviceMonitorLinux::GetInstance();
observer_.Add(monitor); observer_.Add(monitor);
monitor->Enumerate(base::Bind(&InputServiceLinuxImpl::OnDeviceAdded, monitor->Enumerate(base::Bind(&InputServiceLinuxImpl::OnDeviceAdded,
...@@ -116,6 +114,8 @@ InputServiceLinuxImpl::~InputServiceLinuxImpl() { ...@@ -116,6 +114,8 @@ InputServiceLinuxImpl::~InputServiceLinuxImpl() {
void InputServiceLinuxImpl::OnDeviceAdded(udev_device* device) { void InputServiceLinuxImpl::OnDeviceAdded(udev_device* device) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
if (!device) if (!device)
return; return;
const char* devnode = udev_device_get_devnode(device); const char* devnode = udev_device_get_devnode(device);
...@@ -156,6 +156,8 @@ void InputServiceLinuxImpl::OnDeviceRemoved(udev_device* device) { ...@@ -156,6 +156,8 @@ void InputServiceLinuxImpl::OnDeviceRemoved(udev_device* device) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
if (!device) if (!device)
return; return;
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
const char* devnode = udev_device_get_devnode(device); const char* devnode = udev_device_get_devnode(device);
if (devnode) if (devnode)
RemoveDevice(devnode); RemoveDevice(devnode);
......
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