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