Commit 74debd20 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Convert BlobURLStore to new Mojo types

This CL converts BlobURLStoreAssociatedRequest,
BlobURLStoreAssociatedPtr, BlobURLStorePtr, and
BlobURLStoreAssociatedRequest to new Mojo types.
It updates URLStoreForOrigin from blob_registry.mojom and
methods and members with new Mojo types.

Bug: 955171, 978694
Change-Id: I4206429d8d46cd9321ec871599818153ef9d1fe3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1772790Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#691550}
parent 19206c68
......@@ -9,8 +9,6 @@
#include "base/barrier_closure.h"
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "mojo/public/cpp/bindings/strong_associated_binding.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "storage/browser/blob/blob_builder_from_stream.h"
#include "storage/browser/blob/blob_data_builder.h"
#include "storage/browser/blob/blob_impl.h"
......@@ -603,17 +601,17 @@ void BlobRegistryImpl::GetBlobFromUUID(
void BlobRegistryImpl::URLStoreForOrigin(
const url::Origin& origin,
blink::mojom::BlobURLStoreAssociatedRequest request) {
mojo::PendingAssociatedReceiver<blink::mojom::BlobURLStore> receiver) {
// TODO(mek): Pass origin on to BlobURLStoreImpl so it can use it to generate
// Blob URLs, and verify at this point that the renderer can create URLs for
// that origin.
Delegate* delegate = receivers_.current_context().get();
DCHECK(delegate);
auto binding = mojo::MakeStrongAssociatedBinding(
auto self_owned_associated_receiver = mojo::MakeSelfOwnedAssociatedReceiver(
std::make_unique<BlobURLStoreImpl>(context_, delegate),
std::move(request));
std::move(receiver));
if (g_url_store_creation_hook)
g_url_store_creation_hook->Run(binding);
g_url_store_creation_hook->Run(self_owned_associated_receiver);
}
// static
......
......@@ -10,7 +10,7 @@
#include "base/containers/flat_set.h"
#include "base/containers/unique_ptr_adapters.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/strong_associated_binding.h"
#include "mojo/public/cpp/bindings/self_owned_associated_receiver.h"
#include "storage/browser/fileapi/file_system_context.h"
#include "third_party/blink/public/mojom/blob/blob_registry.mojom.h"
......@@ -62,7 +62,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobRegistryImpl
void URLStoreForOrigin(
const url::Origin& origin,
blink::mojom::BlobURLStoreAssociatedRequest url_store) override;
mojo::PendingAssociatedReceiver<blink::mojom::BlobURLStore> url_store)
override;
size_t BlobsUnderConstructionForTesting() const {
return blobs_under_construction_.size();
......@@ -73,7 +74,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobRegistryImpl
}
using URLStoreCreationHook = base::RepeatingCallback<void(
mojo::StrongAssociatedBindingPtr<blink::mojom::BlobURLStore>)>;
mojo::SelfOwnedAssociatedReceiverRef<blink::mojom::BlobURLStore>)>;
static void SetURLStoreCreationHookForTesting(URLStoreCreationHook* hook);
private:
......
......@@ -8,7 +8,8 @@
#include "base/test/bind_test_util.h"
#include "base/test/task_environment.h"
#include "mojo/core/embedder/embedder.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
......@@ -20,7 +21,6 @@
using blink::mojom::BlobPtr;
using blink::mojom::BlobURLStore;
using blink::mojom::BlobURLStorePtr;
namespace storage {
......@@ -67,11 +67,11 @@ class BlobURLStoreImplTest : public testing::Test {
return received_uuid;
}
BlobURLStorePtr CreateURLStore() {
BlobURLStorePtr result;
mojo::MakeStrongBinding(
mojo::PendingRemote<BlobURLStore> CreateURLStore() {
mojo::PendingRemote<BlobURLStore> result;
mojo::MakeSelfOwnedReceiver(
std::make_unique<BlobURLStoreImpl>(context_->AsWeakPtr(), &delegate_),
MakeRequest(&result));
result.InitWithNewPipeAndPassReceiver());
return result;
}
......@@ -132,7 +132,7 @@ TEST_F(BlobURLStoreImplTest, BasicRegisterRevoke) {
TEST_F(BlobURLStoreImplTest, RegisterInvalidScheme) {
BlobPtr blob = CreateBlobFromString(kId, "hello world");
BlobURLStorePtr url_store = CreateURLStore();
mojo::Remote<BlobURLStore> url_store(CreateURLStore());
RegisterURL(url_store.get(), std::move(blob), kInvalidUrl);
EXPECT_FALSE(context_->GetBlobDataFromPublicURL(kInvalidUrl));
EXPECT_EQ(1u, bad_messages_.size());
......@@ -143,7 +143,7 @@ TEST_F(BlobURLStoreImplTest, RegisterCantCommit) {
delegate_.can_commit_url_result = false;
BlobURLStorePtr url_store = CreateURLStore();
mojo::Remote<BlobURLStore> url_store(CreateURLStore());
RegisterURL(url_store.get(), std::move(blob), kValidUrl);
EXPECT_FALSE(context_->GetBlobDataFromPublicURL(kValidUrl));
EXPECT_EQ(1u, bad_messages_.size());
......@@ -152,7 +152,7 @@ TEST_F(BlobURLStoreImplTest, RegisterCantCommit) {
TEST_F(BlobURLStoreImplTest, RegisterUrlFragment) {
BlobPtr blob = CreateBlobFromString(kId, "hello world");
BlobURLStorePtr url_store = CreateURLStore();
mojo::Remote<BlobURLStore> url_store(CreateURLStore());
RegisterURL(url_store.get(), std::move(blob), kFragmentUrl);
EXPECT_FALSE(context_->GetBlobDataFromPublicURL(kFragmentUrl));
EXPECT_EQ(1u, bad_messages_.size());
......@@ -191,7 +191,7 @@ TEST_F(BlobURLStoreImplTest, RevokeThroughDifferentURLStore) {
}
TEST_F(BlobURLStoreImplTest, RevokeInvalidScheme) {
BlobURLStorePtr url_store = CreateURLStore();
mojo::Remote<BlobURLStore> url_store(CreateURLStore());
url_store->Revoke(kInvalidUrl);
url_store.FlushForTesting();
EXPECT_EQ(1u, bad_messages_.size());
......@@ -200,7 +200,7 @@ TEST_F(BlobURLStoreImplTest, RevokeInvalidScheme) {
TEST_F(BlobURLStoreImplTest, RevokeCantCommit) {
delegate_.can_commit_url_result = false;
BlobURLStorePtr url_store = CreateURLStore();
mojo::Remote<BlobURLStore> url_store(CreateURLStore());
url_store->Revoke(kValidUrl);
url_store.FlushForTesting();
EXPECT_EQ(1u, bad_messages_.size());
......@@ -210,7 +210,7 @@ TEST_F(BlobURLStoreImplTest, RevokeCantCommit_ProcessNotValid) {
delegate_.can_commit_url_result = false;
delegate_.is_process_valid_result = false;
BlobURLStorePtr url_store = CreateURLStore();
mojo::Remote<BlobURLStore> url_store(CreateURLStore());
url_store->Revoke(kValidUrl);
url_store.FlushForTesting();
EXPECT_TRUE(bad_messages_.empty());
......@@ -218,7 +218,7 @@ TEST_F(BlobURLStoreImplTest, RevokeCantCommit_ProcessNotValid) {
}
TEST_F(BlobURLStoreImplTest, RevokeURLWithFragment) {
BlobURLStorePtr url_store = CreateURLStore();
mojo::Remote<BlobURLStore> url_store(CreateURLStore());
url_store->Revoke(kFragmentUrl);
url_store.FlushForTesting();
EXPECT_EQ(1u, bad_messages_.size());
......
......@@ -53,5 +53,5 @@ interface BlobRegistry {
// Returns a BlobURLStore for a specific origin.
URLStoreForOrigin(url.mojom.Origin origin,
associated blink.mojom.BlobURLStore& url_store);
pending_associated_receiver<blink.mojom.BlobURLStore> url_store);
};
......@@ -117,7 +117,7 @@ String PublicURLManager::RegisterURL(URLRegistrable* registrable) {
SCOPED_UMA_HISTOGRAM_TIMER("Storage.Blob.RegisterPublicURLTime");
if (!url_store_) {
BlobDataHandle::GetBlobRegistry()->URLStoreForOrigin(
origin, MakeRequest(&url_store_));
origin, url_store_.BindNewEndpointAndPassReceiver());
}
url_store_->Register(std::move(blob), url);
mojo_urls_.insert(url_string);
......@@ -144,7 +144,8 @@ void PublicURLManager::Revoke(const KURL& url) {
if (!url_store_) {
BlobDataHandle::GetBlobRegistry()->URLStoreForOrigin(
GetExecutionContext()->GetSecurityOrigin(), MakeRequest(&url_store_));
GetExecutionContext()->GetSecurityOrigin(),
url_store_.BindNewEndpointAndPassReceiver());
}
url_store_->Revoke(url);
mojo_urls_.erase(url.GetString());
......@@ -166,7 +167,8 @@ void PublicURLManager::Resolve(
DCHECK(url.ProtocolIs("blob"));
if (!url_store_) {
BlobDataHandle::GetBlobRegistry()->URLStoreForOrigin(
GetExecutionContext()->GetSecurityOrigin(), MakeRequest(&url_store_));
GetExecutionContext()->GetSecurityOrigin(),
url_store_.BindNewEndpointAndPassReceiver());
}
url_store_->ResolveAsURLLoaderFactory(url, std::move(factory_request));
}
......@@ -180,7 +182,8 @@ void PublicURLManager::Resolve(
DCHECK(url.ProtocolIs("blob"));
if (!url_store_) {
BlobDataHandle::GetBlobRegistry()->URLStoreForOrigin(
GetExecutionContext()->GetSecurityOrigin(), MakeRequest(&url_store_));
GetExecutionContext()->GetSecurityOrigin(),
url_store_.BindNewEndpointAndPassReceiver());
}
url_store_->ResolveForNavigation(url, std::move(token_request));
}
......
......@@ -26,6 +26,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FILEAPI_PUBLIC_URL_MANAGER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_FILEAPI_PUBLIC_URL_MANAGER_H_
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "services/network/public/mojom/url_loader_factory.mojom-blink.h"
#include "third_party/blink/public/mojom/blob/blob_url_store.mojom-blink.h"
#include "third_party/blink/renderer/core/core_export.h"
......@@ -71,7 +72,7 @@ class CORE_EXPORT PublicURLManager final
void Trace(blink::Visitor*) override;
void SetURLStoreForTesting(
mojom::blink::BlobURLStoreAssociatedPtr url_store) {
mojo::AssociatedRemote<mojom::blink::BlobURLStore> url_store) {
url_store_ = std::move(url_store);
}
......@@ -84,7 +85,7 @@ class CORE_EXPORT PublicURLManager final
bool is_stopped_;
mojom::blink::BlobURLStoreAssociatedPtr url_store_;
mojo::AssociatedRemote<mojom::blink::BlobURLStore> url_store_;
};
} // namespace blink
......
......@@ -5,7 +5,7 @@
#include "third_party/blink/renderer/core/fileapi/public_url_manager.h"
#include "base/test/scoped_feature_list.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
......@@ -23,7 +23,6 @@ namespace {
using mojom::blink::Blob;
using mojom::blink::BlobPtr;
using mojom::blink::BlobURLStore;
using mojom::blink::BlobURLStoreAssociatedPtr;
class TestURLRegistrable : public URLRegistrable {
public:
......@@ -66,7 +65,7 @@ class FakeURLRegistry : public URLRegistry {
class PublicURLManagerTest : public testing::Test {
public:
PublicURLManagerTest() : url_store_binding_(&url_store_) {}
PublicURLManagerTest() : url_store_receiver_(&url_store_) {}
void SetUp() override {
execution_context_ = MakeGarbageCollected<NullExecutionContext>();
......@@ -74,10 +73,10 @@ class PublicURLManagerTest : public testing::Test {
// wants.
execution_context_->SetUpSecurityContext();
BlobURLStoreAssociatedPtr url_store_ptr;
url_store_binding_.Bind(
MakeRequestAssociatedWithDedicatedPipe(&url_store_ptr));
url_manager().SetURLStoreForTesting(std::move(url_store_ptr));
mojo::AssociatedRemote<BlobURLStore> url_store_remote;
url_store_receiver_.Bind(
url_store_remote.BindNewEndpointAndPassDedicatedReceiverForTesting());
url_manager().SetURLStoreForTesting(std::move(url_store_remote));
}
PublicURLManager& url_manager() {
......@@ -95,7 +94,7 @@ class PublicURLManagerTest : public testing::Test {
Persistent<NullExecutionContext> execution_context_;
FakeBlobURLStore url_store_;
mojo::AssociatedBinding<BlobURLStore> url_store_binding_;
mojo::AssociatedReceiver<BlobURLStore> url_store_receiver_;
};
TEST_F(PublicURLManagerTest, RegisterNonMojoBlob) {
......@@ -117,7 +116,7 @@ TEST_F(PublicURLManagerTest, RegisterNonMojoBlob) {
url_manager().Revoke(KURL(url));
EXPECT_FALSE(SecurityOrigin::CreateFromString(url)->IsSameSchemeHostPort(
execution_context_->GetSecurityOrigin()));
url_store_binding_.FlushForTesting();
url_store_receiver_.FlushForTesting();
// Even though this was not a mojo blob, the PublicURLManager might not know
// that, so still expect a revocation on the mojo interface.
ASSERT_EQ(1u, url_store_.revocations.size());
......@@ -141,7 +140,7 @@ TEST_F(PublicURLManagerTest, RegisterMojoBlob) {
url_manager().Revoke(KURL(url));
EXPECT_FALSE(SecurityOrigin::CreateFromString(url)->IsSameSchemeHostPort(
execution_context_->GetSecurityOrigin()));
url_store_binding_.FlushForTesting();
url_store_receiver_.FlushForTesting();
ASSERT_EQ(1u, url_store_.revocations.size());
EXPECT_EQ(url, url_store_.revocations[0]);
}
......@@ -152,7 +151,7 @@ TEST_F(PublicURLManagerTest, RevokeValidNonRegisteredURL) {
KURL url = KURL("blob:http://example.com/id");
url_manager().Revoke(url);
url_store_binding_.FlushForTesting();
url_store_receiver_.FlushForTesting();
ASSERT_EQ(1u, url_store_.revocations.size());
EXPECT_EQ(url, url_store_.revocations[0]);
}
......@@ -167,7 +166,7 @@ TEST_F(PublicURLManagerTest, RevokeInvalidURL) {
url_manager().Revoke(invalid_scheme_url);
url_manager().Revoke(fragment_url);
url_manager().Revoke(invalid_origin_url);
url_store_binding_.FlushForTesting();
url_store_receiver_.FlushForTesting();
// Both should have been silently ignored.
EXPECT_TRUE(url_store_.revocations.IsEmpty());
}
......
......@@ -147,7 +147,7 @@ class BlobDataHandleTest : public testing::Test {
EXPECT_EQ(is_single_unknown_size_file, handle->IsSingleUnknownSizeFile());
blob_registry_remote_.FlushForTesting();
EXPECT_EQ(0u, mock_blob_registry_.binding_requests.size());
EXPECT_EQ(0u, mock_blob_registry_.owned_receivers.size());
ASSERT_EQ(1u, mock_blob_registry_.registrations.size());
auto& reg = mock_blob_registry_.registrations[0];
EXPECT_EQ(handle->Uuid(), reg.uuid);
......@@ -244,7 +244,7 @@ TEST_F(BlobDataHandleTest, CreateEmpty) {
EXPECT_FALSE(handle->IsSingleUnknownSizeFile());
blob_registry_remote_.FlushForTesting();
EXPECT_EQ(0u, mock_blob_registry_.binding_requests.size());
EXPECT_EQ(0u, mock_blob_registry_.owned_receivers.size());
ASSERT_EQ(1u, mock_blob_registry_.registrations.size());
const auto& reg = mock_blob_registry_.registrations[0];
EXPECT_EQ(handle->Uuid(), reg.uuid);
......@@ -276,8 +276,8 @@ TEST_F(BlobDataHandleTest, CreateFromUUID) {
blob_registry_remote_.FlushForTesting();
EXPECT_EQ(0u, mock_blob_registry_.registrations.size());
ASSERT_EQ(1u, mock_blob_registry_.binding_requests.size());
EXPECT_EQ(kUuid, mock_blob_registry_.binding_requests[0].uuid);
ASSERT_EQ(1u, mock_blob_registry_.owned_receivers.size());
EXPECT_EQ(kUuid, mock_blob_registry_.owned_receivers[0].uuid);
}
TEST_F(BlobDataHandleTest, CreateFromEmptyElements) {
......
......@@ -37,7 +37,7 @@ void FakeBlobRegistry::GetBlobFromUUID(
mojo::PendingReceiver<mojom::blink::Blob> blob,
const String& uuid,
GetBlobFromUUIDCallback callback) {
binding_requests.push_back(BindingRequest{uuid});
owned_receivers.push_back(OwnedReceiver{uuid});
mojo::MakeSelfOwnedReceiver(std::make_unique<FakeBlob>(uuid),
std::move(blob));
std::move(callback).Run();
......@@ -45,7 +45,7 @@ void FakeBlobRegistry::GetBlobFromUUID(
void FakeBlobRegistry::URLStoreForOrigin(
const scoped_refptr<const SecurityOrigin>& origin,
mojom::blink::BlobURLStoreAssociatedRequest request) {
mojo::PendingAssociatedReceiver<mojom::blink::BlobURLStore> receiver) {
NOTREACHED();
}
......
......@@ -33,8 +33,9 @@ class FakeBlobRegistry : public mojom::blink::BlobRegistry {
const String& uuid,
GetBlobFromUUIDCallback) override;
void URLStoreForOrigin(const scoped_refptr<const SecurityOrigin>&,
mojom::blink::BlobURLStoreAssociatedRequest) override;
void URLStoreForOrigin(
const scoped_refptr<const SecurityOrigin>&,
mojo::PendingAssociatedReceiver<mojom::blink::BlobURLStore>) override;
struct Registration {
String uuid;
......@@ -44,10 +45,10 @@ class FakeBlobRegistry : public mojom::blink::BlobRegistry {
};
Vector<Registration> registrations;
struct BindingRequest {
struct OwnedReceiver {
String uuid;
};
Vector<BindingRequest> binding_requests;
Vector<OwnedReceiver> owned_receivers;
};
} // namespace blink
......
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