Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(504)

Unified Diff: ui/display/win/dpi.cc

Issue 2151413002: Add a UMA histogram for a user's device scale at startup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move metric to dpi.cc Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/metrics/histograms/histograms.xml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/display/win/dpi.cc
diff --git a/ui/display/win/dpi.cc b/ui/display/win/dpi.cc
index 778d83b0d468dc2cd082e98831514f6fe6b3ddb1..60805d066825beda5d8186737556dd5f3cb9aca4 100644
--- a/ui/display/win/dpi.cc
+++ b/ui/display/win/dpi.cc
@@ -4,8 +4,12 @@
#include "ui/display/win/dpi.h"
+#include <algorithm>
+
#include <windows.h>
+#include "base/metrics/histogram.h"
Ilya Sherman 2016/07/16 01:31:24 nit: You shouldn't need this include -- just the s
Bret 2016/07/18 17:41:48 Done.
+#include "base/metrics/sparse_histogram.h"
#include "base/win/scoped_hdc.h"
#include "ui/display/display.h"
@@ -18,6 +22,8 @@ const float kDefaultDPI = 96.f;
float g_device_scale_factor = 0.f;
+void RecordDeviceScale();
+
gfx::Size GetDPI() {
static int dpi_x = 0;
static int dpi_y = 0;
@@ -31,14 +37,22 @@ gfx::Size GetDPI() {
// to all screens.
dpi_x = GetDeviceCaps(screen_dc, LOGPIXELSX);
dpi_y = GetDeviceCaps(screen_dc, LOGPIXELSY);
+ RecordDeviceScale();
}
return gfx::Size(dpi_x, dpi_y);
}
float GetUnforcedDeviceScaleFactor() {
- return g_device_scale_factor
- ? g_device_scale_factor
- : GetScalingFactorFromDPI(GetDPI().width());
+ return g_device_scale_factor ? g_device_scale_factor
+ : GetScalingFactorFromDPI(GetDPI().width());
+}
+
+void RecordDeviceScale() {
+ // Clamp the reported value so that if it's wildly out-of-band we won't send
+ // it to the backend.
+ const int scale = std::min(
+ std::max(std::floor(GetUnforcedDeviceScaleFactor() * 100), 0.f), 1000.f);
Ilya Sherman 2016/07/16 01:31:24 nit: Somewhere, please add some explicit code to c
Bret 2016/07/18 17:41:48 Done.
+ UMA_HISTOGRAM_SPARSE_SLOWLY("UI.DeviceScale", scale);
}
} // namespace
« no previous file with comments | « tools/metrics/histograms/histograms.xml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698