Commit 2d56a039 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 /components/download.

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=shaktisahu@chromium.org

TBR=shaktisahu@chromium.org

Bug: 874080
Change-Id: Icf3e527d0d344e099a9debe054a8046273baebef
Reviewed-on: https://chromium-review.googlesource.com/1191096
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594725}
parent b8d2f6cc
......@@ -11,7 +11,7 @@
#include "base/stl_util.h"
#include "base/sys_info.h"
#include "base/task_runner_util.h"
#include "base/threading/thread_restrictions.h"
#include "base/threading/scoped_blocking_call.h"
namespace download {
......@@ -24,7 +24,7 @@ bool CalculateDiskUtilization(const base::FilePath& file_dir,
int64_t& total_disk_space,
int64_t& free_disk_space,
int64_t& files_size) {
base::AssertBlockingAllowed();
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
base::FileEnumerator file_enumerator(file_dir, false /* recursive */,
base::FileEnumerator::FILES);
......@@ -79,7 +79,7 @@ bool InitializeAndCreateDownloadDirectory(const base::FilePath& dir_path) {
void GetFilesInDirectory(const base::FilePath& directory,
std::set<base::FilePath>& paths_out) {
base::AssertBlockingAllowed();
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
base::FileEnumerator file_enumerator(directory, false /* recursive */,
base::FileEnumerator::FILES);
......@@ -91,7 +91,7 @@ void GetFilesInDirectory(const base::FilePath& directory,
void DeleteFilesOnFileThread(const std::set<base::FilePath>& paths,
stats::FileCleanupReason reason) {
base::AssertBlockingAllowed();
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
int num_delete_attempted = 0;
int num_delete_failed = 0;
int num_delete_by_external = 0;
......@@ -116,7 +116,7 @@ void DeleteFilesOnFileThread(const std::set<base::FilePath>& paths,
void DeleteUnknownFilesOnFileThread(
const base::FilePath& directory,
const std::set<base::FilePath>& download_file_paths) {
base::AssertBlockingAllowed();
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
std::set<base::FilePath> files_in_dir;
GetFilesInDirectory(directory, files_in_dir);
......@@ -127,7 +127,7 @@ void DeleteUnknownFilesOnFileThread(
}
bool HardRecoverOnFileThread(const base::FilePath& directory) {
base::AssertBlockingAllowed();
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
std::set<base::FilePath> files_in_dir;
GetFilesInDirectory(directory, files_in_dir);
DeleteFilesOnFileThread(files_in_dir,
......
......@@ -15,7 +15,7 @@
#include "base/guid.h"
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "base/threading/scoped_blocking_call.h"
#include "components/download/public/common/download_interrupt_reasons_utils.h"
#include "components/download/public/common/download_stats.h"
......@@ -235,7 +235,7 @@ DownloadInterruptReason MapShFileOperationCodes(int code) {
// Returns a network error, or net::OK for success.
DownloadInterruptReason BaseFile::MoveFileAndAdjustPermissions(
const base::FilePath& new_path) {
base::AssertBlockingAllowed();
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
// The parameters to SHFileOperation must be terminated with 2 NULL chars.
base::FilePath::StringType source = full_path_.value();
......
......@@ -10,7 +10,7 @@
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/threading/thread_restrictions.h"
#include "base/threading/scoped_blocking_call.h"
#include "components/download/quarantine/common_linux.h"
#include "url/gurl.h"
......@@ -23,7 +23,7 @@ bool SetExtendedFileAttribute(const char* path,
const char* value,
size_t value_size,
int flags) {
base::AssertBlockingAllowed();
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
int result = setxattr(path, name, value, value_size, flags);
if (result) {
DPLOG(ERROR) << "Could not set extended attribute " << name << " on file "
......
......@@ -17,7 +17,7 @@
#include "base/mac/scoped_cftyperef.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "base/threading/scoped_blocking_call.h"
#include "components/download/quarantine/common_mac.h"
#include "url/gurl.h"
......@@ -99,7 +99,7 @@ namespace {
bool AddOriginMetadataToFile(const base::FilePath& file,
const GURL& source,
const GURL& referrer) {
base::AssertBlockingAllowed();
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
// There's no declaration for MDItemSetAttribute in any known public SDK.
// It exists in the 10.4 and 10.5 runtimes. To play it safe, do the lookup
// at runtime instead of declaring it ourselves and linking against what's
......@@ -169,7 +169,7 @@ bool AddOriginMetadataToFile(const base::FilePath& file,
bool AddQuarantineMetadataToFile(const base::FilePath& file,
const GURL& source,
const GURL& referrer) {
base::AssertBlockingAllowed();
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
base::scoped_nsobject<NSMutableDictionary> properties;
bool success = false;
if (@available(macos 10.10, *)) {
......
......@@ -25,7 +25,7 @@
#include "base/metrics/histogram_macros.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/win/scoped_handle.h"
#include "base/win/win_util.h"
#include "components/download/quarantine/common_win.h"
......@@ -215,7 +215,7 @@ QuarantineFileResult QuarantineFile(const base::FilePath& file,
const GURL& source_url,
const GURL& referrer_url,
const std::string& client_guid) {
base::AssertBlockingAllowed();
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
int64_t file_size = 0;
if (!base::PathExists(file) || !base::GetFileSize(file, &file_size))
......
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