| Index: chrome/utility/media_galleries/ipc_data_source.cc
|
| diff --git a/chrome/utility/media_galleries/ipc_data_source.cc b/chrome/utility/media_galleries/ipc_data_source.cc
|
| index 63e09c449ee7dca35e4bd223ac09f4a54b3de14f..6d1778d7502d5bc5573ae6fd57f1043cb82f2320 100644
|
| --- a/chrome/utility/media_galleries/ipc_data_source.cc
|
| +++ b/chrome/utility/media_galleries/ipc_data_source.cc
|
| @@ -5,15 +5,16 @@
|
| #include "chrome/utility/media_galleries/ipc_data_source.h"
|
|
|
| #include "base/threading/thread_task_runner_handle.h"
|
| -#include "chrome/common/extensions/chrome_utility_extensions_messages.h"
|
| #include "content/public/utility/utility_thread.h"
|
|
|
| namespace metadata {
|
|
|
| -IPCDataSource::IPCDataSource(int64_t total_size)
|
| - : total_size_(total_size),
|
| - utility_task_runner_(base::ThreadTaskRunnerHandle::Get()),
|
| - next_request_id_(0) {
|
| +IPCDataSource::IPCDataSource(
|
| + extensions::mojom::MediaDataSourcePtr media_data_source,
|
| + int64_t total_size)
|
| + : media_data_source_(std::move(media_data_source)),
|
| + total_size_(total_size),
|
| + utility_task_runner_(base::ThreadTaskRunnerHandle::Get()) {
|
| data_source_thread_checker_.DetachFromThread();
|
| }
|
|
|
| @@ -31,13 +32,13 @@ void IPCDataSource::Abort() {
|
|
|
| void IPCDataSource::Read(int64_t position,
|
| int size,
|
| - uint8_t* data,
|
| - const DataSource::ReadCB& read_cb) {
|
| + uint8_t* destination,
|
| + const DataSource::ReadCB& callback) {
|
| DCHECK(data_source_thread_checker_.CalledOnValidThread());
|
| +
|
| utility_task_runner_->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(&IPCDataSource::ReadOnUtilityThread, base::Unretained(this),
|
| - position, size, data, read_cb));
|
| + FROM_HERE, base::Bind(&IPCDataSource::ReadBlob, base::Unretained(this),
|
| + destination, callback, position, size));
|
| }
|
|
|
| bool IPCDataSource::GetSize(int64_t* size_out) {
|
| @@ -55,30 +56,10 @@ void IPCDataSource::SetBitrate(int bitrate) {
|
| DCHECK(data_source_thread_checker_.CalledOnValidThread());
|
| }
|
|
|
| -bool IPCDataSource::OnMessageReceived(const IPC::Message& message) {
|
| - DCHECK(utility_thread_checker_.CalledOnValidThread());
|
| - bool handled = true;
|
| - IPC_BEGIN_MESSAGE_MAP(IPCDataSource, message)
|
| - IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RequestBlobBytes_Finished,
|
| - OnRequestBlobBytesFinished)
|
| - IPC_MESSAGE_UNHANDLED(handled = false)
|
| - IPC_END_MESSAGE_MAP()
|
| - return handled;
|
| -}
|
| -
|
| -IPCDataSource::Request::Request()
|
| - : destination(NULL) {
|
| -}
|
| -
|
| -IPCDataSource::Request::Request(const Request& other) = default;
|
| -
|
| -IPCDataSource::Request::~Request() {
|
| -}
|
| -
|
| -void IPCDataSource::ReadOnUtilityThread(int64_t position,
|
| - int size,
|
| - uint8_t* data,
|
| - const DataSource::ReadCB& read_cb) {
|
| +void IPCDataSource::ReadBlob(uint8_t* destination,
|
| + const DataSource::ReadCB& callback,
|
| + int64_t position,
|
| + int size) {
|
| DCHECK(utility_thread_checker_.CalledOnValidThread());
|
| CHECK_GE(total_size_, 0);
|
| CHECK_GE(position, 0);
|
| @@ -89,29 +70,19 @@ void IPCDataSource::ReadOnUtilityThread(int64_t position,
|
| int64_t clamped_size =
|
| std::min(static_cast<int64_t>(size), total_size_ - position);
|
|
|
| - int64_t request_id = ++next_request_id_;
|
| -
|
| - Request request;
|
| - request.destination = data;
|
| - request.callback = read_cb;
|
| -
|
| - pending_requests_[request_id] = request;
|
| - content::UtilityThread::Get()->Send(new ChromeUtilityHostMsg_RequestBlobBytes(
|
| - request_id, position, clamped_size));
|
| + media_data_source_->ReadBlob(
|
| + position, clamped_size,
|
| + base::Bind(&IPCDataSource::ReadDone, base::Unretained(this), destination,
|
| + callback));
|
| }
|
|
|
| -void IPCDataSource::OnRequestBlobBytesFinished(int64_t request_id,
|
| - const std::string& bytes) {
|
| +void IPCDataSource::ReadDone(uint8_t* destination,
|
| + const DataSource::ReadCB& callback,
|
| + const std::vector<uint8_t>& data) {
|
| DCHECK(utility_thread_checker_.CalledOnValidThread());
|
| - std::map<int64_t, Request>::iterator it = pending_requests_.find(request_id);
|
| -
|
| - if (it == pending_requests_.end())
|
| - return;
|
| -
|
| - std::copy(bytes.begin(), bytes.end(), it->second.destination);
|
| - it->second.callback.Run(bytes.size());
|
|
|
| - pending_requests_.erase(it);
|
| + std::copy(data.begin(), data.end(), destination);
|
| + callback.Run(data.size());
|
| }
|
|
|
| } // namespace metadata
|
|
|