Skip to content

Commit

Permalink
Convert BlobURLTokenRequest to new Mojo types
Browse files Browse the repository at this point in the history
This CL converts BlobURLTokenRequest to new Mojo types.
It updates ResolveForNavigation and Clone from
blob_url_store.mojom and methods and members with new
Mojo types.

Bug: 955171, 978694
Change-Id: Ib18e1c3834e6b0c6129cd2c9b1f13930a06a909d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1772791
Reviewed-by: Ken Rockot <rockot@google.com>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#691595}
  • Loading branch information
jkim-julie authored and Commit Bot committed Aug 29, 2019
1 parent 910657f commit df939f0
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 21 deletions.
19 changes: 10 additions & 9 deletions storage/browser/blob/blob_url_store_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "storage/browser/blob/blob_url_store_impl.h"

#include "base/bind.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "storage/browser/blob/blob_impl.h"
#include "storage/browser/blob/blob_storage_context.h"
#include "storage/browser/blob/blob_url_loader_factory.h"
Expand All @@ -19,13 +19,13 @@ class BlobURLTokenImpl : public blink::mojom::BlobURLToken {
BlobURLTokenImpl(base::WeakPtr<BlobStorageContext> context,
const GURL& url,
std::unique_ptr<BlobDataHandle> blob,
blink::mojom::BlobURLTokenRequest request)
mojo::PendingReceiver<blink::mojom::BlobURLToken> receiver)
: context_(std::move(context)),
url_(url),
blob_(std::move(blob)),
token_(base::UnguessableToken::Create()) {
bindings_.AddBinding(this, std::move(request));
bindings_.set_connection_error_handler(base::BindRepeating(
receivers_.Add(this, std::move(receiver));
receivers_.set_disconnect_handler(base::BindRepeating(
&BlobURLTokenImpl::OnConnectionError, base::Unretained(this)));
if (context_) {
context_->mutable_registry()->AddTokenMapping(token_, url_,
Expand All @@ -42,19 +42,20 @@ class BlobURLTokenImpl : public blink::mojom::BlobURLToken {
std::move(callback).Run(token_);
}

void Clone(blink::mojom::BlobURLTokenRequest request) override {
bindings_.AddBinding(this, std::move(request));
void Clone(
mojo::PendingReceiver<blink::mojom::BlobURLToken> receiver) override {
receivers_.Add(this, std::move(receiver));
}

private:
void OnConnectionError() {
if (!bindings_.empty())
if (!receivers_.empty())
return;
delete this;
}

base::WeakPtr<BlobStorageContext> context_;
mojo::BindingSet<blink::mojom::BlobURLToken> bindings_;
mojo::ReceiverSet<blink::mojom::BlobURLToken> receivers_;
const GURL url_;
const std::unique_ptr<BlobDataHandle> blob_;
const base::UnguessableToken token_;
Expand Down Expand Up @@ -151,7 +152,7 @@ void BlobURLStoreImpl::ResolveAsURLLoaderFactory(

void BlobURLStoreImpl::ResolveForNavigation(
const GURL& url,
blink::mojom::BlobURLTokenRequest token) {
mojo::PendingReceiver<blink::mojom::BlobURLToken> token) {
if (!context_)
return;
std::unique_ptr<BlobDataHandle> blob_handle =
Expand Down
5 changes: 3 additions & 2 deletions storage/browser/blob/blob_url_store_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobURLStoreImpl
void ResolveAsURLLoaderFactory(
const GURL& url,
network::mojom::URLLoaderFactoryRequest request) override;
void ResolveForNavigation(const GURL& url,
blink::mojom::BlobURLTokenRequest token) override;
void ResolveForNavigation(
const GURL& url,
mojo::PendingReceiver<blink::mojom::BlobURLToken> token) override;

private:
void RegisterWithUUID(blink::mojom::BlobPtr blob,
Expand Down
4 changes: 2 additions & 2 deletions third_party/blink/public/mojom/blob/blob_url_store.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ interface BlobURLStore {
// used by the browser process to securely look up the blob a URL used to
// refer to, even after the URL is revoked.
// As long as the token is alive, the resolved blob will also be kept alive.
ResolveForNavigation(url.mojom.Url url, BlobURLToken& token);
ResolveForNavigation(url.mojom.Url url, pending_receiver<BlobURLToken> token);
};

// A token representing a Blob URL. The browser process can use this to look up
// the blob URL and blob it referred to, even after the blob URL itself is
// revoked. For the renderer this is just an opaque token without any meaning.
interface BlobURLToken {
Clone(BlobURLToken& token);
Clone(pending_receiver<BlobURLToken> token);
GetToken() => (mojo_base.mojom.UnguessableToken token);
};
4 changes: 2 additions & 2 deletions third_party/blink/renderer/core/fileapi/public_url_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void PublicURLManager::Resolve(

void PublicURLManager::Resolve(
const KURL& url,
mojom::blink::BlobURLTokenRequest token_request) {
mojo::PendingReceiver<mojom::blink::BlobURLToken> token_receiver) {
if (is_stopped_)
return;

Expand All @@ -185,7 +185,7 @@ void PublicURLManager::Resolve(
GetExecutionContext()->GetSecurityOrigin(),
url_store_.BindNewEndpointAndPassReceiver());
}
url_store_->ResolveForNavigation(url, std::move(token_request));
url_store_->ResolveForNavigation(url, std::move(token_receiver));
}

void PublicURLManager::ContextDestroyed(ExecutionContext*) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CORE_EXPORT PublicURLManager final
// BlobURLToken. This token can be used by the browser process to securely
// lookup what blob a URL used to refer to, even after the URL is revoked.
// If the URL fails to resolve the request will simply be disconnected.
void Resolve(const KURL&, mojom::blink::BlobURLTokenRequest);
void Resolve(const KURL&, mojo::PendingReceiver<mojom::blink::BlobURLToken>);

// ContextLifecycleObserver interface.
void ContextDestroyed(ExecutionContext*) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ void FakeBlobURLStore::ResolveAsURLLoaderFactory(
NOTREACHED();
}

void FakeBlobURLStore::ResolveForNavigation(const KURL&,
mojom::blink::BlobURLTokenRequest) {
void FakeBlobURLStore::ResolveForNavigation(
const KURL&,
mojo::PendingReceiver<mojom::blink::BlobURLToken>) {
NOTREACHED();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "third_party/blink/public/mojom/blob/blob_url_store.mojom-blink.h"

#include "mojo/public/cpp/bindings/binding_set.h"
#include "third_party/blink/renderer/platform/weborigin/kurl_hash.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
Expand All @@ -23,8 +22,9 @@ class FakeBlobURLStore : public mojom::blink::BlobURLStore {
void ResolveAsURLLoaderFactory(
const KURL&,
network::mojom::blink::URLLoaderFactoryRequest) override;
void ResolveForNavigation(const KURL&,
mojom::blink::BlobURLTokenRequest) override;
void ResolveForNavigation(
const KURL&,
mojo::PendingReceiver<mojom::blink::BlobURLToken>) override;

HashMap<KURL, mojom::blink::BlobPtr> registrations;
Vector<KURL> revocations;
Expand Down

0 comments on commit df939f0

Please sign in to comment.