Commit 2f5624c2 authored by cfredric's avatar cfredric Committed by Commit Bot

Instrument calls to GPU.requestAdapter.

This will be used to analyze how much entropy leaked by this API can be
used for cross-site tracking.

Bug: 973801
Change-Id: I3741e7bf887e0d7b07b203531afac230ca7dcf70
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2441324Reviewed-by: default avatarCorentin Wallez <cwallez@chromium.org>
Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Commit-Queue: Asanka Herath <asanka@chromium.org>
Auto-Submit: Chris Fredrickson <cfredric@google.com>
Cr-Commit-Position: refs/heads/master@{#812862}
parent 8b726d9d
...@@ -184,6 +184,9 @@ class IdentifiableSurface { ...@@ -184,6 +184,9 @@ class IdentifiableSurface {
// will key this type on a digest of both the enums' values. // will key this type on a digest of both the enums' values.
kWebGLShaderPrecisionFormat = 16, kWebGLShaderPrecisionFormat = 16,
// Represents a call to GPU.requestAdapter. Input is the options filter.
kGPU_RequestAdapter = 20,
// We can use values up to and including |kMax|. // We can use values up to and including |kMax|.
kMax = (1 << kTypeBits) - 1 kMax = (1 << kTypeBits) - 1
}; };
......
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include <utility> #include <utility>
#include "gpu/command_buffer/client/webgpu_interface.h" #include "gpu/command_buffer/client/webgpu_interface.h"
#include "third_party/blink/public/common/privacy_budget/identifiability_metric_builder.h"
#include "third_party/blink/public/common/privacy_budget/identifiability_study_settings.h"
#include "third_party/blink/public/common/privacy_budget/identifiable_token_builder.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_graphics_context_3d_provider.h" #include "third_party/blink/public/platform/web_graphics_context_3d_provider.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
...@@ -17,6 +20,7 @@ ...@@ -17,6 +20,7 @@
#include "third_party/blink/renderer/modules/webgpu/gpu_adapter.h" #include "third_party/blink/renderer/modules/webgpu/gpu_adapter.h"
#include "third_party/blink/renderer/platform/graphics/gpu/dawn_control_client_holder.h" #include "third_party/blink/renderer/platform/graphics/gpu/dawn_control_client_holder.h"
#include "third_party/blink/renderer/platform/heap/heap.h" #include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/privacy_budget/identifiability_digest_helpers.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"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h" #include "third_party/blink/renderer/platform/scheduler/public/thread.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h" #include "third_party/blink/renderer/platform/weborigin/kurl.h"
...@@ -98,7 +102,9 @@ void GPU::ContextDestroyed() { ...@@ -98,7 +102,9 @@ void GPU::ContextDestroyed() {
dawn_control_client_->Destroy(); dawn_control_client_->Destroy();
} }
void GPU::OnRequestAdapterCallback(ScriptPromiseResolver* resolver, void GPU::OnRequestAdapterCallback(ScriptState* script_state,
const GPURequestAdapterOptions* options,
ScriptPromiseResolver* resolver,
int32_t adapter_server_id, int32_t adapter_server_id,
const WGPUDeviceProperties& properties) { const WGPUDeviceProperties& properties) {
GPUAdapter* adapter = nullptr; GPUAdapter* adapter = nullptr;
...@@ -106,9 +112,43 @@ void GPU::OnRequestAdapterCallback(ScriptPromiseResolver* resolver, ...@@ -106,9 +112,43 @@ void GPU::OnRequestAdapterCallback(ScriptPromiseResolver* resolver,
adapter = MakeGarbageCollected<GPUAdapter>( adapter = MakeGarbageCollected<GPUAdapter>(
"Default", adapter_server_id, properties, dawn_control_client_); "Default", adapter_server_id, properties, dawn_control_client_);
} }
RecordAdapterForIdentifiability(script_state, options, adapter);
resolver->Resolve(adapter); resolver->Resolve(adapter);
} }
void GPU::RecordAdapterForIdentifiability(
ScriptState* script_state,
const GPURequestAdapterOptions* options,
GPUAdapter* adapter) const {
constexpr IdentifiableSurface::Type type =
IdentifiableSurface::Type::kGPU_RequestAdapter;
if (!IdentifiabilityStudySettings::Get()->IsTypeAllowed(type))
return;
ExecutionContext* context = GetExecutionContext();
if (!context)
return;
IdentifiableTokenBuilder input_builder;
if (options && options->hasPowerPreference()) {
input_builder.AddToken(
IdentifiabilityBenignStringToken(options->powerPreference()));
}
const auto surface =
IdentifiableSurface::FromTypeAndToken(type, input_builder.GetToken());
IdentifiableTokenBuilder output_builder;
if (adapter) {
output_builder.AddToken(IdentifiabilityBenignStringToken(adapter->name()));
for (const auto& extension : adapter->extensions(script_state)) {
output_builder.AddToken(IdentifiabilityBenignStringToken(extension));
}
}
IdentifiabilityMetricBuilder(context->UkmSourceID())
.Set(surface, output_builder.GetToken())
.Record(context->UkmRecorder());
}
ScriptPromise GPU::requestAdapter(ScriptState* script_state, ScriptPromise GPU::requestAdapter(ScriptState* script_state,
const GPURequestAdapterOptions* options) { const GPURequestAdapterOptions* options) {
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state); auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
...@@ -148,6 +188,7 @@ ScriptPromise GPU::requestAdapter(ScriptState* script_state, ...@@ -148,6 +188,7 @@ ScriptPromise GPU::requestAdapter(ScriptState* script_state,
if (!dawn_control_client_->GetInterface()->RequestAdapterAsync( if (!dawn_control_client_->GetInterface()->RequestAdapterAsync(
power_preference, power_preference,
WTF::Bind(&GPU::OnRequestAdapterCallback, WrapPersistent(this), WTF::Bind(&GPU::OnRequestAdapterCallback, WrapPersistent(this),
WrapPersistent(script_state), WrapPersistent(options),
WrapPersistent(resolver)))) { WrapPersistent(resolver)))) {
resolver->Reject(MakeGarbageCollected<DOMException>( resolver->Reject(MakeGarbageCollected<DOMException>(
DOMExceptionCode::kOperationError, "Fail to request GPUAdapter")); DOMExceptionCode::kOperationError, "Fail to request GPUAdapter"));
......
...@@ -15,6 +15,7 @@ struct WGPUDeviceProperties; ...@@ -15,6 +15,7 @@ struct WGPUDeviceProperties;
namespace blink { namespace blink {
class GPUAdapter;
class GPURequestAdapterOptions; class GPURequestAdapterOptions;
class ScriptPromiseResolver; class ScriptPromiseResolver;
class ScriptState; class ScriptState;
...@@ -40,10 +41,16 @@ class GPU final : public ScriptWrappable, ...@@ -40,10 +41,16 @@ class GPU final : public ScriptWrappable,
const GPURequestAdapterOptions* options); const GPURequestAdapterOptions* options);
private: private:
void OnRequestAdapterCallback(ScriptPromiseResolver* resolver, void OnRequestAdapterCallback(ScriptState* script_state,
const GPURequestAdapterOptions* options,
ScriptPromiseResolver* resolver,
int32_t adapter_server_id, int32_t adapter_server_id,
const WGPUDeviceProperties& properties); const WGPUDeviceProperties& properties);
void RecordAdapterForIdentifiability(ScriptState* script_state,
const GPURequestAdapterOptions* options,
GPUAdapter* adapter) const;
scoped_refptr<DawnControlClientHolder> dawn_control_client_; scoped_refptr<DawnControlClientHolder> dawn_control_client_;
DISALLOW_COPY_AND_ASSIGN(GPU); DISALLOW_COPY_AND_ASSIGN(GPU);
......
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