Commit d9a11387 authored by Dylan Cutler's avatar Dylan Cutler Committed by Commit Bot

Instrument navigator.getGamepads() for identifiability study.

Bug: 973801
Change-Id: I96fcf532f33e80b246475a2ba8a806d5019a33b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2438199Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Reviewed-by: default avatarMatt Reynolds <mattreynolds@chromium.org>
Commit-Queue: Dylan Cutler <dylancutler@google.com>
Cr-Commit-Position: refs/heads/master@{#812262}
parent 498a5211
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include "base/auto_reset.h" #include "base/auto_reset.h"
#include "device/gamepad/public/cpp/gamepad_features.h" #include "device/gamepad/public/cpp/gamepad_features.h"
#include "device/gamepad/public/cpp/gamepads.h" #include "device/gamepad/public/cpp/gamepads.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/platform/task_type.h" #include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/renderer/core/dom/events/event.h" #include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
...@@ -41,6 +43,7 @@ ...@@ -41,6 +43,7 @@
#include "third_party/blink/renderer/modules/gamepad/gamepad_dispatcher.h" #include "third_party/blink/renderer/modules/gamepad/gamepad_dispatcher.h"
#include "third_party/blink/renderer/modules/gamepad/gamepad_event.h" #include "third_party/blink/renderer/modules/gamepad/gamepad_event.h"
#include "third_party/blink/renderer/modules/gamepad/gamepad_list.h" #include "third_party/blink/renderer/modules/gamepad/gamepad_list.h"
#include "third_party/blink/renderer/platform/privacy_budget/identifiability_digest_helpers.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h" #include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
namespace blink { namespace blink {
...@@ -76,6 +79,38 @@ NavigatorGamepad& NavigatorGamepad::From(Navigator& navigator) { ...@@ -76,6 +79,38 @@ NavigatorGamepad& NavigatorGamepad::From(Navigator& navigator) {
return *supplement; return *supplement;
} }
namespace {
void RecordGamepadsForIdentifiabilityStudy(ExecutionContext* context,
GamepadList* gamepads) {
if (!context || !IdentifiabilityStudySettings::Get()->IsSurfaceAllowed(
IdentifiableSurface::FromTypeAndToken(
IdentifiableSurface::Type::kWebFeature,
WebFeature::kGetGamepads)))
return;
IdentifiableTokenBuilder builder;
if (gamepads) {
for (unsigned i = 0; i < gamepads->length(); i++) {
if (auto* gp = gamepads->item(i)) {
builder.AddValue(gp->axes().size())
.AddValue(gp->buttons().size())
.AddValue(gp->connected())
.AddToken(IdentifiabilityBenignStringToken(gp->id()))
.AddToken(IdentifiabilityBenignStringToken(gp->mapping()))
.AddValue(gp->timestamp());
if (auto* vb = gp->vibrationActuator()) {
builder.AddToken(IdentifiabilityBenignStringToken(vb->type()));
}
}
}
}
IdentifiabilityMetricBuilder(context->UkmSourceID())
.SetWebfeature(WebFeature::kGetGamepads, builder.GetToken())
.Record(context->UkmRecorder());
}
} // namespace
// static // static
GamepadList* NavigatorGamepad::getGamepads(Navigator& navigator, GamepadList* NavigatorGamepad::getGamepads(Navigator& navigator,
ExceptionState& exception_state) { ExceptionState& exception_state) {
...@@ -83,7 +118,13 @@ GamepadList* NavigatorGamepad::getGamepads(Navigator& navigator, ...@@ -83,7 +118,13 @@ GamepadList* NavigatorGamepad::getGamepads(Navigator& navigator,
// Using an existing NavigatorGamepad if one exists, but don't create one // Using an existing NavigatorGamepad if one exists, but don't create one
// for a detached window, as its subclasses depend on a non-null window. // for a detached window, as its subclasses depend on a non-null window.
auto* gamepad = Supplement<Navigator>::From<NavigatorGamepad>(navigator); auto* gamepad = Supplement<Navigator>::From<NavigatorGamepad>(navigator);
return gamepad ? gamepad->Gamepads() : nullptr; if (gamepad) {
auto* result = gamepad->Gamepads();
RecordGamepadsForIdentifiabilityStudy(gamepad->GetExecutionContext(),
result);
return result;
}
return nullptr;
} }
auto* navigator_gamepad = &NavigatorGamepad::From(navigator); auto* navigator_gamepad = &NavigatorGamepad::From(navigator);
...@@ -124,7 +165,9 @@ GamepadList* NavigatorGamepad::getGamepads(Navigator& navigator, ...@@ -124,7 +165,9 @@ GamepadList* NavigatorGamepad::getGamepads(Navigator& navigator,
} }
} }
return NavigatorGamepad::From(navigator).Gamepads(); auto* result = NavigatorGamepad::From(navigator).Gamepads();
RecordGamepadsForIdentifiabilityStudy(context, result);
return result;
} }
GamepadList* NavigatorGamepad::Gamepads() { GamepadList* NavigatorGamepad::Gamepads() {
......
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