Commit a1e81dfd 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 /chrome/browser/apps/platform_apps/.

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: 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().

This CL was uploaded by git cl split.

TBR=dominickn@chromium.org

Bug: 874080
Change-Id: Iceac744a259b8feaba56efc153c0eaed7392cf90
Reviewed-on: https://chromium-review.googlesource.com/c/1255601
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602344}
parent 5133da7f
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#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/task/post_task.h" #include "base/task/post_task.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/scoped_blocking_call.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
...@@ -48,7 +48,7 @@ const char* const kNetDeviceNamePrefixes[] = { ...@@ -48,7 +48,7 @@ const char* const kNetDeviceNamePrefixes[] = {
typedef std::map<base::FilePath, base::FilePath> DiskEntries; typedef std::map<base::FilePath, base::FilePath> DiskEntries;
std::string GetDiskUuid() { std::string GetDiskUuid() {
base::AssertBlockingAllowedDeprecated(); base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
DiskEntries disk_uuids; DiskEntries disk_uuids;
base::FileEnumerator files(base::FilePath(kDiskByUuidDirectoryName), base::FileEnumerator files(base::FilePath(kDiskByUuidDirectoryName),
...@@ -71,7 +71,7 @@ std::string GetDiskUuid() { ...@@ -71,7 +71,7 @@ std::string GetDiskUuid() {
// Look for first device name matching an entry of |kDeviceNames|. // Look for first device name matching an entry of |kDeviceNames|.
std::string result; std::string result;
for (size_t i = 0; i < arraysize(kDeviceNames); i++) { for (size_t i = 0; i < arraysize(kDeviceNames); i++) {
auto it = disk_uuids.find(base::FilePath(kDeviceNames[i])); DiskEntries::iterator it = disk_uuids.find(base::FilePath(kDeviceNames[i]));
if (it != disk_uuids.end()) { if (it != disk_uuids.end()) {
DVLOG(1) << "Returning uuid: \"" << it->second.value() DVLOG(1) << "Returning uuid: \"" << it->second.value()
<< "\" for device \"" << it->first.value() << "\""; << "\" for device \"" << it->first.value() << "\"";
...@@ -85,7 +85,8 @@ std::string GetDiskUuid() { ...@@ -85,7 +85,8 @@ std::string GetDiskUuid() {
if (result.empty() && !error_logged) { if (result.empty() && !error_logged) {
error_logged = true; error_logged = true;
LOG(ERROR) << "Could not find appropriate disk uuid."; LOG(ERROR) << "Could not find appropriate disk uuid.";
for (auto it = disk_uuids.begin(); it != disk_uuids.end(); ++it) { for (DiskEntries::iterator it = disk_uuids.begin(); it != disk_uuids.end();
++it) {
LOG(ERROR) << " DeviceID=" << it->first.value() LOG(ERROR) << " DeviceID=" << it->first.value()
<< ", uuid=" << it->second.value(); << ", uuid=" << it->second.value();
} }
...@@ -149,7 +150,7 @@ class MacAddressProcessor { ...@@ -149,7 +150,7 @@ class MacAddressProcessor {
std::string GetMacAddress( std::string GetMacAddress(
const IsValidMacAddressCallback& is_valid_mac_address) { const IsValidMacAddressCallback& is_valid_mac_address) {
base::AssertBlockingAllowedDeprecated(); base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
struct ifaddrs* ifaddrs; struct ifaddrs* ifaddrs;
int rv = getifaddrs(&ifaddrs); int rv = getifaddrs(&ifaddrs);
...@@ -171,8 +172,6 @@ std::string GetMacAddress( ...@@ -171,8 +172,6 @@ std::string GetMacAddress(
void GetRawDeviceIdImpl(const IsValidMacAddressCallback& is_valid_mac_address, void GetRawDeviceIdImpl(const IsValidMacAddressCallback& is_valid_mac_address,
const DeviceId::IdCallback& callback) { const DeviceId::IdCallback& callback) {
base::AssertBlockingAllowedDeprecated();
std::string disk_id = GetDiskUuid(); std::string disk_id = GetDiskUuid();
std::string mac_address = GetMacAddress(is_valid_mac_address); std::string mac_address = GetMacAddress(is_valid_mac_address);
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#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/task/post_task.h" #include "base/task/post_task.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/scoped_blocking_call.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
...@@ -40,6 +40,8 @@ typedef base::Callback<bool(const void* bytes, size_t size)> ...@@ -40,6 +40,8 @@ typedef base::Callback<bool(const void* bytes, size_t size)>
// through the mounted volumes . // through the mounted volumes .
// Return "" if an error occured. // Return "" if an error occured.
std::string FindBSDNameOfSystemDisk() { std::string FindBSDNameOfSystemDisk() {
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
struct statfs* mounted_volumes; struct statfs* mounted_volumes;
int num_volumes = getmntinfo(&mounted_volumes, 0); int num_volumes = getmntinfo(&mounted_volumes, 0);
if (num_volumes == 0) { if (num_volumes == 0) {
...@@ -61,6 +63,8 @@ std::string FindBSDNameOfSystemDisk() { ...@@ -61,6 +63,8 @@ std::string FindBSDNameOfSystemDisk() {
// Return the Volume UUID property of a BSD disk name (e.g. '/dev/disk1'). // Return the Volume UUID property of a BSD disk name (e.g. '/dev/disk1').
// Return "" if an error occured. // Return "" if an error occured.
std::string GetVolumeUUIDFromBSDName(const std::string& bsd_name) { std::string GetVolumeUUIDFromBSDName(const std::string& bsd_name) {
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
const CFAllocatorRef allocator = NULL; const CFAllocatorRef allocator = NULL;
base::ScopedCFTypeRef<DASessionRef> session(DASessionCreate(allocator)); base::ScopedCFTypeRef<DASessionRef> session(DASessionCreate(allocator));
...@@ -102,8 +106,6 @@ std::string GetVolumeUUIDFromBSDName(const std::string& bsd_name) { ...@@ -102,8 +106,6 @@ std::string GetVolumeUUIDFromBSDName(const std::string& bsd_name) {
// Return Volume UUID property of disk mounted as "/". // Return Volume UUID property of disk mounted as "/".
std::string GetVolumeUUID() { std::string GetVolumeUUID() {
base::AssertBlockingAllowedDeprecated();
std::string result; std::string result;
std::string bsd_name = FindBSDNameOfSystemDisk(); std::string bsd_name = FindBSDNameOfSystemDisk();
if (!bsd_name.empty()) { if (!bsd_name.empty()) {
...@@ -163,7 +165,7 @@ class MacAddressProcessor { ...@@ -163,7 +165,7 @@ class MacAddressProcessor {
std::string GetMacAddress( std::string GetMacAddress(
const IsValidMacAddressCallback& is_valid_mac_address) { const IsValidMacAddressCallback& is_valid_mac_address) {
base::AssertBlockingAllowedDeprecated(); base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
mach_port_t master_port; mach_port_t master_port;
kern_return_t kr = IOMasterPort(MACH_PORT_NULL, &master_port); kern_return_t kr = IOMasterPort(MACH_PORT_NULL, &master_port);
...@@ -213,8 +215,6 @@ std::string GetMacAddress( ...@@ -213,8 +215,6 @@ std::string GetMacAddress(
void GetRawDeviceIdImpl(const IsValidMacAddressCallback& is_valid_mac_address, void GetRawDeviceIdImpl(const IsValidMacAddressCallback& is_valid_mac_address,
const DeviceId::IdCallback& callback) { const DeviceId::IdCallback& callback) {
base::AssertBlockingAllowedDeprecated();
std::string raw_device_id; std::string raw_device_id;
std::string mac_address = GetMacAddress(is_valid_mac_address); std::string mac_address = GetMacAddress(is_valid_mac_address);
std::string disk_id = GetVolumeUUID(); std::string disk_id = GetVolumeUUID();
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#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/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/win/windows_version.h" #include "base/win/windows_version.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
...@@ -89,7 +89,7 @@ class MacAddressProcessor { ...@@ -89,7 +89,7 @@ class MacAddressProcessor {
std::string GetMacAddressFromGetAdaptersAddresses( std::string GetMacAddressFromGetAdaptersAddresses(
const IsValidMacAddressCallback& is_valid_mac_address) { const IsValidMacAddressCallback& is_valid_mac_address) {
base::AssertBlockingAllowedDeprecated(); base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
// MS recommends a default size of 15k. // MS recommends a default size of 15k.
ULONG bufferSize = 15 * 1024; ULONG bufferSize = 15 * 1024;
...@@ -124,7 +124,7 @@ std::string GetMacAddressFromGetAdaptersAddresses( ...@@ -124,7 +124,7 @@ std::string GetMacAddressFromGetAdaptersAddresses(
std::string GetMacAddressFromGetIfTable2( std::string GetMacAddressFromGetIfTable2(
const IsValidMacAddressCallback& is_valid_mac_address) { const IsValidMacAddressCallback& is_valid_mac_address) {
base::AssertBlockingAllowedDeprecated(); base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
// This is available on Vista+ only. // This is available on Vista+ only.
base::ScopedNativeLibrary library(base::FilePath(L"Iphlpapi.dll")); base::ScopedNativeLibrary library(base::FilePath(L"Iphlpapi.dll"));
...@@ -162,8 +162,6 @@ std::string GetMacAddressFromGetIfTable2( ...@@ -162,8 +162,6 @@ std::string GetMacAddressFromGetIfTable2(
void GetMacAddress(const IsValidMacAddressCallback& is_valid_mac_address, void GetMacAddress(const IsValidMacAddressCallback& is_valid_mac_address,
const DeviceId::IdCallback& callback) { const DeviceId::IdCallback& callback) {
base::AssertBlockingAllowedDeprecated();
std::string mac_address = std::string mac_address =
GetMacAddressFromGetAdaptersAddresses(is_valid_mac_address); GetMacAddressFromGetAdaptersAddresses(is_valid_mac_address);
if (mac_address.empty()) if (mac_address.empty())
......
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