Commit d7e5694e authored by Wenjie Shi's avatar Wenjie Shi Committed by Commit Bot

Update WinRT sensor activation histogram to be on par with Win32 path

This CL modifies the Sensors.Windows.WinRT.Activation.Result to log
HRESULT_FROM_WIN32(ERROR_NOT_FOUND) when the sensor does not
exist on this system. This brings the histogram on parity with the Win32
flavor.

Bug: 958266
Change-Id: I6406c9ef3335d7d892ba8afaaa1b1848a6461ee2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1919570Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Wenjie Shi <wensh@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#715855}
parent 6c3ad8f9
...@@ -172,8 +172,8 @@ bool PlatformSensorReaderWinrtBase< ...@@ -172,8 +172,8 @@ bool PlatformSensorReaderWinrtBase<
} }
hr = sensor_statics->GetDefault(&sensor_); hr = sensor_statics->GetDefault(&sensor_);
base::UmaHistogramSparse("Sensors.Windows.WinRT.Activation.Result", hr);
if (FAILED(hr)) { if (FAILED(hr)) {
base::UmaHistogramSparse("Sensors.Windows.WinRT.Activation.Result", hr);
DLOG(ERROR) << "Failed to query default sensor: " DLOG(ERROR) << "Failed to query default sensor: "
<< logging::SystemErrorCodeToString(hr); << logging::SystemErrorCodeToString(hr);
return false; return false;
...@@ -181,10 +181,17 @@ bool PlatformSensorReaderWinrtBase< ...@@ -181,10 +181,17 @@ bool PlatformSensorReaderWinrtBase<
// GetDefault() returns null if the sensor does not exist // GetDefault() returns null if the sensor does not exist
if (!sensor_) { if (!sensor_) {
// https://docs.microsoft.com/en-us/windows/win32/api/sensorsapi/nf-sensorsapi-isensormanager-getsensorsbytype
// The Win32 flavor returns HRESULT_FROM_WIN32(ERROR_NOT_FOUND) when the
// sensor is not found so log the same error result here as well.
base::UmaHistogramSparse("Sensors.Windows.WinRT.Activation.Result",
HRESULT_FROM_WIN32(ERROR_NOT_FOUND));
VLOG(1) << "Sensor does not exist on system"; VLOG(1) << "Sensor does not exist on system";
return false; return false;
} }
base::UmaHistogramSparse("Sensors.Windows.WinRT.Activation.Result", S_OK);
minimum_report_interval_ = GetMinimumReportIntervalFromSensor(); minimum_report_interval_ = GetMinimumReportIntervalFromSensor();
if (minimum_report_interval_.is_zero()) if (minimum_report_interval_.is_zero())
......
...@@ -1748,6 +1748,16 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckSensorActivationHistogram) { ...@@ -1748,6 +1748,16 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckSensorActivationHistogram) {
"Sensors.Windows.WinRT.Activation.Result", S_OK), "Sensors.Windows.WinRT.Activation.Result", S_OK),
1); 1);
// Trigger HRESULT_FROM_WIN32(ERROR_NOT_FOUND) which happens when the sensor
// does not exist
fake_sensor_factory->fake_sensor_ = nullptr;
EXPECT_EQ(sensor->Initialize(), false);
EXPECT_EQ(
histogram_tester.GetBucketCount("Sensors.Windows.WinRT.Activation.Result",
HRESULT_FROM_WIN32(ERROR_NOT_FOUND)),
1);
// Trigger E_ACCESSDENIED twice // Trigger E_ACCESSDENIED twice
fake_sensor_factory->SetGetDefaultReturnCode(E_ACCESSDENIED); fake_sensor_factory->SetGetDefaultReturnCode(E_ACCESSDENIED);
EXPECT_FALSE(sensor->Initialize()); EXPECT_FALSE(sensor->Initialize());
...@@ -1763,7 +1773,7 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckSensorActivationHistogram) { ...@@ -1763,7 +1773,7 @@ TEST_F(PlatformSensorReaderTestWinrt, CheckSensorActivationHistogram) {
2); 2);
histogram_tester.ExpectTotalCount("Sensors.Windows.WinRT.Activation.Result", histogram_tester.ExpectTotalCount("Sensors.Windows.WinRT.Activation.Result",
3); 4);
} }
// Tests the sensor start histogram tracks sensor start return codes // Tests the sensor start histogram tracks sensor start return codes
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment