-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reland "[PageZoom] Add UKM for new zoom value on slider dismissal"
This is a reland of commit 3d3d5d0 This reland has been updated to include bucketing in intervals of 5 for the zoom value and a unit test. See go/clank-page-zoom-design for the feature design document and UKM request, as well as approval from chrome-privacy-core. Original change's description: > [PageZoom] Add UKM for new zoom value on slider dismissal > > 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} (cherry picked from commit 60d1bf2) Bug: 1232536, 1402526 Change-Id: I55054d0ebbfd1085de7ed939fa528d892a352543 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4118930 Reviewed-by: Yue Ru Sun <yrsun@chromium.org> Reviewed-by: Theresa Sullivan <twellington@chromium.org> Auto-Submit: Amanda Lin Dietz <aldietz@google.com> Commit-Queue: Amanda Lin Dietz <aldietz@google.com> Reviewed-by: Alexei Svitkine <asvitkine@chromium.org> Cr-Original-Commit-Position: refs/heads/main@{#1091057} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4163259 Reviewed-by: Mark Schillaci <mschillaci@google.com> Commit-Queue: Mark Schillaci <mschillaci@google.com> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Cr-Commit-Position: refs/branch-heads/5481@{#248} Cr-Branched-From: 130f3e4-refs/heads/main@{#1084008}
- Loading branch information
Showing
10 changed files
with
213 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
include_rules = [ | ||
"+components/prefs", | ||
"+components/ukm", | ||
"+components/user_prefs", | ||
"+content/public/android/java", | ||
"+content/public/browser", | ||
"+services/metrics/public/cpp", | ||
"+ui/android", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...ty/android/java/src/org/chromium/components/browser_ui/accessibility/PageZoomMetrics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2023 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 { | ||
/** | ||
* Logs 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); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
components/browser_ui/accessibility/android/page_zoom_metrics.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2023 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" | ||
|
||
using base::android::JavaParamRef; | ||
using base::android::JavaRef; | ||
|
||
namespace { | ||
int ValueToStep(double value) { | ||
return (static_cast<int>(round(100 * value)) / 5) * 5; | ||
} | ||
} // namespace | ||
|
||
namespace browser_ui { | ||
|
||
void JNI_PageZoomMetrics_LogZoomLevelUKM( | ||
JNIEnv* env, | ||
const base::android::JavaParamRef<jobject>& j_web_contents, | ||
jdouble new_zoom_level) { | ||
content::WebContents* web_contents = | ||
content::WebContents::FromJavaWebContents(j_web_contents); | ||
DCHECK(web_contents); | ||
|
||
ukm::SourceId ukm_source_id = | ||
web_contents->GetPrimaryMainFrame()->GetPageUkmSourceId(); | ||
|
||
PageZoomMetrics::LogZoomLevelUKMHelper(ukm_source_id, new_zoom_level, | ||
ukm::UkmRecorder::Get()); | ||
} | ||
|
||
// static | ||
void PageZoomMetrics::LogZoomLevelUKMHelper(ukm::SourceId ukm_source_id, | ||
double new_zoom_level, | ||
ukm::UkmRecorder* ukm_recorder) { | ||
ukm::builders::Accessibility_PageZoom(ukm_source_id) | ||
.SetSliderZoomValue(ValueToStep(new_zoom_level)) | ||
.Record(ukm_recorder); | ||
} | ||
|
||
} // namespace browser_ui |
37 changes: 37 additions & 0 deletions
37
components/browser_ui/accessibility/android/page_zoom_metrics.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2023 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_ | ||
|
||
#include "services/metrics/public/cpp/ukm_recorder.h" | ||
#include "services/metrics/public/cpp/ukm_source_id.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 new_zoom_level); | ||
|
||
// Helper function for UKM logging | ||
static void LogZoomLevelUKMHelper(ukm::SourceId ukm_source_id, | ||
double new_zoom_level, | ||
ukm::UkmRecorder* ukm_recorder); | ||
}; | ||
|
||
} // namespace browser_ui | ||
|
||
#endif // COMPONENTS_BROWSER_UI_ACCESSIBILITY_ANDROID_PAGE_ZOOM_METRICS_H_ |
41 changes: 41 additions & 0 deletions
41
components/browser_ui/accessibility/android/page_zoom_metrics_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2023 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 "components/ukm/test_ukm_recorder.h" | ||
#include "services/metrics/public/cpp/ukm_builders.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
namespace browser_ui { | ||
|
||
TEST(PageZoomMetricsTest, PageZoomUkmExactValue) { | ||
ukm::TestUkmRecorder test_recorder; | ||
ukm::SourceId mock_source_id = test_recorder.GetNewSourceID(); | ||
|
||
PageZoomMetrics::LogZoomLevelUKMHelper(mock_source_id, 0.75, &test_recorder); | ||
|
||
base::StringPiece expectedMetricName = "SliderZoomValue"; | ||
|
||
auto entries = test_recorder.GetEntriesByName( | ||
ukm::builders::Accessibility_PageZoom::kEntryName); | ||
ASSERT_EQ(entries.size(), 1u); | ||
test_recorder.ExpectEntryMetric(entries.front(), expectedMetricName, 75); | ||
} | ||
|
||
TEST(PageZoomMetricsTest, PageZoomUkmBucket) { | ||
ukm::TestUkmRecorder test_recorder; | ||
ukm::SourceId mock_source_id = test_recorder.GetNewSourceID(); | ||
|
||
PageZoomMetrics::LogZoomLevelUKMHelper(mock_source_id, 0.78, &test_recorder); | ||
|
||
base::StringPiece expectedMetricName = "SliderZoomValue"; | ||
|
||
auto entries = test_recorder.GetEntriesByName( | ||
ukm::builders::Accessibility_PageZoom::kEntryName); | ||
ASSERT_EQ(entries.size(), 1u); | ||
test_recorder.ExpectEntryMetric(entries.front(), expectedMetricName, 75); | ||
} | ||
|
||
} // namespace browser_ui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters