Skip to content

Commit

Permalink
[PageZoom] Add UKM for new zoom value on slider dismissal
Browse files Browse the repository at this point in the history
This CL adds logging for UKM at the same point when existing UMA
is logged: at dismissal of the Page Zoom slider if the user
changed the slider value before dismissal.

See UKM Collection in the Privacy Considerations section at
go/clank-page-zoom-design for doc and UKM request.

Bug: 1232536
Fixed: 1402526
Change-Id: I431d0a05efc1f841650340503f6a3c274eb75307
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4094081
Reviewed-by: Robert Kaplow <rkaplow@chromium.org>
Reviewed-by: Mark Schillaci <mschillaci@google.com>
Commit-Queue: Amanda Lin Dietz <aldietz@google.com>
Cr-Commit-Position: refs/heads/main@{#1085286}
  • Loading branch information
aldietz authored and Chromium LUCI CQ committed Dec 20, 2022
1 parent 5a60d50 commit 3d3d5d0
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 1 deletion.
1 change: 1 addition & 0 deletions components/browser_ui/accessibility/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ include_rules = [
"+components/user_prefs",
"+content/public/android/java",
"+content/public/browser",
"+services/metrics/public/cpp",
"+ui/android",
]
9 changes: 8 additions & 1 deletion components/browser_ui/accessibility/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@
import("//build/config/android/rules.gni")

generate_jni("accessibility_jni_headers") {
sources = [ "java/src/org/chromium/components/browser_ui/accessibility/FontSizePrefs.java" ]
sources = [
"java/src/org/chromium/components/browser_ui/accessibility/FontSizePrefs.java",
"java/src/org/chromium/components/browser_ui/accessibility/PageZoomMetrics.java",
]
}

source_set("android") {
sources = [
"font_size_prefs_android.cc",
"font_size_prefs_android.h",
"page_zoom_metrics.cc",
"page_zoom_metrics.h",
]
deps = [
":accessibility_jni_headers",
"//base",
"//components/prefs",
"//components/user_prefs",
"//content/public/browser",
"//services/metrics/public/cpp:ukm_builders",
]
}

Expand All @@ -34,6 +40,7 @@ android_library("java") {
"java/src/org/chromium/components/browser_ui/accessibility/FontSizePrefs.java",
"java/src/org/chromium/components/browser_ui/accessibility/PageZoomCoordinator.java",
"java/src/org/chromium/components/browser_ui/accessibility/PageZoomMediator.java",
"java/src/org/chromium/components/browser_ui/accessibility/PageZoomMetrics.java",
"java/src/org/chromium/components/browser_ui/accessibility/PageZoomPreference.java",
"java/src/org/chromium/components/browser_ui/accessibility/PageZoomProperties.java",
"java/src/org/chromium/components/browser_ui/accessibility/PageZoomUma.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public void hide() {
// Ensure that the user has set a zoom value during this session.
double zoomValue = mMediator.latestZoomValue();
if (zoomValue != 0.0) {
mMediator.logZoomLevelUKM(zoomValue);
PageZoomUma.logAppMenuSliderZoomLevelChangedHistogram();
PageZoomUma.logAppMenuSliderZoomLevelValueHistogram(zoomValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ protected double latestZoomValue() {
return mLatestZoomValue;
}

/**
* Log UKM for the user changing the zoom level on the page from the slider.
*/
protected void logZoomLevelUKM(double value) {
PageZoomMetrics.logZoomLevelUKM(mWebContents, value);
}

@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
void handleDecreaseClicked(Void unused) {
// When decreasing zoom, "snap" to the greatest preset value that is less than the current.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.components.browser_ui.accessibility;

import androidx.annotation.NonNull;

import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.content_public.browser.WebContents;

/**
* Centralizes metrics data collection for Page Zoom.
*/
@JNINamespace("browser_ui")
public class PageZoomMetrics {
/**
* Log new zoom level UKM for the given web contents.
* Recorded on slider dismissal if the user chose a new value.
* @param webContents WebContents for which to log value
* @param newZoomLevel double - new zoom level
*/
public static void logZoomLevelUKM(@NonNull WebContents webContents, double newZoomLevel) {
PageZoomMetricsJni.get().logZoomLevelUKM(webContents, newZoomLevel);
}

@NativeMethods
public interface Natives {
void logZoomLevelUKM(WebContents webContents, double value);
}
}
35 changes: 35 additions & 0 deletions components/browser_ui/accessibility/android/page_zoom_metrics.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/browser_ui/accessibility/android/page_zoom_metrics.h"

#include "base/android/scoped_java_ref.h"
#include "components/browser_ui/accessibility/android/accessibility_jni_headers/PageZoomMetrics_jni.h"
#include "content/public/browser/web_contents.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_source_id.h"

namespace browser_ui {

using base::android::JavaParamRef;
using base::android::JavaRef;

void JNI_PageZoomMetrics_LogZoomLevelUKM(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& j_web_contents,
jdouble newZoomLevel) {
content::WebContents* web_contents =
content::WebContents::FromJavaWebContents(j_web_contents);
DCHECK(web_contents);

ukm::SourceId ukm_source_id =
web_contents->GetPrimaryMainFrame()->GetPageUkmSourceId();

ukm::builders::Accessibility_PageZoom(ukm_source_id)
.SetSliderZoomValue((int)round(100 * newZoomLevel))
.Record(ukm::UkmRecorder::Get());
}

} // namespace browser_ui
28 changes: 28 additions & 0 deletions components/browser_ui/accessibility/android/page_zoom_metrics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_BROWSER_UI_ACCESSIBILITY_ANDROID_PAGE_ZOOM_METRICS_H_
#define COMPONENTS_BROWSER_UI_ACCESSIBILITY_ANDROID_PAGE_ZOOM_METRICS_H_

namespace content {
class WebContents;
}

namespace browser_ui {

/*
* Native component to log metrics for Page Zoom.
*/
class PageZoomMetrics {
public:
PageZoomMetrics();
~PageZoomMetrics();

// Logs UKM with the current zoom level for the specified WebContents.
void LogZoomLevelUKM(content::WebContents* web_contents, double newZoomLevel);
};

} // namespace browser_ui

#endif // COMPONENTS_BROWSER_UI_ACCESSIBILITY_ANDROID_PAGE_ZOOM_METRICS_H_
25 changes: 25 additions & 0 deletions tools/metrics/ukm/ukm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,31 @@ be describing additional metrics about the same event.
</metric>
</event>

<event name="Accessibility.PageZoom">
<owner>aldietz@google.com</owner>
<owner>mschillaci@google.com</owner>
<owner>chrome-a11y-core@google.com</owner>
<summary>
Tracks usage of Page Zoom on Chrome for Android. Recorded each time the
slider is dismissed if the user changed the zoom level on this page before
dismissal.
</summary>
<metric name="SliderZoomValue">
<summary>
For users who changed the individual zoom level on this page, tracks what
zoom level has been set on the page at slider dismissal. There may be
multiple instances where the slider is opened on the same page, so there
may be multiple values logged per page. The value will be an integer
between 25 and 500, inclusive.
</summary>
<aggregation>
<history>
<statistics/>
</history>
</aggregation>
</metric>
</event>

<event name="Accessibility.Renderer">
<owner>aleventhal@chromium.org</owner>
<owner>nektar@chromium.org</owner>
Expand Down

0 comments on commit 3d3d5d0

Please sign in to comment.