Commit 7ba89a98 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Convert BytesProvider to new Mojo types

This CL converts BytesProviderRequest and BytesProviderPtr
to new Mojo types.
It updates struct DataElementBytes from data_element.mojom
and methods and members to new Mojo types.

Bug: 955171, 978694
Change-Id: I4a1f7a2cb73581ec23596178154fc9282c25e6f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1774424
Commit-Queue: Julie Kim <jkim@igalia.com>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691982}
parent 55730c21
...@@ -58,8 +58,8 @@ class BlobRegistryImpl::BlobUnderConstruction { ...@@ -58,8 +58,8 @@ class BlobRegistryImpl::BlobUnderConstruction {
private: private:
// Holds onto a blink::mojom::DataElement struct and optionally a bound // Holds onto a blink::mojom::DataElement struct and optionally a bound
// blink::mojom::BytesProviderPtr or blink::mojom::BlobPtr, if the element // mojo::Remote<blink::mojom::BytesProvider> or blink::mojom::BlobPtr, if the
// encapsulates a large byte array or a blob. // element encapsulates a large byte array or a blob.
struct ElementEntry { struct ElementEntry {
explicit ElementEntry(blink::mojom::DataElementPtr e) explicit ElementEntry(blink::mojom::DataElementPtr e)
: element(std::move(e)) { : element(std::move(e)) {
...@@ -75,7 +75,7 @@ class BlobRegistryImpl::BlobUnderConstruction { ...@@ -75,7 +75,7 @@ class BlobRegistryImpl::BlobUnderConstruction {
ElementEntry& operator=(ElementEntry&& other) = default; ElementEntry& operator=(ElementEntry&& other) = default;
blink::mojom::DataElementPtr element; blink::mojom::DataElementPtr element;
blink::mojom::BytesProviderPtr bytes_provider; mojo::Remote<blink::mojom::BytesProvider> bytes_provider;
blink::mojom::BlobPtr blob; blink::mojom::BlobPtr blob;
}; };
...@@ -228,7 +228,7 @@ void BlobRegistryImpl::BlobUnderConstruction::StartTransportation() { ...@@ -228,7 +228,7 @@ void BlobRegistryImpl::BlobUnderConstruction::StartTransportation() {
base::BindOnce(&BlobUnderConstruction::ReceivedBlobUUID, base::BindOnce(&BlobUnderConstruction::ReceivedBlobUUID,
weak_ptr_factory_.GetWeakPtr(), blob_count++)); weak_ptr_factory_.GetWeakPtr(), blob_count++));
} else if (element->is_bytes()) { } else if (element->is_bytes()) {
entry.bytes_provider.set_connection_error_handler(base::BindOnce( entry.bytes_provider.set_disconnect_handler(base::BindOnce(
&BlobUnderConstruction::MarkAsBroken, weak_ptr_factory_.GetWeakPtr(), &BlobUnderConstruction::MarkAsBroken, weak_ptr_factory_.GetWeakPtr(),
BlobStatus::ERR_SOURCE_DIED_IN_TRANSIT, "")); BlobStatus::ERR_SOURCE_DIED_IN_TRANSIT, ""));
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "mojo/core/embedder/embedder.h" #include "mojo/core/embedder/embedder.h"
#include "mojo/public/cpp/bindings/associated_receiver.h" #include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/associated_remote.h" #include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/system/data_pipe_utils.h" #include "mojo/public/cpp/system/data_pipe_utils.h"
#include "storage/browser/blob/blob_data_builder.h" #include "storage/browser/blob/blob_data_builder.h"
...@@ -47,9 +48,10 @@ const uint64_t kTestBlobStorageMaxDiskSpace = 4000; ...@@ -47,9 +48,10 @@ const uint64_t kTestBlobStorageMaxDiskSpace = 4000;
const uint64_t kTestBlobStorageMinFileSizeBytes = 10; const uint64_t kTestBlobStorageMinFileSizeBytes = 10;
const uint64_t kTestBlobStorageMaxFileSizeBytes = 100; const uint64_t kTestBlobStorageMaxFileSizeBytes = 100;
void BindBytesProvider(std::unique_ptr<MockBytesProvider> impl, void BindBytesProvider(
blink::mojom::BytesProviderRequest request) { std::unique_ptr<MockBytesProvider> impl,
mojo::MakeStrongBinding(std::move(impl), std::move(request)); mojo::PendingReceiver<blink::mojom::BytesProvider> receiver) {
mojo::MakeSelfOwnedReceiver(std::move(impl), std::move(receiver));
} }
} // namespace } // namespace
...@@ -140,24 +142,25 @@ class BlobRegistryImplTest : public testing::Test { ...@@ -140,24 +142,25 @@ class BlobRegistryImplTest : public testing::Test {
loop.Run(); loop.Run();
} }
blink::mojom::BytesProviderPtrInfo CreateBytesProvider( mojo::PendingRemote<blink::mojom::BytesProvider> CreateBytesProvider(
const std::string& bytes) { const std::string& bytes) {
if (!bytes_provider_runner_) { if (!bytes_provider_runner_) {
bytes_provider_runner_ = base::CreateSequencedTaskRunner( bytes_provider_runner_ = base::CreateSequencedTaskRunner(
{base::ThreadPool(), base::MayBlock()}); {base::ThreadPool(), base::MayBlock()});
} }
blink::mojom::BytesProviderPtrInfo result; mojo::PendingRemote<blink::mojom::BytesProvider> result;
auto provider = std::make_unique<MockBytesProvider>( auto provider = std::make_unique<MockBytesProvider>(
std::vector<uint8_t>(bytes.begin(), bytes.end()), &reply_request_count_, std::vector<uint8_t>(bytes.begin(), bytes.end()), &reply_request_count_,
&stream_request_count_, &file_request_count_); &stream_request_count_, &file_request_count_);
bytes_provider_runner_->PostTask( bytes_provider_runner_->PostTask(
FROM_HERE, base::BindOnce(&BindBytesProvider, std::move(provider), FROM_HERE, base::BindOnce(&BindBytesProvider, std::move(provider),
MakeRequest(&result))); result.InitWithNewPipeAndPassReceiver()));
return result; return result;
} }
void CreateBytesProvider(const std::string& bytes, void CreateBytesProvider(
blink::mojom::BytesProviderRequest request) { const std::string& bytes,
mojo::PendingReceiver<blink::mojom::BytesProvider> receiver) {
if (!bytes_provider_runner_) { if (!bytes_provider_runner_) {
bytes_provider_runner_ = base::CreateSequencedTaskRunner( bytes_provider_runner_ = base::CreateSequencedTaskRunner(
{base::ThreadPool(), base::MayBlock()}); {base::ThreadPool(), base::MayBlock()});
...@@ -167,7 +170,7 @@ class BlobRegistryImplTest : public testing::Test { ...@@ -167,7 +170,7 @@ class BlobRegistryImplTest : public testing::Test {
&stream_request_count_, &file_request_count_); &stream_request_count_, &file_request_count_);
bytes_provider_runner_->PostTask( bytes_provider_runner_->PostTask(
FROM_HERE, base::BindOnce(&BindBytesProvider, std::move(provider), FROM_HERE, base::BindOnce(&BindBytesProvider, std::move(provider),
std::move(request))); std::move(receiver)));
} }
size_t BlobsUnderConstruction() { size_t BlobsUnderConstruction() {
...@@ -842,13 +845,13 @@ TEST_F(BlobRegistryImplTest, Register_ValidBytesAsFile) { ...@@ -842,13 +845,13 @@ TEST_F(BlobRegistryImplTest, Register_ValidBytesAsFile) {
TEST_F(BlobRegistryImplTest, Register_BytesProviderClosedPipe) { TEST_F(BlobRegistryImplTest, Register_BytesProviderClosedPipe) {
const std::string kId = "id"; const std::string kId = "id";
blink::mojom::BytesProviderPtrInfo bytes_provider_info; mojo::PendingRemote<blink::mojom::BytesProvider> bytes_provider_remote;
MakeRequest(&bytes_provider_info); ignore_result(bytes_provider_remote.InitWithNewPipeAndPassReceiver());
std::vector<blink::mojom::DataElementPtr> elements; std::vector<blink::mojom::DataElementPtr> elements;
elements.push_back( elements.push_back(
blink::mojom::DataElement::NewBytes(blink::mojom::DataElementBytes::New( blink::mojom::DataElement::NewBytes(blink::mojom::DataElementBytes::New(
32, base::nullopt, std::move(bytes_provider_info)))); 32, base::nullopt, std::move(bytes_provider_remote))));
blink::mojom::BlobPtr blob; blink::mojom::BlobPtr blob;
EXPECT_TRUE(registry_->Register(MakeRequest(&blob), kId, "", "", EXPECT_TRUE(registry_->Register(MakeRequest(&blob), kId, "", "",
...@@ -867,13 +870,13 @@ TEST_F(BlobRegistryImplTest, ...@@ -867,13 +870,13 @@ TEST_F(BlobRegistryImplTest,
Register_DefereferencedWhileBuildingBeforeBreaking) { Register_DefereferencedWhileBuildingBeforeBreaking) {
const std::string kId = "id"; const std::string kId = "id";
blink::mojom::BytesProviderPtrInfo bytes_provider_info; mojo::PendingRemote<blink::mojom::BytesProvider> bytes_provider_remote;
auto request = MakeRequest(&bytes_provider_info); auto receiver = bytes_provider_remote.InitWithNewPipeAndPassReceiver();
std::vector<blink::mojom::DataElementPtr> elements; std::vector<blink::mojom::DataElementPtr> elements;
elements.push_back( elements.push_back(
blink::mojom::DataElement::NewBytes(blink::mojom::DataElementBytes::New( blink::mojom::DataElement::NewBytes(blink::mojom::DataElementBytes::New(
32, base::nullopt, std::move(bytes_provider_info)))); 32, base::nullopt, std::move(bytes_provider_remote))));
blink::mojom::BlobPtr blob; blink::mojom::BlobPtr blob;
EXPECT_TRUE(registry_->Register(MakeRequest(&blob), kId, "", "", EXPECT_TRUE(registry_->Register(MakeRequest(&blob), kId, "", "",
...@@ -891,7 +894,7 @@ TEST_F(BlobRegistryImplTest, ...@@ -891,7 +894,7 @@ TEST_F(BlobRegistryImplTest,
EXPECT_FALSE(context_->registry().HasEntry(kId)); EXPECT_FALSE(context_->registry().HasEntry(kId));
// Now cause construction to fail, if it would still be going on. // Now cause construction to fail, if it would still be going on.
request = nullptr; receiver.reset();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(0u, BlobsUnderConstruction()); EXPECT_EQ(0u, BlobsUnderConstruction());
} }
...@@ -945,13 +948,13 @@ TEST_F(BlobRegistryImplTest, ...@@ -945,13 +948,13 @@ TEST_F(BlobRegistryImplTest,
const std::string kId = "id"; const std::string kId = "id";
const std::string kData = "hello world"; const std::string kData = "hello world";
blink::mojom::BytesProviderPtrInfo bytes_provider_info; mojo::PendingRemote<blink::mojom::BytesProvider> bytes_provider_remote;
auto request = MakeRequest(&bytes_provider_info); auto receiver = bytes_provider_remote.InitWithNewPipeAndPassReceiver();
std::vector<blink::mojom::DataElementPtr> elements; std::vector<blink::mojom::DataElementPtr> elements;
elements.push_back( elements.push_back(
blink::mojom::DataElement::NewBytes(blink::mojom::DataElementBytes::New( blink::mojom::DataElement::NewBytes(blink::mojom::DataElementBytes::New(
kData.size(), base::nullopt, std::move(bytes_provider_info)))); kData.size(), base::nullopt, std::move(bytes_provider_remote))));
blink::mojom::BlobPtr blob; blink::mojom::BlobPtr blob;
EXPECT_TRUE(registry_->Register(MakeRequest(&blob), kId, "", "", EXPECT_TRUE(registry_->Register(MakeRequest(&blob), kId, "", "",
...@@ -969,7 +972,7 @@ TEST_F(BlobRegistryImplTest, ...@@ -969,7 +972,7 @@ TEST_F(BlobRegistryImplTest,
EXPECT_FALSE(context_->registry().HasEntry(kId)); EXPECT_FALSE(context_->registry().HasEntry(kId));
// Now cause construction to complete, if it would still be going on. // Now cause construction to complete, if it would still be going on.
CreateBytesProvider(kData, std::move(request)); CreateBytesProvider(kData, std::move(receiver));
task_environment_.RunUntilIdle(); task_environment_.RunUntilIdle();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(0u, BlobsUnderConstruction()); EXPECT_EQ(0u, BlobsUnderConstruction());
...@@ -981,13 +984,13 @@ TEST_F(BlobRegistryImplTest, ...@@ -981,13 +984,13 @@ TEST_F(BlobRegistryImplTest,
const std::string kData = const std::string kData =
base::RandBytesAsString(kTestBlobStorageMaxBlobMemorySize + 42); base::RandBytesAsString(kTestBlobStorageMaxBlobMemorySize + 42);
blink::mojom::BytesProviderPtrInfo bytes_provider_info; mojo::PendingRemote<blink::mojom::BytesProvider> bytes_provider_remote;
auto request = MakeRequest(&bytes_provider_info); auto receiver = bytes_provider_remote.InitWithNewPipeAndPassReceiver();
std::vector<blink::mojom::DataElementPtr> elements; std::vector<blink::mojom::DataElementPtr> elements;
elements.push_back( elements.push_back(
blink::mojom::DataElement::NewBytes(blink::mojom::DataElementBytes::New( blink::mojom::DataElement::NewBytes(blink::mojom::DataElementBytes::New(
kData.size(), base::nullopt, std::move(bytes_provider_info)))); kData.size(), base::nullopt, std::move(bytes_provider_remote))));
blink::mojom::BlobPtr blob; blink::mojom::BlobPtr blob;
EXPECT_TRUE(registry_->Register(MakeRequest(&blob), kId, "", "", EXPECT_TRUE(registry_->Register(MakeRequest(&blob), kId, "", "",
...@@ -1005,7 +1008,7 @@ TEST_F(BlobRegistryImplTest, ...@@ -1005,7 +1008,7 @@ TEST_F(BlobRegistryImplTest,
EXPECT_FALSE(context_->registry().HasEntry(kId)); EXPECT_FALSE(context_->registry().HasEntry(kId));
// Now cause construction to complete, if it would still be going on. // Now cause construction to complete, if it would still be going on.
CreateBytesProvider(kData, std::move(request)); CreateBytesProvider(kData, std::move(receiver));
task_environment_.RunUntilIdle(); task_environment_.RunUntilIdle();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(0u, BlobsUnderConstruction()); EXPECT_EQ(0u, BlobsUnderConstruction());
......
...@@ -26,8 +26,9 @@ class NoneNeededTransportStrategy : public BlobTransportStrategy { ...@@ -26,8 +26,9 @@ class NoneNeededTransportStrategy : public BlobTransportStrategy {
ResultCallback result_callback) ResultCallback result_callback)
: BlobTransportStrategy(builder, std::move(result_callback)) {} : BlobTransportStrategy(builder, std::move(result_callback)) {}
void AddBytesElement(blink::mojom::DataElementBytes* bytes, void AddBytesElement(
const blink::mojom::BytesProviderPtr& data) override { blink::mojom::DataElementBytes* bytes,
const mojo::Remote<blink::mojom::BytesProvider>& data) override {
DCHECK(bytes->embedded_data); DCHECK(bytes->embedded_data);
DCHECK_EQ(bytes->length, bytes->embedded_data->size()); DCHECK_EQ(bytes->length, bytes->embedded_data->size());
builder_->AppendData( builder_->AppendData(
...@@ -48,8 +49,9 @@ class ReplyTransportStrategy : public BlobTransportStrategy { ...@@ -48,8 +49,9 @@ class ReplyTransportStrategy : public BlobTransportStrategy {
ResultCallback result_callback) ResultCallback result_callback)
: BlobTransportStrategy(builder, std::move(result_callback)) {} : BlobTransportStrategy(builder, std::move(result_callback)) {}
void AddBytesElement(blink::mojom::DataElementBytes* bytes, void AddBytesElement(
const blink::mojom::BytesProviderPtr& data) override { blink::mojom::DataElementBytes* bytes,
const mojo::Remote<blink::mojom::BytesProvider>& data) override {
BlobDataBuilder::FutureData future_data = BlobDataBuilder::FutureData future_data =
builder_->AppendFutureData(bytes->length); builder_->AppendFutureData(bytes->length);
// base::Unretained is safe because |this| is guaranteed (by the contract // base::Unretained is safe because |this| is guaranteed (by the contract
...@@ -109,8 +111,9 @@ class DataPipeTransportStrategy : public BlobTransportStrategy { ...@@ -109,8 +111,9 @@ class DataPipeTransportStrategy : public BlobTransportStrategy {
mojo::SimpleWatcher::ArmingPolicy::AUTOMATIC, mojo::SimpleWatcher::ArmingPolicy::AUTOMATIC,
base::SequencedTaskRunnerHandle::Get()) {} base::SequencedTaskRunnerHandle::Get()) {}
void AddBytesElement(blink::mojom::DataElementBytes* bytes, void AddBytesElement(
const blink::mojom::BytesProviderPtr& data) override { blink::mojom::DataElementBytes* bytes,
const mojo::Remote<blink::mojom::BytesProvider>& data) override {
// Split up the data in |max_bytes_data_item_size| sized chunks. // Split up the data in |max_bytes_data_item_size| sized chunks.
std::vector<BlobDataBuilder::FutureData> future_data; std::vector<BlobDataBuilder::FutureData> future_data;
for (uint64_t source_offset = 0; source_offset < bytes->length; for (uint64_t source_offset = 0; source_offset < bytes->length;
...@@ -260,8 +263,9 @@ class FileTransportStrategy : public BlobTransportStrategy { ...@@ -260,8 +263,9 @@ class FileTransportStrategy : public BlobTransportStrategy {
: BlobTransportStrategy(builder, std::move(result_callback)), : BlobTransportStrategy(builder, std::move(result_callback)),
limits_(limits) {} limits_(limits) {}
void AddBytesElement(blink::mojom::DataElementBytes* bytes, void AddBytesElement(
const blink::mojom::BytesProviderPtr& data) override { blink::mojom::DataElementBytes* bytes,
const mojo::Remote<blink::mojom::BytesProvider>& data) override {
uint64_t source_offset = 0; uint64_t source_offset = 0;
while (source_offset < bytes->length) { while (source_offset < bytes->length) {
if (current_file_size_ >= limits_.max_file_size || if (current_file_size_ >= limits_.max_file_size ||
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/component_export.h" #include "base/component_export.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "storage/browser/blob/blob_memory_controller.h" #include "storage/browser/blob/blob_memory_controller.h"
#include "third_party/blink/public/mojom/blob/blob_registry.mojom.h" #include "third_party/blink/public/mojom/blob/blob_registry.mojom.h"
...@@ -35,8 +36,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobTransportStrategy { ...@@ -35,8 +36,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobTransportStrategy {
// outlive the BlobTransportStrategy instance. If |data| is bound, this call // outlive the BlobTransportStrategy instance. If |data| is bound, this call
// may use it to acquire the bytes asynchronously rather than reading from // may use it to acquire the bytes asynchronously rather than reading from
// |bytes|. // |bytes|.
virtual void AddBytesElement(blink::mojom::DataElementBytes* bytes, virtual void AddBytesElement(
const blink::mojom::BytesProviderPtr& data) = 0; blink::mojom::DataElementBytes* bytes,
const mojo::Remote<blink::mojom::BytesProvider>& data) = 0;
// Called when quota has been allocated and transportation should begin. // Called when quota has been allocated and transportation should begin.
// Implementations will call the |result_callback_| when transportation has // Implementations will call the |result_callback_| when transportation has
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "mojo/core/embedder/embedder.h" #include "mojo/core/embedder/embedder.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "storage/browser/blob/blob_data_builder.h" #include "storage/browser/blob/blob_data_builder.h"
#include "storage/browser/test/mock_bytes_provider.h" #include "storage/browser/test/mock_bytes_provider.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -40,9 +40,10 @@ const uint64_t kTestBlobStorageMaxFileSizeBytes = 100; ...@@ -40,9 +40,10 @@ const uint64_t kTestBlobStorageMaxFileSizeBytes = 100;
const char kId[] = "blob-id"; const char kId[] = "blob-id";
void BindBytesProvider(std::unique_ptr<MockBytesProvider> impl, void BindBytesProvider(
blink::mojom::BytesProviderRequest request) { std::unique_ptr<MockBytesProvider> impl,
mojo::MakeStrongBinding(std::move(impl), std::move(request)); mojo::PendingReceiver<blink::mojom::BytesProvider> receiver) {
mojo::MakeSelfOwnedReceiver(std::move(impl), std::move(receiver));
} }
class BlobTransportStrategyTest : public testing::Test { class BlobTransportStrategyTest : public testing::Test {
...@@ -81,16 +82,16 @@ class BlobTransportStrategyTest : public testing::Test { ...@@ -81,16 +82,16 @@ class BlobTransportStrategyTest : public testing::Test {
bad_messages_.push_back(error); bad_messages_.push_back(error);
} }
blink::mojom::BytesProviderPtr CreateBytesProvider( mojo::PendingRemote<blink::mojom::BytesProvider> CreateBytesProvider(
const std::string& bytes, const std::string& bytes,
base::Optional<base::Time> time) { base::Optional<base::Time> time) {
blink::mojom::BytesProviderPtr result; mojo::PendingRemote<blink::mojom::BytesProvider> result;
auto provider = std::make_unique<MockBytesProvider>( auto provider = std::make_unique<MockBytesProvider>(
std::vector<uint8_t>(bytes.begin(), bytes.end()), &reply_request_count_, std::vector<uint8_t>(bytes.begin(), bytes.end()), &reply_request_count_,
&stream_request_count_, &file_request_count_, time); &stream_request_count_, &file_request_count_, time);
bytes_provider_runner_->PostTask( bytes_provider_runner_->PostTask(
FROM_HERE, base::BindOnce(&BindBytesProvider, std::move(provider), FROM_HERE, base::BindOnce(&BindBytesProvider, std::move(provider),
MakeRequest(&result))); result.InitWithNewPipeAndPassReceiver()));
return result; return result;
} }
...@@ -157,21 +158,27 @@ TEST_P(BasicTests, WithBytes) { ...@@ -157,21 +158,27 @@ TEST_P(BasicTests, WithBytes) {
std::string data = base::RandBytesAsString(7); std::string data = base::RandBytesAsString(7);
blink::mojom::DataElementBytes bytes1( blink::mojom::DataElementBytes bytes1(
data.size(), std::vector<uint8_t>(data.begin(), data.end()), nullptr); data.size(), std::vector<uint8_t>(data.begin(), data.end()),
auto bytes_provider1 = CreateBytesProvider(data, mock_time_); mojo::NullRemote());
mojo::Remote<blink::mojom::BytesProvider> bytes_provider1(
CreateBytesProvider(data, mock_time_));
strategy->AddBytesElement(&bytes1, bytes_provider1); strategy->AddBytesElement(&bytes1, bytes_provider1);
expected.AppendData(data); expected.AppendData(data);
data = base::RandBytesAsString(3); data = base::RandBytesAsString(3);
blink::mojom::DataElementBytes bytes2( blink::mojom::DataElementBytes bytes2(
data.size(), std::vector<uint8_t>(data.begin(), data.end()), nullptr); data.size(), std::vector<uint8_t>(data.begin(), data.end()),
auto bytes_provider2 = CreateBytesProvider(data, mock_time_); mojo::NullRemote());
mojo::Remote<blink::mojom::BytesProvider> bytes_provider2(
CreateBytesProvider(data, mock_time_));
strategy->AddBytesElement(&bytes2, bytes_provider2); strategy->AddBytesElement(&bytes2, bytes_provider2);
expected.AppendData(data); expected.AppendData(data);
data = base::RandBytesAsString(10); data = base::RandBytesAsString(10);
blink::mojom::DataElementBytes bytes3(data.size(), base::nullopt, nullptr); blink::mojom::DataElementBytes bytes3(data.size(), base::nullopt,
auto bytes_provider3 = CreateBytesProvider(data, mock_time_); mojo::NullRemote());
mojo::Remote<blink::mojom::BytesProvider> bytes_provider3(
CreateBytesProvider(data, mock_time_));
if (GetParam() != MemoryStrategy::NONE_NEEDED) { if (GetParam() != MemoryStrategy::NONE_NEEDED) {
strategy->AddBytesElement(&bytes3, bytes_provider3); strategy->AddBytesElement(&bytes3, bytes_provider3);
expected.AppendData(data); expected.AppendData(data);
...@@ -229,8 +236,10 @@ TEST_P(BasicErrorTests, NotEnoughBytesInProvider) { ...@@ -229,8 +236,10 @@ TEST_P(BasicErrorTests, NotEnoughBytesInProvider) {
limits_); limits_);
std::string data = base::RandBytesAsString(7); std::string data = base::RandBytesAsString(7);
blink::mojom::DataElementBytes bytes(data.size(), base::nullopt, nullptr); blink::mojom::DataElementBytes bytes(data.size(), base::nullopt,
auto bytes_provider = CreateBytesProvider(data.substr(0, 4), mock_time_); mojo::NullRemote());
mojo::Remote<blink::mojom::BytesProvider> bytes_provider(
CreateBytesProvider(data.substr(0, 4), mock_time_));
strategy->AddBytesElement(&bytes, bytes_provider); strategy->AddBytesElement(&bytes, bytes_provider);
strategy->BeginTransport(FileInfoVector()); strategy->BeginTransport(FileInfoVector());
...@@ -257,8 +266,10 @@ TEST_P(BasicErrorTests, TooManyBytesInProvider) { ...@@ -257,8 +266,10 @@ TEST_P(BasicErrorTests, TooManyBytesInProvider) {
limits_); limits_);
std::string data = base::RandBytesAsString(4); std::string data = base::RandBytesAsString(4);
blink::mojom::DataElementBytes bytes(data.size(), base::nullopt, nullptr); blink::mojom::DataElementBytes bytes(data.size(), base::nullopt,
auto bytes_provider = CreateBytesProvider(data + "foobar", mock_time_); mojo::NullRemote());
mojo::Remote<blink::mojom::BytesProvider> bytes_provider(
CreateBytesProvider(data + "foobar", mock_time_));
strategy->AddBytesElement(&bytes, bytes_provider); strategy->AddBytesElement(&bytes, bytes_provider);
strategy->BeginTransport(FileInfoVector()); strategy->BeginTransport(FileInfoVector());
...@@ -297,8 +308,10 @@ TEST_F(BlobTransportStrategyTest, DataStreamChunksData) { ...@@ -297,8 +308,10 @@ TEST_F(BlobTransportStrategyTest, DataStreamChunksData) {
std::string data = std::string data =
base::RandBytesAsString(kTestBlobStorageMaxSharedMemoryBytes * 3 + 13); base::RandBytesAsString(kTestBlobStorageMaxSharedMemoryBytes * 3 + 13);
blink::mojom::DataElementBytes bytes(data.size(), base::nullopt, nullptr); blink::mojom::DataElementBytes bytes(data.size(), base::nullopt,
auto bytes_provider = CreateBytesProvider(data, mock_time_); mojo::NullRemote());
mojo::Remote<blink::mojom::BytesProvider> bytes_provider(
CreateBytesProvider(data, mock_time_));
strategy->AddBytesElement(&bytes, bytes_provider); strategy->AddBytesElement(&bytes, bytes_provider);
size_t offset = 0; size_t offset = 0;
...@@ -363,8 +376,10 @@ TEST_F(BlobTransportStrategyTest, Files_WriteFailed) { ...@@ -363,8 +376,10 @@ TEST_F(BlobTransportStrategyTest, Files_WriteFailed) {
limits_); limits_);
std::string data = base::RandBytesAsString(kTestBlobStorageMaxFileSizeBytes); std::string data = base::RandBytesAsString(kTestBlobStorageMaxFileSizeBytes);
blink::mojom::DataElementBytes bytes(data.size(), base::nullopt, nullptr); blink::mojom::DataElementBytes bytes(data.size(), base::nullopt,
auto bytes_provider = CreateBytesProvider(data, base::nullopt); mojo::NullRemote());
mojo::Remote<blink::mojom::BytesProvider> bytes_provider(
CreateBytesProvider(data, base::nullopt));
strategy->AddBytesElement(&bytes, bytes_provider); strategy->AddBytesElement(&bytes, bytes_provider);
FileInfoVector files(1); FileInfoVector files(1);
...@@ -405,8 +420,10 @@ TEST_F(BlobTransportStrategyTest, Files_ValidBytesOneElement) { ...@@ -405,8 +420,10 @@ TEST_F(BlobTransportStrategyTest, Files_ValidBytesOneElement) {
std::string data = std::string data =
base::RandBytesAsString(kTestBlobStorageMaxBlobMemorySize + 42); base::RandBytesAsString(kTestBlobStorageMaxBlobMemorySize + 42);
blink::mojom::DataElementBytes bytes(data.size(), base::nullopt, nullptr); blink::mojom::DataElementBytes bytes(data.size(), base::nullopt,
auto bytes_provider = CreateBytesProvider(data, mock_time_); mojo::NullRemote());
mojo::Remote<blink::mojom::BytesProvider> bytes_provider(
CreateBytesProvider(data, mock_time_));
strategy->AddBytesElement(&bytes, bytes_provider); strategy->AddBytesElement(&bytes, bytes_provider);
size_t expected_file_count = size_t expected_file_count =
...@@ -459,17 +476,25 @@ TEST_F(BlobTransportStrategyTest, Files_ValidBytesMultipleElements) { ...@@ -459,17 +476,25 @@ TEST_F(BlobTransportStrategyTest, Files_ValidBytesMultipleElements) {
std::string data = std::string data =
base::RandBytesAsString(kTestBlobStorageMaxBlobMemorySize / 3); base::RandBytesAsString(kTestBlobStorageMaxBlobMemorySize / 3);
blink::mojom::DataElementBytes bytes1(data.size(), base::nullopt, nullptr); blink::mojom::DataElementBytes bytes1(data.size(), base::nullopt,
auto bytes_provider1 = CreateBytesProvider(data, mock_time_); mojo::NullRemote());
mojo::Remote<blink::mojom::BytesProvider> bytes_provider1(
CreateBytesProvider(data, mock_time_));
strategy->AddBytesElement(&bytes1, bytes_provider1); strategy->AddBytesElement(&bytes1, bytes_provider1);
blink::mojom::DataElementBytes bytes2(data.size(), base::nullopt, nullptr); blink::mojom::DataElementBytes bytes2(data.size(), base::nullopt,
auto bytes_provider2 = CreateBytesProvider(data, mock_time_); mojo::NullRemote());
mojo::Remote<blink::mojom::BytesProvider> bytes_provider2(
CreateBytesProvider(data, mock_time_));
strategy->AddBytesElement(&bytes2, bytes_provider2); strategy->AddBytesElement(&bytes2, bytes_provider2);
blink::mojom::DataElementBytes bytes3(data.size(), base::nullopt, nullptr); blink::mojom::DataElementBytes bytes3(data.size(), base::nullopt,
auto bytes_provider3 = CreateBytesProvider(data, mock_time_); mojo::NullRemote());
mojo::Remote<blink::mojom::BytesProvider> bytes_provider3(
CreateBytesProvider(data, mock_time_));
strategy->AddBytesElement(&bytes3, bytes_provider3); strategy->AddBytesElement(&bytes3, bytes_provider3);
blink::mojom::DataElementBytes bytes4(data.size(), base::nullopt, nullptr); blink::mojom::DataElementBytes bytes4(data.size(), base::nullopt,
auto bytes_provider4 = CreateBytesProvider(data, mock_time_); mojo::NullRemote());
mojo::Remote<blink::mojom::BytesProvider> bytes_provider4(
CreateBytesProvider(data, mock_time_));
strategy->AddBytesElement(&bytes4, bytes_provider4); strategy->AddBytesElement(&bytes4, bytes_provider4);
size_t expected_file_count = size_t expected_file_count =
......
...@@ -38,7 +38,7 @@ struct DataElementBytes { ...@@ -38,7 +38,7 @@ struct DataElementBytes {
// equal to |length|. // equal to |length|.
array<uint8>? embedded_data; array<uint8>? embedded_data;
// Interface through which the blob registry can request the data. // Interface through which the blob registry can request the data.
BytesProvider data; pending_remote<BytesProvider> data;
}; };
// Interface through which the blob registry can request data when it is ready // Interface through which the blob registry can request data when it is ready
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/platform/instrumentation/histogram.h" #include "third_party/blink/renderer/platform/instrumentation/histogram.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h" #include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
...@@ -116,7 +116,7 @@ constexpr size_t BlobBytesProvider::kMaxConsolidatedItemSizeInBytes; ...@@ -116,7 +116,7 @@ constexpr size_t BlobBytesProvider::kMaxConsolidatedItemSizeInBytes;
// static // static
BlobBytesProvider* BlobBytesProvider::CreateAndBind( BlobBytesProvider* BlobBytesProvider::CreateAndBind(
mojom::blink::BytesProviderRequest request) { mojo::PendingReceiver<mojom::blink::BytesProvider> receiver) {
auto task_runner = base::CreateSequencedTaskRunner( auto task_runner = base::CreateSequencedTaskRunner(
{base::ThreadPool(), base::MayBlock(), base::TaskPriority::USER_VISIBLE}); {base::ThreadPool(), base::MayBlock(), base::TaskPriority::USER_VISIBLE});
auto provider = base::WrapUnique(new BlobBytesProvider(task_runner)); auto provider = base::WrapUnique(new BlobBytesProvider(task_runner));
...@@ -127,10 +127,11 @@ BlobBytesProvider* BlobBytesProvider::CreateAndBind( ...@@ -127,10 +127,11 @@ BlobBytesProvider* BlobBytesProvider::CreateAndBind(
*task_runner, FROM_HERE, *task_runner, FROM_HERE,
CrossThreadBindOnce( CrossThreadBindOnce(
[](std::unique_ptr<BlobBytesProvider> provider, [](std::unique_ptr<BlobBytesProvider> provider,
mojom::blink::BytesProviderRequest request) { mojo::PendingReceiver<mojom::blink::BytesProvider> receiver) {
mojo::MakeStrongBinding(std::move(provider), std::move(request)); mojo::MakeSelfOwnedReceiver(std::move(provider),
std::move(receiver));
}, },
WTF::Passed(std::move(provider)), WTF::Passed(std::move(request)))); WTF::Passed(std::move(provider)), WTF::Passed(std::move(receiver))));
return result; return result;
} }
......
...@@ -28,7 +28,8 @@ class PLATFORM_EXPORT BlobBytesProvider : public mojom::blink::BytesProvider { ...@@ -28,7 +28,8 @@ class PLATFORM_EXPORT BlobBytesProvider : public mojom::blink::BytesProvider {
// Creates a new instance, and binds it on a new SequencedTaskRunner. The // Creates a new instance, and binds it on a new SequencedTaskRunner. The
// returned instance should only be considered valid as long as the request // returned instance should only be considered valid as long as the request
// passed in to this method is still known to be valid. // passed in to this method is still known to be valid.
static BlobBytesProvider* CreateAndBind(mojom::blink::BytesProviderRequest); static BlobBytesProvider* CreateAndBind(
mojo::PendingReceiver<mojom::blink::BytesProvider>);
static std::unique_ptr<BlobBytesProvider> CreateForTesting( static std::unique_ptr<BlobBytesProvider> CreateForTesting(
scoped_refptr<base::SequencedTaskRunner>); scoped_refptr<base::SequencedTaskRunner>);
......
...@@ -57,16 +57,14 @@ namespace blink { ...@@ -57,16 +57,14 @@ namespace blink {
using mojom::blink::BlobPtr; using mojom::blink::BlobPtr;
using mojom::blink::BlobPtrInfo; using mojom::blink::BlobPtrInfo;
using mojom::blink::BytesProviderPtr; using mojom::blink::BytesProvider;
using mojom::blink::BytesProviderPtrInfo;
using mojom::blink::BytesProviderRequest;
using mojom::blink::DataElement; using mojom::blink::DataElement;
using mojom::blink::DataElementBlob; using mojom::blink::DataElementBlob;
using mojom::blink::DataElementPtr;
using mojom::blink::DataElementBytes; using mojom::blink::DataElementBytes;
using mojom::blink::DataElementBytesPtr; using mojom::blink::DataElementBytesPtr;
using mojom::blink::DataElementFile; using mojom::blink::DataElementFile;
using mojom::blink::DataElementFilesystemURL; using mojom::blink::DataElementFilesystemURL;
using mojom::blink::DataElementPtr;
namespace { namespace {
...@@ -286,12 +284,12 @@ void BlobData::AppendDataInternal(base::span<const char> data, ...@@ -286,12 +284,12 @@ void BlobData::AppendDataInternal(base::span<const char> data,
bytes_element->embedded_data = base::nullopt; bytes_element->embedded_data = base::nullopt;
} }
} else { } else {
BytesProviderPtrInfo bytes_provider_info; mojo::PendingRemote<BytesProvider> bytes_provider_remote;
last_bytes_provider_ = last_bytes_provider_ = BlobBytesProvider::CreateAndBind(
BlobBytesProvider::CreateAndBind(MakeRequest(&bytes_provider_info)); bytes_provider_remote.InitWithNewPipeAndPassReceiver());
auto bytes_element = DataElementBytes::New(data.size(), base::nullopt, auto bytes_element = DataElementBytes::New(
std::move(bytes_provider_info)); data.size(), base::nullopt, std::move(bytes_provider_remote));
if (should_embed_bytes) { if (should_embed_bytes) {
bytes_element->embedded_data = Vector<uint8_t>(); bytes_element->embedded_data = Vector<uint8_t>();
bytes_element->embedded_data->Append(data.data(), data.size()); bytes_element->embedded_data->Append(data.data(), data.size());
......
...@@ -42,14 +42,14 @@ struct ExpectedElement { ...@@ -42,14 +42,14 @@ struct ExpectedElement {
static ExpectedElement EmbeddedBytes(Vector<uint8_t> embedded_data) { static ExpectedElement EmbeddedBytes(Vector<uint8_t> embedded_data) {
uint64_t size = embedded_data.size(); uint64_t size = embedded_data.size();
return ExpectedElement{DataElement::NewBytes( return ExpectedElement{DataElement::NewBytes(DataElementBytes::New(
DataElementBytes::New(size, std::move(embedded_data), nullptr))}; size, std::move(embedded_data), mojo::NullRemote()))};
} }
static ExpectedElement LargeBytes(Vector<uint8_t> data) { static ExpectedElement LargeBytes(Vector<uint8_t> data) {
uint64_t size = data.size(); uint64_t size = data.size();
return ExpectedElement{DataElement::NewBytes(DataElementBytes::New( return ExpectedElement{DataElement::NewBytes(DataElementBytes::New(
size, base::nullopt, nullptr)), size, base::nullopt, mojo::NullRemote())),
String(), std::move(data)}; String(), std::move(data)};
} }
...@@ -165,7 +165,7 @@ class BlobDataHandleTest : public testing::Test { ...@@ -165,7 +165,7 @@ class BlobDataHandleTest : public testing::Test {
base::RunLoop loop; base::RunLoop loop;
Vector<uint8_t> received_bytes; Vector<uint8_t> received_bytes;
mojom::blink::BytesProviderPtr actual_data( mojo::Remote<mojom::blink::BytesProvider> actual_data(
std::move(actual->get_bytes()->data)); std::move(actual->get_bytes()->data));
actual_data->RequestAsReply(base::BindOnce( actual_data->RequestAsReply(base::BindOnce(
[](base::Closure quit_closure, Vector<uint8_t>* bytes_out, [](base::Closure quit_closure, Vector<uint8_t>* bytes_out,
......
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