Commit a9df7cc8 authored by Jose Lopes's avatar Jose Lopes Committed by Commit Bot

media: Migrate DataSource::ReadCB to once callback.

This callback is used to signal completion of the read operation,
therefore, it's a once callback:
* https://cs.chromium.org/chromium/src/media/base/data_source.h?rcl=6e8610f8f31aa3bb8266660380a66c6c25b2e64a&l=27

This is part of the base::Callback migration.

Context: https://cs.chromium.org/chromium/src/docs/callback.md?rcl=9fcc3764aea8f97e9f6de4a9ee61d554e67edcda&l=40

Bug: 714018
Change-Id: Ie43febda1247be065f9f22cc4aec0d8412873491
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2056729Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarXiaohan Wang <xhwang@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Commit-Queue: Jose Lopes <jabolopes@google.com>
Cr-Commit-Position: refs/heads/master@{#745018}
parent b807d1c2
......@@ -31,13 +31,13 @@ void IPCDataSource::Abort() {
void IPCDataSource::Read(int64_t position,
int size,
uint8_t* destination,
const DataSource::ReadCB& callback) {
DataSource::ReadCB callback) {
DCHECK_CALLED_ON_VALID_THREAD(data_source_thread_checker_);
utility_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&IPCDataSource::ReadMediaData, base::Unretained(this),
destination, callback, position, size));
destination, std::move(callback), position, size));
}
bool IPCDataSource::GetSize(int64_t* size_out) {
......@@ -56,7 +56,7 @@ void IPCDataSource::SetBitrate(int bitrate) {
}
void IPCDataSource::ReadMediaData(uint8_t* destination,
const DataSource::ReadCB& callback,
DataSource::ReadCB callback,
int64_t position,
int size) {
DCHECK_CALLED_ON_VALID_THREAD(utility_thread_checker_);
......@@ -72,14 +72,14 @@ void IPCDataSource::ReadMediaData(uint8_t* destination,
media_data_source_->Read(
position, clamped_size,
base::BindOnce(&IPCDataSource::ReadDone, base::Unretained(this),
destination, callback));
destination, std::move(callback)));
}
void IPCDataSource::ReadDone(uint8_t* destination,
const DataSource::ReadCB& callback,
DataSource::ReadCB callback,
const std::vector<uint8_t>& data) {
DCHECK_CALLED_ON_VALID_THREAD(utility_thread_checker_);
std::copy(data.begin(), data.end(), destination);
callback.Run(data.size());
std::move(callback).Run(data.size());
}
......@@ -39,7 +39,7 @@ class IPCDataSource : public media::DataSource {
void Read(int64_t position,
int size,
uint8_t* destination,
const ReadCB& callback) override;
ReadCB callback) override;
bool GetSize(int64_t* size_out) override;
bool IsStreaming() override;
void SetBitrate(int bitrate) override;
......@@ -47,11 +47,11 @@ class IPCDataSource : public media::DataSource {
private:
// Media data read helpers: must be run on the utility thread.
void ReadMediaData(uint8_t* destination,
const ReadCB& callback,
ReadCB callback,
int64_t position,
int size);
void ReadDone(uint8_t* destination,
const ReadCB& callback,
ReadCB callback,
const std::vector<uint8_t>& data);
mojo::Remote<chrome::mojom::MediaDataSource> media_data_source_;
......
......@@ -16,8 +16,7 @@ namespace media {
class MEDIA_EXPORT DataSource {
public:
typedef base::Callback<void(int64_t, int64_t)> StatusCallback;
typedef base::Callback<void(int)> ReadCB;
using ReadCB = base::OnceCallback<void(int)>;
enum { kReadError = -1, kAborted = -2 };
......@@ -30,7 +29,7 @@ class MEDIA_EXPORT DataSource {
virtual void Read(int64_t position,
int size,
uint8_t* data,
const DataSource::ReadCB& read_cb) = 0;
DataSource::ReadCB read_cb) = 0;
// Stops the DataSource. Once this is called all future Read() calls will
// return an error. This is a synchronous call and may be called from any
......
......@@ -74,7 +74,7 @@ class MultibufferDataSource::ReadOperation {
ReadOperation(int64_t position,
int size,
uint8_t* data,
const DataSource::ReadCB& callback);
DataSource::ReadCB callback);
~ReadOperation();
// Runs |callback_| with the given |result|, deleting the operation
......@@ -94,12 +94,14 @@ class MultibufferDataSource::ReadOperation {
DISALLOW_IMPLICIT_CONSTRUCTORS(ReadOperation);
};
MultibufferDataSource::ReadOperation::ReadOperation(
int64_t position,
int size,
uint8_t* data,
const DataSource::ReadCB& callback)
: position_(position), size_(size), data_(data), callback_(callback) {
MultibufferDataSource::ReadOperation::ReadOperation(int64_t position,
int size,
uint8_t* data,
DataSource::ReadCB callback)
: position_(position),
size_(size),
data_(data),
callback_(std::move(callback)) {
DCHECK(!callback_.is_null());
}
......@@ -183,10 +185,9 @@ void MultibufferDataSource::CreateResourceLoader_Locked(
DCHECK(render_task_runner_->BelongsToCurrentThread());
lock_.AssertAcquired();
reader_.reset(new MultiBufferReader(
reader_ = std::make_unique<MultiBufferReader>(
url_data_->multibuffer(), first_byte_position, last_byte_position,
base::BindRepeating(&MultibufferDataSource::ProgressCallback,
weak_ptr_)));
base::BindRepeating(&MultibufferDataSource::ProgressCallback, weak_ptr_));
UpdateBufferSizes();
}
......@@ -390,7 +391,7 @@ GURL MultibufferDataSource::GetUrlAfterRedirects() const {
void MultibufferDataSource::Read(int64_t position,
int size,
uint8_t* data,
const DataSource::ReadCB& read_cb) {
DataSource::ReadCB read_cb) {
DVLOG(1) << "Read: " << position << " offset, " << size << " bytes";
// Reading is not allowed until after initialization.
DCHECK(!init_cb_);
......@@ -401,7 +402,7 @@ void MultibufferDataSource::Read(int64_t position,
DCHECK(!read_op_);
if (stop_signal_received_) {
read_cb.Run(kReadError);
std::move(read_cb).Run(kReadError);
return;
}
......@@ -421,11 +422,12 @@ void MultibufferDataSource::Read(int64_t position,
kSeekDelay);
}
read_cb.Run(bytes_read);
std::move(read_cb).Run(bytes_read);
return;
}
}
read_op_.reset(new ReadOperation(position, size, data, read_cb));
read_op_ = std::make_unique<ReadOperation>(position, size, data,
std::move(read_cb));
}
render_task_runner_->PostTask(FROM_HERE,
......
......@@ -117,7 +117,7 @@ class MEDIA_BLINK_EXPORT MultibufferDataSource : public DataSource {
void Read(int64_t position,
int size,
uint8_t* data,
const DataSource::ReadCB& read_cb) override;
DataSource::ReadCB read_cb) override;
bool GetSize(int64_t* size_out) override;
bool IsStreaming() override;
void SetBitrate(int bitrate) override;
......
......@@ -336,8 +336,8 @@ class MultibufferDataSourceTest : public testing::Test {
void ReadAt(int64_t position, int64_t howmuch = kDataSize) {
data_source_->Read(position, howmuch, buffer_,
base::Bind(&MultibufferDataSourceTest::ReadCallback,
base::Unretained(this)));
base::BindOnce(&MultibufferDataSourceTest::ReadCallback,
base::Unretained(this)));
base::RunLoop().RunUntilIdle();
}
......@@ -888,8 +888,8 @@ TEST_F(MultibufferDataSourceTest, StopDuringRead) {
uint8_t buffer[256];
data_source_->Read(kDataSize, base::size(buffer), buffer,
base::Bind(&MultibufferDataSourceTest::ReadCallback,
base::Unretained(this)));
base::BindOnce(&MultibufferDataSourceTest::ReadCallback,
base::Unretained(this)));
// The outstanding read should fail before the stop callback runs.
{
......@@ -1282,8 +1282,8 @@ TEST_F(MultibufferDataSourceTest,
ReceiveData(kDataSize);
EXPECT_EQ(data_source_->downloading(), false);
data_source_->Read(kDataSize * 10, kDataSize, buffer_,
base::Bind(&MultibufferDataSourceTest::ReadCallback,
base::Unretained(this)));
base::BindOnce(&MultibufferDataSourceTest::ReadCallback,
base::Unretained(this)));
data_source_->OnBufferingHaveEnough(false);
EXPECT_TRUE(active_loader_allownull());
EXPECT_CALL(*this, ReadCallback(-1));
......@@ -1758,8 +1758,8 @@ TEST_F(MultibufferDataSourceTest, Http_CheckLoadingTransition) {
EXPECT_CALL(*this, ReadCallback(1));
data_source_->Read(kDataSize, 2, buffer_,
base::Bind(&MultibufferDataSourceTest::ReadCallback,
base::Unretained(this)));
base::BindOnce(&MultibufferDataSourceTest::ReadCallback,
base::Unretained(this)));
base::RunLoop().RunUntilIdle();
// Make sure we're not downloading anymore.
......
......@@ -61,8 +61,8 @@ int BlockingUrlProtocol::Read(int size, uint8_t* data) {
// 1) |last_read_bytes_| is set and |read_complete_| is signalled
// 2) |aborted_| is signalled
data_source_->Read(read_position_, size, data,
base::Bind(&BlockingUrlProtocol::SignalReadCompleted,
base::Unretained(this)));
base::BindOnce(&BlockingUrlProtocol::SignalReadCompleted,
base::Unretained(this)));
}
base::WaitableEvent* events[] = { &aborted_, &read_complete_ };
......
......@@ -34,9 +34,9 @@ void FileDataSource::Abort() {}
void FileDataSource::Read(int64_t position,
int size,
uint8_t* data,
const DataSource::ReadCB& read_cb) {
DataSource::ReadCB read_cb) {
if (force_read_errors_ || !file_.IsValid()) {
read_cb.Run(kReadError);
std::move(read_cb).Run(kReadError);
return;
}
......@@ -53,7 +53,7 @@ void FileDataSource::Read(int64_t position,
memcpy(data, file_.data() + position, clamped_size);
bytes_read_ += clamped_size;
read_cb.Run(clamped_size);
std::move(read_cb).Run(clamped_size);
}
bool FileDataSource::GetSize(int64_t* size_out) {
......
......@@ -33,7 +33,7 @@ class MEDIA_EXPORT FileDataSource : public DataSource {
void Read(int64_t position,
int size,
uint8_t* data,
const DataSource::ReadCB& read_cb) override;
DataSource::ReadCB read_cb) override;
bool GetSize(int64_t* size_out) override;
bool IsStreaming() override;
void SetBitrate(int bitrate) override;
......
......@@ -23,12 +23,12 @@ MemoryDataSource::~MemoryDataSource() = default;
void MemoryDataSource::Read(int64_t position,
int size,
uint8_t* data,
const DataSource::ReadCB& read_cb) {
DataSource::ReadCB read_cb) {
DCHECK(read_cb);
if (is_stopped_ || size < 0 || position < 0 ||
static_cast<size_t>(position) > size_) {
read_cb.Run(kReadError);
std::move(read_cb).Run(kReadError);
return;
}
......@@ -41,7 +41,7 @@ void MemoryDataSource::Read(int64_t position,
memcpy(data, data_ + position, clamped_size);
}
read_cb.Run(clamped_size);
std::move(read_cb).Run(clamped_size);
}
void MemoryDataSource::Stop() {
......
......@@ -29,7 +29,7 @@ class MEDIA_EXPORT MemoryDataSource : public DataSource {
void Read(int64_t position,
int size,
uint8_t* data,
const DataSource::ReadCB& read_cb) final;
DataSource::ReadCB read_cb) final;
void Stop() final;
void Abort() final;
bool GetSize(int64_t* size_out) final;
......
......@@ -35,7 +35,7 @@ class MemoryDataSourceTest : public ::testing::Test {
EXPECT_CALL(*this, ReadCB(expected_read_size));
memory_data_source_->Read(
position, size, data.data(),
base::Bind(&MemoryDataSourceTest::ReadCB, base::Unretained(this)));
base::BindOnce(&MemoryDataSourceTest::ReadCB, base::Unretained(this)));
if (expected_read_size != DataSource::kReadError) {
EXPECT_EQ(
......
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