Commit e84f4265 authored by Victor Costan's avatar Victor Costan Committed by Commit Bot

Blobs: Qualify base::Bind calls and remove deprecated mojo call.

Change-Id: Ie63379b3002521a1badac056809edbf8b8d40b71
Reviewed-on: https://chromium-review.googlesource.com/c/1292956
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601564}
parent 7bf83841
......@@ -407,12 +407,12 @@ class BlobMemoryController::FileQuotaAllocationTask
// Send file creation task to file thread.
base::PostTaskAndReplyWithResult(
controller_->file_runner_.get(), FROM_HERE,
base::Bind(&CreateEmptyFiles, controller_->blob_storage_dir_,
disk_space_function, controller_->file_runner_,
base::Passed(&file_paths)),
base::Bind(&FileQuotaAllocationTask::OnCreateEmptyFiles,
weak_factory_.GetWeakPtr(), base::Passed(&references),
allocation_size_));
base::BindOnce(&CreateEmptyFiles, controller_->blob_storage_dir_,
disk_space_function, controller_->file_runner_,
std::move(file_paths)),
base::BindOnce(&FileQuotaAllocationTask::OnCreateEmptyFiles,
weak_factory_.GetWeakPtr(), std::move(references),
allocation_size_));
controller_->RecordTracingCounters();
}
~FileQuotaAllocationTask() override = default;
......@@ -524,8 +524,8 @@ BlobMemoryController::BlobMemoryController(
populated_memory_items_(
base::MRUCache<uint64_t, ShareableBlobDataItem*>::NO_AUTO_EVICT),
memory_pressure_listener_(
base::Bind(&BlobMemoryController::OnMemoryPressure,
base::Unretained(this))),
base::BindRepeating(&BlobMemoryController::OnMemoryPressure,
base::Unretained(this))),
weak_factory_(this) {}
BlobMemoryController::~BlobMemoryController() = default;
......@@ -741,9 +741,10 @@ void BlobMemoryController::CalculateBlobStorageLimits() {
if (file_runner_) {
PostTaskAndReplyWithResult(
file_runner_.get(), FROM_HERE,
base::Bind(&CalculateBlobStorageLimitsImpl, blob_storage_dir_, true),
base::Bind(&BlobMemoryController::OnStorageLimitsCalculated,
weak_factory_.GetWeakPtr()));
base::BindOnce(&CalculateBlobStorageLimitsImpl, blob_storage_dir_,
true),
base::BindOnce(&BlobMemoryController::OnStorageLimitsCalculated,
weak_factory_.GetWeakPtr()));
} else {
OnStorageLimitsCalculated(
CalculateBlobStorageLimitsImpl(blob_storage_dir_, false));
......
......@@ -129,7 +129,7 @@ bool BlobReader::has_side_data() const {
return item.disk_cache_entry()->GetDataSize(disk_cache_side_stream_index) > 0;
}
BlobReader::Status BlobReader::ReadSideData(const StatusCallback& done) {
BlobReader::Status BlobReader::ReadSideData(StatusCallback done) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!has_side_data())
......@@ -142,8 +142,9 @@ BlobReader::Status BlobReader::ReadSideData(const StatusCallback& done) {
net_error_ = net::OK;
const int result = item->disk_cache_entry()->ReadData(
disk_cache_side_stream_index, 0, side_data_.get(), side_data_size,
base::Bind(&BlobReader::DidReadDiskCacheEntrySideData,
weak_factory_.GetWeakPtr(), done, side_data_size));
base::BindOnce(&BlobReader::DidReadDiskCacheEntrySideData,
weak_factory_.GetWeakPtr(), std::move(done),
side_data_size));
if (result >= 0) {
DCHECK_EQ(side_data_size, result);
return Status::DONE;
......@@ -153,7 +154,7 @@ BlobReader::Status BlobReader::ReadSideData(const StatusCallback& done) {
return ReportError(result);
}
void BlobReader::DidReadDiskCacheEntrySideData(const StatusCallback& done,
void BlobReader::DidReadDiskCacheEntrySideData(StatusCallback done,
int expected_size,
int result) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......@@ -161,11 +162,11 @@ void BlobReader::DidReadDiskCacheEntrySideData(const StatusCallback& done,
DCHECK_EQ(expected_size, result);
if (result > 0)
storage::RecordBytesRead(kCacheStorageRecordBytesLabel, result);
done.Run(Status::DONE);
std::move(done).Run(Status::DONE);
return;
}
side_data_ = nullptr;
done.Run(ReportError(result));
std::move(done).Run(ReportError(result));
}
BlobReader::Status BlobReader::SetReadRange(uint64_t offset, uint64_t length) {
......@@ -338,7 +339,7 @@ BlobReader::Status BlobReader::CalculateSizeImpl(
if (!reader)
return ReportError(net::ERR_FILE_NOT_FOUND);
int64_t length_output = reader->GetLength(base::Bind(
int64_t length_output = reader->GetLength(base::BindOnce(
&BlobReader::DidGetFileItemLength, weak_factory_.GetWeakPtr(), i));
if (length_output == net::ERR_IO_PENDING)
continue;
......@@ -549,7 +550,7 @@ BlobReader::Status BlobReader::ReadFileItem(FileStreamReader* reader,
DCHECK(reader);
const int result = reader->Read(
read_buf_.get(), bytes_to_read,
base::Bind(&BlobReader::DidReadFile, weak_factory_.GetWeakPtr()));
base::BindOnce(&BlobReader::DidReadFile, weak_factory_.GetWeakPtr()));
if (result >= 0) {
AdvanceBytesRead(result);
return Status::DONE;
......@@ -604,8 +605,8 @@ BlobReader::Status BlobReader::ReadDiskCacheEntryItem(const BlobDataItem& item,
const int result = item.disk_cache_entry()->ReadData(
item.disk_cache_stream_index(), item.offset() + current_item_offset_,
read_buf_.get(), bytes_to_read,
base::Bind(&BlobReader::DidReadDiskCacheEntry,
weak_factory_.GetWeakPtr()));
base::BindOnce(&BlobReader::DidReadDiskCacheEntry,
weak_factory_.GetWeakPtr()));
if (result >= 0) {
AdvanceBytesRead(result);
return Status::DONE;
......
......@@ -65,7 +65,7 @@ class STORAGE_EXPORT BlobReader {
const base::Time& expected_modification_time) = 0;
};
enum class Status { NET_ERROR, IO_PENDING, DONE };
using StatusCallback = base::Callback<void(Status)>;
using StatusCallback = base::OnceCallback<void(Status)>;
virtual ~BlobReader();
// This calculates the total size of the blob, and initializes the reading
......@@ -92,7 +92,7 @@ class STORAGE_EXPORT BlobReader {
// * If this function returns Status::IO_PENDING, the done callback will be
// called with Status::DONE or Status::NET_ERROR.
// Currently side data is supported only for single DiskCache entry blob.
Status ReadSideData(const StatusCallback& done);
Status ReadSideData(StatusCallback done);
// Returns the side data which has been already read with ReadSideData().
net::IOBufferWithSize* side_data() const {
......@@ -199,7 +199,7 @@ class STORAGE_EXPORT BlobReader {
Status ReadDiskCacheEntryItem(const BlobDataItem& item, int bytes_to_read);
void DidReadDiskCacheEntry(int result);
void DidReadItem(int result);
void DidReadDiskCacheEntrySideData(const StatusCallback& done,
void DidReadDiskCacheEntrySideData(StatusCallback done,
int expected_size,
int result);
int ComputeBytesToRead() const;
......
......@@ -584,7 +584,7 @@ TEST_F(BlobReaderTest, DiskCacheWithSideData) {
BlobReader::Status status = BlobReader::Status::DONE;
EXPECT_EQ(BlobReader::Status::DONE,
reader_->ReadSideData(
base::Bind(&SetValue<BlobReader::Status>, &status)));
base::BindOnce(&SetValue<BlobReader::Status>, &status)));
EXPECT_EQ(net::OK, reader_->net_error());
EXPECT_TRUE(reader_->side_data());
std::string result(reader_->side_data()->data(),
......
......@@ -73,7 +73,7 @@ class BlobRegistryImplTest : public testing::Test {
delegate_ptr_ = delegate.get();
registry_impl_->Bind(MakeRequest(&registry_), std::move(delegate));
mojo::core::SetDefaultProcessErrorCallback(base::Bind(
mojo::core::SetDefaultProcessErrorCallback(base::BindRepeating(
&BlobRegistryImplTest::OnBadMessage, base::Unretained(this)));
storage::BlobStorageLimits limits;
......
......@@ -163,16 +163,19 @@ class DataPipeTransportStrategy : public BlobTransportStrategy {
current_source_offset_ = 0;
provider->RequestAsStream(std::move(producer_handle));
watcher_.Watch(consumer_handle_.get(), MOJO_HANDLE_SIGNAL_READABLE,
base::Bind(&DataPipeTransportStrategy::OnDataPipeReadable,
base::Unretained(this), expected_source_size,
std::move(future_data)));
watcher_.Watch(
consumer_handle_.get(), MOJO_HANDLE_SIGNAL_READABLE,
MOJO_WATCH_CONDITION_SATISFIED,
base::BindRepeating(&DataPipeTransportStrategy::OnDataPipeReadable,
base::Unretained(this), expected_source_size,
std::move(future_data)));
}
void OnDataPipeReadable(
size_t expected_full_source_size,
const std::vector<BlobDataBuilder::FutureData>& future_data,
MojoResult result) {
MojoResult result,
const mojo::HandleSignalsState& state) {
// The index of the element data should currently be written to, relative to
// the first element of this stream (the first item in future_data).
size_t relative_element_index =
......
......@@ -61,7 +61,7 @@ class BlobTransportStrategyTest : public testing::Test {
limits_.min_page_file_size = kTestBlobStorageMinFileSizeBytes;
limits_.max_file_size = kTestBlobStorageMaxFileSizeBytes;
mojo::core::SetDefaultProcessErrorCallback(base::Bind(
mojo::core::SetDefaultProcessErrorCallback(base::BindRepeating(
&BlobTransportStrategyTest::OnBadMessage, base::Unretained(this)));
// Disallow IO on the main loop.
......
......@@ -251,7 +251,7 @@ void BlobURLRequestJob::DidCalculateSize(int result) {
// TODO(horo): When the requester doesn't need the side data (ex:FileReader)
// we should skip reading the side data.
if (blob_reader_->has_side_data() &&
blob_reader_->ReadSideData(base::Bind(
blob_reader_->ReadSideData(base::BindOnce(
&BlobURLRequestJob::DidReadMetadata, weak_factory_.GetWeakPtr())) ==
BlobReader::Status::IO_PENDING) {
return;
......
......@@ -123,8 +123,9 @@ void MojoBlobReader::DidCalculateSize(int result) {
if (!blob_reader_->has_side_data()) {
DidReadSideData(BlobReader::Status::DONE);
} else {
BlobReader::Status read_status = blob_reader_->ReadSideData(
base::Bind(&MojoBlobReader::DidReadSideData, base::Unretained(this)));
BlobReader::Status read_status =
blob_reader_->ReadSideData(base::BindOnce(
&MojoBlobReader::DidReadSideData, base::Unretained(this)));
if (read_status != BlobReader::Status::IO_PENDING)
DidReadSideData(BlobReader::Status::DONE);
}
......@@ -151,14 +152,16 @@ void MojoBlobReader::StartReading() {
response_body_stream_ = delegate_->PassDataPipe();
peer_closed_handle_watcher_.Watch(
response_body_stream_.get(), MOJO_HANDLE_SIGNAL_PEER_CLOSED,
base::Bind(&MojoBlobReader::OnResponseBodyStreamClosed,
base::Unretained(this)));
MOJO_WATCH_CONDITION_SATISFIED,
base::BindRepeating(&MojoBlobReader::OnResponseBodyStreamClosed,
base::Unretained(this)));
peer_closed_handle_watcher_.ArmOrNotify();
writable_handle_watcher_.Watch(
response_body_stream_.get(), MOJO_HANDLE_SIGNAL_WRITABLE,
base::Bind(&MojoBlobReader::OnResponseBodyStreamReady,
base::Unretained(this)));
MOJO_WATCH_CONDITION_SATISFIED,
base::BindRepeating(&MojoBlobReader::OnResponseBodyStreamReady,
base::Unretained(this)));
// Start reading...
ReadMore();
......@@ -242,7 +245,9 @@ void MojoBlobReader::DidRead(bool completed_synchronously, int num_bytes) {
}
}
void MojoBlobReader::OnResponseBodyStreamClosed(MojoResult result) {
void MojoBlobReader::OnResponseBodyStreamClosed(
MojoResult result,
const mojo::HandleSignalsState& state) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
response_body_stream_.reset();
......@@ -250,11 +255,13 @@ void MojoBlobReader::OnResponseBodyStreamClosed(MojoResult result) {
NotifyCompletedAndDeleteIfNeeded(net::ERR_ABORTED);
}
void MojoBlobReader::OnResponseBodyStreamReady(MojoResult result) {
void MojoBlobReader::OnResponseBodyStreamReady(
MojoResult result,
const mojo::HandleSignalsState& state) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (result == MOJO_RESULT_FAILED_PRECONDITION) {
OnResponseBodyStreamClosed(MOJO_RESULT_OK);
OnResponseBodyStreamClosed(MOJO_RESULT_OK, state);
return;
}
DCHECK_EQ(result, MOJO_RESULT_OK);
......
......@@ -97,8 +97,10 @@ class STORAGE_EXPORT MojoBlobReader {
void StartReading();
void ReadMore();
void DidRead(bool completed_synchronously, int num_bytes);
void OnResponseBodyStreamClosed(MojoResult result);
void OnResponseBodyStreamReady(MojoResult result);
void OnResponseBodyStreamClosed(MojoResult result,
const mojo::HandleSignalsState& state);
void OnResponseBodyStreamReady(MojoResult result,
const mojo::HandleSignalsState& state);
const std::unique_ptr<Delegate> delegate_;
......
......@@ -32,11 +32,12 @@ class BlobBytesStreamer {
mojo::SimpleWatcher::ArmingPolicy::AUTOMATIC,
std::move(task_runner)) {
watcher_.Watch(pipe_.get(), MOJO_HANDLE_SIGNAL_WRITABLE,
MOJO_WATCH_CONDITION_SATISFIED,
WTF::BindRepeating(&BlobBytesStreamer::OnWritable,
WTF::Unretained(this)));
}
void OnWritable(MojoResult result) {
void OnWritable(MojoResult result, const mojo::HandleSignalsState& state) {
if (result == MOJO_RESULT_CANCELLED ||
result == MOJO_RESULT_FAILED_PRECONDITION) {
delete this;
......
......@@ -336,9 +336,11 @@ TEST_F(BlobBytesProviderTest, RequestAsStream) {
blink::scheduler::GetSequencedTaskRunnerForTesting());
watcher.Watch(
pipe.consumer_handle.get(), MOJO_HANDLE_SIGNAL_READABLE,
MOJO_WATCH_CONDITION_SATISFIED,
base::BindRepeating(
[](mojo::DataPipeConsumerHandle pipe, base::Closure quit_closure,
Vector<uint8_t>* bytes_out, MojoResult result) {
Vector<uint8_t>* bytes_out, MojoResult result,
const mojo::HandleSignalsState& state) {
if (result == MOJO_RESULT_CANCELLED ||
result == MOJO_RESULT_FAILED_PRECONDITION) {
quit_closure.Run();
......
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