Commit 2b9639bc authored by Marijn Kruisselbrink's avatar Marijn Kruisselbrink Committed by Commit Bot

[FileAPI] Change BlobURLRegistry to store PendingRemotes instead of Remotes.

This not only saves memory, but also makes the (blocking) BlobUrlStore.Registry
mojom call faster by not having to set up the blob mojo binding context at
that point. On the other hand this makes blob url resolution slightly less
efficient, but this seems like the right trade-off.

Bug: 1112410
Change-Id: Ic8e97fbcc313ae053f55166d1bad5479a856b8c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2335402
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795821}
parent d125aad1
......@@ -22,7 +22,7 @@ bool BlobUrlRegistry::AddUrlMapping(
DCHECK(!BlobUrlUtils::UrlHasFragment(blob_url));
if (IsUrlMapped(blob_url))
return false;
url_to_blob_[blob_url] = mojo::Remote<blink::mojom::Blob>(std::move(blob));
url_to_blob_[blob_url] = std::move(blob);
return true;
}
......@@ -47,8 +47,10 @@ mojo::PendingRemote<blink::mojom::Blob> BlobUrlRegistry::GetBlobFromUrl(
auto it = url_to_blob_.find(BlobUrlUtils::ClearUrlFragment(url));
if (it == url_to_blob_.end())
return mojo::NullRemote();
mojo::Remote<blink::mojom::Blob> blob(std::move(it->second));
mojo::PendingRemote<blink::mojom::Blob> result;
it->second->Clone(result.InitWithNewPipeAndPassReceiver());
blob->Clone(result.InitWithNewPipeAndPassReceiver());
it->second = blob.Unbind();
return result;
}
......@@ -58,9 +60,7 @@ void BlobUrlRegistry::AddTokenMapping(
mojo::PendingRemote<blink::mojom::Blob> blob) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(token_to_url_and_blob_.find(token) == token_to_url_and_blob_.end());
token_to_url_and_blob_.emplace(
token,
std::make_pair(url, mojo::Remote<blink::mojom::Blob>(std::move(blob))));
token_to_url_and_blob_.emplace(token, std::make_pair(url, std::move(blob)));
}
void BlobUrlRegistry::RemoveTokenMapping(const base::UnguessableToken& token) {
......@@ -72,13 +72,15 @@ void BlobUrlRegistry::RemoveTokenMapping(const base::UnguessableToken& token) {
bool BlobUrlRegistry::GetTokenMapping(
const base::UnguessableToken& token,
GURL* url,
mojo::PendingRemote<blink::mojom::Blob>* blob) const {
mojo::PendingRemote<blink::mojom::Blob>* blob) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto it = token_to_url_and_blob_.find(token);
if (it == token_to_url_and_blob_.end())
return false;
*url = it->second.first;
it->second.second->Clone(blob->InitWithNewPipeAndPassReceiver());
mojo::Remote<blink::mojom::Blob> source_blob(std::move(it->second.second));
source_blob->Clone(blob->InitWithNewPipeAndPassReceiver());
it->second.second = source_blob.Unbind();
return true;
}
......
......@@ -50,7 +50,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobUrlRegistry {
void RemoveTokenMapping(const base::UnguessableToken& token);
bool GetTokenMapping(const base::UnguessableToken& token,
GURL* url,
mojo::PendingRemote<blink::mojom::Blob>* blob) const;
mojo::PendingRemote<blink::mojom::Blob>* blob);
base::WeakPtr<BlobUrlRegistry> AsWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
......@@ -59,9 +59,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobUrlRegistry {
private:
SEQUENCE_CHECKER(sequence_checker_);
std::map<GURL, mojo::Remote<blink::mojom::Blob>> url_to_blob_;
std::map<GURL, mojo::PendingRemote<blink::mojom::Blob>> url_to_blob_;
std::map<base::UnguessableToken,
std::pair<GURL, mojo::Remote<blink::mojom::Blob>>>
std::pair<GURL, mojo::PendingRemote<blink::mojom::Blob>>>
token_to_url_and_blob_;
base::WeakPtrFactory<BlobUrlRegistry> weak_ptr_factory_{this};
......
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