Bug 1923028 - Migrate scalars to use Glean APIs for a11.*, r=chutten.

Differential Revision: https://phabricator.services.mozilla.com/D225366
This commit is contained in:
Florian Quèze
2024-10-16 20:46:06 +00:00
parent 6dd20fd9b2
commit 1d371b8a8e
6 changed files with 178 additions and 25 deletions

View File

@@ -22,7 +22,7 @@
#include "nsAppShell.h"
#include "nsCocoaUtils.h"
#include "mozilla/EnumSet.h"
#include "mozilla/Telemetry.h"
#include "mozilla/glean/GleanMetrics.h"
// Available from 10.13 onwards; test availability at runtime before using
@interface NSWorkspace (AvailableSinceHighSierra)
@@ -326,9 +326,7 @@ uint64_t GetCacheDomainsForKnownClients(uint64_t aCacheDomains) {
const char* client = GetStringForClient(clientToLog);
#if defined(MOZ_TELEMETRY_REPORTING)
mozilla::Telemetry::ScalarSet(
mozilla::Telemetry::ScalarID::A11Y_INSTANTIATORS,
NS_ConvertASCIItoUTF16(client));
mozilla::glean::a11y::instantiators.Set(nsDependentCString(client));
#endif // defined(MOZ_TELEMETRY_REPORTING)
CrashReporter::RecordAnnotationCString(
CrashReporter::Annotation::AccessibilityClient, client);

156
accessible/metrics.yaml Normal file
View File

@@ -0,0 +1,156 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Adding a new metric? We have docs for that!
# https://firefox-source-docs.mozilla.org/toolkit/components/glean/user/new_definitions_file.html
---
$schema: moz://mozilla.org/schemas/glean/metrics/2-0-0
$tags:
- 'Core :: Disability Access APIs'
a11y:
always_underline_links:
type: boolean
description: >
Bool tracking if the user has always underline links enabled in
firefox.
This metric was generated to correspond to the Legacy Telemetry
scalar a11y.always_underline_links.
bugs:
- https://bugzil.la/1835194
data_reviews:
- https://bugzil.la/1835194
notification_emails:
- accessibility@mozilla.com
- mreschenberg@mozilla.com
expires: never
telemetry_mirror: A11Y_ALWAYS_UNDERLINE_LINKS
use_system_colors:
type: boolean
description: >
Bool tracking if the user has system colors enabled in firefox.
This metric was generated to correspond to the Legacy Telemetry
scalar a11y.use_system_colors.
bugs:
- https://bugzil.la/1835194
data_reviews:
- https://bugzil.la/1835194
notification_emails:
- accessibility@mozilla.com
- mreschenberg@mozilla.com
expires: never
telemetry_mirror: A11Y_USE_SYSTEM_COLORS
hcm_background:
type: quantity
description: >
Unsigned int tracking the user's prefered background color \ (logged
when HCM is enabled).
This metric was generated to correspond to the Legacy Telemetry
scalar a11y.HCM_background.
bugs:
- https://bugzil.la/1694717
data_reviews:
- https://bugzil.la/1694717
notification_emails:
- accessibility@mozilla.com
- mreschenberg@mozilla.com
expires: never
unit: nscolor
telemetry_mirror: A11Y_HCM_BACKGROUND
hcm_foreground:
type: quantity
description: >
Unsigned int tracking the user's prefered foreground color \ (logged
when HCM is enabled).
This metric was generated to correspond to the Legacy Telemetry
scalar a11y.HCM_foreground.
bugs:
- https://bugzil.la/1694717
data_reviews:
- https://bugzil.la/1694717
notification_emails:
- accessibility@mozilla.com
- mreschenberg@mozilla.com
expires: never
unit: nscolor
telemetry_mirror: A11Y_HCM_FOREGROUND
backplate:
type: boolean
description: >
Boolean tracking if the user has the backplate preference enabled or
disabled.
This metric was generated to correspond to the Legacy Telemetry
scalar a11y.backplate.
bugs:
- https://bugzil.la/1539212
data_reviews:
- https://bugzil.la/1539212
notification_emails:
- accessibility@mozilla.com
- mreschenberg@mozilla.com
expires: never
telemetry_mirror: A11Y_BACKPLATE
instantiators:
type: string
description: >
The leaf name and version number of the binary for the process
responsible for remotely instantiating a11y.
This metric was generated to correspond to the Legacy Telemetry
scalar a11y.instantiators.
bugs:
- https://bugzil.la/1323069
- https://bugzil.la/1462238
data_reviews:
- https://bugzil.la/1323069
- https://bugzil.la/1462238
notification_emails:
- accessibility@mozilla.com
- jteh@mozilla.com
expires: never
telemetry_mirror: A11Y_INSTANTIATORS
invert_colors:
type: boolean
description: >
Boolean tracking if the user has an invert colors OS setting
enabled.
This metric was generated to correspond to the Legacy Telemetry
scalar a11y.invert_colors.
bugs:
- https://bugzil.la/1794626
data_reviews:
- https://bugzil.la/1794626
notification_emails:
- accessibility@mozilla.com
- mreschenberg@mozilla.com
expires: never
telemetry_mirror: A11Y_INVERT_COLORS
theme:
type: labeled_boolean
description: >
OS high contrast or other accessibility theme is enabled. The result
is split into keys which represent the values of
browser.display.document_color_use: "default", "always", or "never".
This metric was generated to correspond to the Legacy Telemetry
scalar a11y.theme.
bugs:
- https://bugzil.la/1022528
data_reviews:
- https://bugzil.la/1022528
notification_emails:
- accessibility@mozilla.com
- eisaacson@mozilla.com
expires: never
labels:
- default
- always
- never
telemetry_mirror: A11Y_THEME

