Chromium Code Reviews| 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 |