Commit de2ae649 authored by Francois Doray's avatar Francois Doray Committed by Commit Bot

[TaskScheduler]: Use ScopedBlockingCall to mark blocking tasks.

This CL uses ScopedBlockingCall to mark blocking calls in /chrome/browser/resource_coordinator.

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

Bug: 874080
Change-Id: I5c943766529166e6f73470dbbcb426b1b182a37c
Reviewed-on: https://chromium-review.googlesource.com/1191190Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Commit-Queue: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586415}
parent bc614719
......@@ -14,7 +14,7 @@
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/task_runner_util.h"
#include "base/threading/thread_restrictions.h"
#include "base/threading/scoped_blocking_call.h"
#include "chrome/browser/resource_coordinator/utils.h"
#include "third_party/leveldatabase/env_chromium.h"
#include "third_party/leveldatabase/leveldb_chrome.h"
......@@ -211,14 +211,18 @@ base::Optional<SiteCharacteristicsProto>
LevelDBSiteCharacteristicsDatabase::AsyncHelper::ReadSiteCharacteristicsFromDB(
const url::Origin& origin) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::AssertBlockingAllowed();
if (!db_)
return base::nullopt;
leveldb::Status s;
std::string protobuf_value;
leveldb::Status s = db_->Get(
read_options_, SerializeOriginIntoDatabaseKey(origin), &protobuf_value);
{
base::ScopedBlockingCall scoped_blocking_call(
base::BlockingType::MAY_BLOCK);
s = db_->Get(read_options_, SerializeOriginIntoDatabaseKey(origin),
&protobuf_value);
}
base::Optional<SiteCharacteristicsProto> site_characteristic_proto;
if (s.ok()) {
site_characteristic_proto = SiteCharacteristicsProto();
......@@ -236,14 +240,18 @@ void LevelDBSiteCharacteristicsDatabase::AsyncHelper::
const url::Origin& origin,
const SiteCharacteristicsProto& site_characteristic_proto) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::AssertBlockingAllowed();
if (!db_)
return;
leveldb::Status s =
db_->Put(write_options_, SerializeOriginIntoDatabaseKey(origin),
site_characteristic_proto.SerializeAsString());
leveldb::Status s;
{
base::ScopedBlockingCall scoped_blocking_call(
base::BlockingType::MAY_BLOCK);
s = db_->Put(write_options_, SerializeOriginIntoDatabaseKey(origin),
site_characteristic_proto.SerializeAsString());
}
if (!s.ok()) {
DLOG(ERROR)
<< "Error while inserting an element in the site characteristics "
......@@ -255,11 +263,11 @@ void LevelDBSiteCharacteristicsDatabase::AsyncHelper::
RemoveSiteCharacteristicsFromDB(
const std::vector<url::Origin>& site_origins) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::AssertBlockingAllowed();
if (!db_)
return;
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
leveldb::WriteBatch batch;
for (const auto& iter : site_origins)
batch.Delete(SerializeOriginIntoDatabaseKey(iter));
......@@ -272,12 +280,12 @@ void LevelDBSiteCharacteristicsDatabase::AsyncHelper::
void LevelDBSiteCharacteristicsDatabase::AsyncHelper::ClearDatabase() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::AssertBlockingAllowed();
if (!db_)
return;
leveldb_env::Options options;
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
db_.reset();
leveldb_env::Options options;
leveldb::Status status = leveldb::DestroyDB(db_path_.AsUTF8Unsafe(), options);
if (status.ok()) {
OpenOrCreateDatabaseImpl();
......@@ -291,7 +299,7 @@ LevelDBSiteCharacteristicsDatabase::AsyncHelper::OpeningType
LevelDBSiteCharacteristicsDatabase::AsyncHelper::OpenOrCreateDatabaseImpl() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!db_) << "Database already open";
base::AssertBlockingAllowed();
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
OpeningType opening_type = OpeningType::kNewDb;
......
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