View File

@@ -22,7 +22,7 @@
#include <tuple>
#if defined(MOZ_TELEMETRY_REPORTING)
# include "mozilla/Telemetry.h"
# include "mozilla/glean/GleanMetrics.h"
#endif // defined(MOZ_TELEMETRY_REPORTING)
using namespace mozilla;
@@ -204,7 +204,7 @@ static void AccumulateInstantiatorTelemetry(const nsAString& aValue) {
if (!aValue.IsEmpty()) {
#if defined(MOZ_TELEMETRY_REPORTING)
Telemetry::ScalarSet(Telemetry::ScalarID::A11Y_INSTANTIATORS, aValue);
glean::a11y::instantiators.Set(NS_ConvertUTF16toUTF8(aValue));
#endif // defined(MOZ_TELEMETRY_REPORTING)
CrashReporter::RecordAnnotationNSString(
CrashReporter::Annotation::AccessibilityClient, aValue);

View File

@@ -14,7 +14,7 @@
#include "mozilla/StaticPrefs_layout.h"
#include "mozilla/StaticPrefs_widget.h"
#include "mozilla/StaticPrefs_ui.h"
#include "mozilla/Telemetry.h"
#include "mozilla/glean/GleanMetrics.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/ServoBindings.h"
#include "mozilla/dom/Document.h"
@@ -275,21 +275,21 @@ void PreferenceSheet::Initialize() {
return;
}
nsAutoString useDocumentColorPref;
glean::a11y::ThemeLabel gleanLabel;
switch (StaticPrefs::browser_display_document_color_use()) {
case 1:
useDocumentColorPref.AssignLiteral("always");
gleanLabel = glean::a11y::ThemeLabel::eAlways;
break;
case 2:
useDocumentColorPref.AssignLiteral("never");
gleanLabel = glean::a11y::ThemeLabel::eNever;
break;
default:
useDocumentColorPref.AssignLiteral("default");
gleanLabel = glean::a11y::ThemeLabel::eDefault;
break;
}
Telemetry::ScalarSet(Telemetry::ScalarID::A11Y_THEME, useDocumentColorPref,
sContentPrefs.mUseAccessibilityTheme);
glean::a11y::theme.EnumGet(gleanLabel)
.Set(sContentPrefs.mUseAccessibilityTheme);
if (!sContentPrefs.mUseDocumentColors) {
// If a user has chosen to override doc colors through OS HCM or our HCM,
// we should log the user's current foreground (text) color and background
@@ -304,18 +304,16 @@ void PreferenceSheet::Initialize() {
// theme color/background (if we're using system colors and the user is
// using a High Contrast theme), and also the colors that as of today we
// allow setting in about:preferences.
Telemetry::ScalarSet(Telemetry::ScalarID::A11Y_HCM_FOREGROUND,
sContentPrefs.mLightColors.mDefault);
Telemetry::ScalarSet(Telemetry::ScalarID::A11Y_HCM_BACKGROUND,
sContentPrefs.mLightColors.mDefaultBackground);
glean::a11y::hcm_foreground.Set(sContentPrefs.mLightColors.mDefault);
glean::a11y::hcm_background.Set(
sContentPrefs.mLightColors.mDefaultBackground);
}
Telemetry::ScalarSet(Telemetry::ScalarID::A11Y_BACKPLATE,
StaticPrefs::browser_display_permit_backplate());
Telemetry::ScalarSet(Telemetry::ScalarID::A11Y_USE_SYSTEM_COLORS,
StaticPrefs::browser_display_use_system_colors());
Telemetry::ScalarSet(Telemetry::ScalarID::A11Y_ALWAYS_UNDERLINE_LINKS,
StaticPrefs::layout_css_always_underline_links());
glean::a11y::backplate.Set(StaticPrefs::browser_display_permit_backplate());
glean::a11y::use_system_colors.Set(
StaticPrefs::browser_display_use_system_colors());
glean::a11y::always_underline_links.Set(
StaticPrefs::layout_css_always_underline_links());
}
bool PreferenceSheet::AffectedByPref(const nsACString& aPref) {

View File

@@ -15,6 +15,7 @@
# (Firefox Desktop, Firefox for Android, Focus for Android, etc.).
# Order is lexicographical, enforced by t/c/glean/tests/pytest/test_yaml_indices.py
gecko_metrics = [
"accessible/metrics.yaml",
"browser/base/content/metrics.yaml",
"devtools/client/shared/metrics.yaml",
"docshell/base/metrics.yaml",

View File

@@ -16,7 +16,7 @@
#include "mozilla/FontPropertyTypes.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/StaticPrefs_widget.h"
#include "mozilla/Telemetry.h"
#include "mozilla/glean/GleanMetrics.h"
#include "mozilla/widget/WidgetMessageUtils.h"
#include "mozilla/MacStringHelpers.h"
@@ -579,7 +579,7 @@ void nsLookAndFeel::RecordAccessibilityTelemetry() {
(accessibilityDisplayShouldInvertColors)]) {
bool val =
[[NSWorkspace sharedWorkspace] accessibilityDisplayShouldInvertColors];
Telemetry::ScalarSet(Telemetry::ScalarID::A11Y_INVERT_COLORS, val);
glean::a11y::invert_colors.Set(val);
}
}