Skip to content

Commit

Permalink
Add metrics for Blob URL usage in data URL workers
Browse files Browse the repository at this point in the history
Note that I didn't see an easy way to add tests for this,
but I verified that the histograms were updated after running
the following WPT that creates a Blob URL from a data URL
worker:

html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/blob-data.https.html

(cherry picked from commit 2d7cca1)

Bug: 1058759,1325852
Change-Id: I9644d69fb143b89ff6cd512a3758aba5b15e3b27
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3639563
Commit-Queue: Andrew Williams <awillia@google.com>
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1002966}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3649946
Cr-Commit-Position: refs/branch-heads/5060@{#33}
Cr-Branched-From: b83393d-refs/heads/main@{#1002911}
  • Loading branch information
recvfrom authored and Chromium LUCI CQ committed May 16, 2022
1 parent 1fec745 commit f3701f4
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
52 changes: 52 additions & 0 deletions third_party/blink/renderer/core/fileapi/public_url_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "third_party/blink/renderer/core/fileapi/public_url_manager.h"

#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/unguessable_token.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
Expand All @@ -35,6 +36,7 @@
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/fileapi/url_registry.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/platform/blob/blob_data.h"
#include "third_party/blink/renderer/platform/blob/blob_url.h"
#include "third_party/blink/renderer/platform/blob/blob_url_null_origin_map.h"
Expand Down Expand Up @@ -76,6 +78,19 @@ String PublicURLManager::RegisterURL(URLRegistrable* registrable) {
DCHECK(!url.IsEmpty());
const String& url_string = url.GetString();

// Collect metrics on how frequently a worker context that makes use of the
// Blob URL API was created from a data URL. Note that we ignore service
// workers for this since they can't be created from data URLs.
if (GetExecutionContext()->IsWorkerGlobalScope()) {
WorkerGlobalScope* worker_global_scope =
DynamicTo<WorkerGlobalScope>(GetExecutionContext());
if (worker_global_scope->IsDedicatedWorkerGlobalScope() ||
worker_global_scope->IsSharedWorkerGlobalScope()) {
base::UmaHistogramBoolean("Storage.Blob.DataURLWorkerRegister",
worker_global_scope->Url().ProtocolIsData());
}
}

if (registrable->IsMojoBlob()) {
// Measure how much jank the following synchronous IPC introduces.
SCOPED_UMA_HISTOGRAM_TIMER("Storage.Blob.RegisterPublicURLTime");
Expand Down Expand Up @@ -143,6 +158,25 @@ void PublicURLManager::Resolve(
return;

DCHECK(url.ProtocolIs("blob"));

// Collect metrics on how frequently a worker context that makes use of the
// Blob URL API was created from a data URL. Note that we ignore service
// workers for this since they can't be created from data URLs.
if (GetExecutionContext()->IsWorkerGlobalScope()) {
WorkerGlobalScope* worker_global_scope =
DynamicTo<WorkerGlobalScope>(GetExecutionContext());
// Note that for module workers created from blob URLs, this gets called
// before the worker global scope has been initialized. Thus, no valid URL
// is available.
if (worker_global_scope->IsUrlValid() &&
(worker_global_scope->IsDedicatedWorkerGlobalScope() ||
worker_global_scope->IsSharedWorkerGlobalScope())) {
base::UmaHistogramBoolean(
"Storage.Blob.DataURLWorkerResolveAsURLLoaderFactory",
worker_global_scope->Url().ProtocolIsData());
}
}

url_store_->ResolveAsURLLoaderFactory(
url, std::move(factory_receiver),
WTF::Bind(
Expand Down Expand Up @@ -198,6 +232,24 @@ void PublicURLManager::Resolve(
return;

DCHECK(url.ProtocolIs("blob"));

// Collect metrics on how frequently a worker context that makes use of the
// Blob URL API was created from a data URL. Note that we ignore service
// workers for this since they can't be created from data URLs.
if (GetExecutionContext()->IsWorkerGlobalScope()) {
WorkerGlobalScope* worker_global_scope =
DynamicTo<WorkerGlobalScope>(GetExecutionContext());
// Note that the URL validity check here is not known to be needed but
// adding it just in case!
if (worker_global_scope->IsUrlValid() &&
(worker_global_scope->IsDedicatedWorkerGlobalScope() ||
worker_global_scope->IsSharedWorkerGlobalScope())) {
base::UmaHistogramBoolean(
"Storage.Blob.DataURLWorkerResolveForNavigation",
worker_global_scope->Url().ProtocolIsData());
}
}

url_store_->ResolveForNavigation(
url, std::move(token_receiver),
WTF::Bind(
Expand Down
33 changes: 33 additions & 0 deletions tools/metrics/histograms/metadata/storage/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,39 @@ chromium-metrics-reviews@google.com.
</summary>
</histogram>

<histogram name="Storage.Blob.DataURLWorkerRegister" enum="Boolean"
expires_after="M106">
<owner>awillia@chromium.org</owner>
<owner>ayui@chromium.org</owner>
<summary>
Recorded when the PublicURLManager::Register method is called from a worker
execution context (excluding service worker contexts). The value indicates
if the worker was created from a data URL.
</summary>
</histogram>

<histogram name="Storage.Blob.DataURLWorkerResolveAsURLLoaderFactory"
enum="Boolean" expires_after="M106">
<owner>awillia@chromium.org</owner>
<owner>ayui@chromium.org</owner>
<summary>
Recorded when the PublicURLManager::Resolve URLLoaderFactory method is
called from a worker execution context (excluding service worker contexts).
The value indicates if the worker was created from a data URL.
</summary>
</histogram>

<histogram name="Storage.Blob.DataURLWorkerResolveForNavigation" enum="Boolean"
expires_after="M106">
<owner>awillia@chromium.org</owner>
<owner>ayui@chromium.org</owner>
<summary>
Recorded when the PublicURLManager::Resolve method for navigations is called
from a worker execution context (excluding service worker contexts). The
value indicates if the worker was created from a data URL.
</summary>
</histogram>

<histogram name="Storage.Blob.FileReaderLoader.FailureType"
enum="FileReaderLoaderFailureType" expires_after="M95">
<owner>mek@chromium.org</owner>
Expand Down

0 comments on commit f3701f4

Please sign in to comment.