Commit 47275743 authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

Log CoCreateInstance failures in //services/device/generic_sensor

The Generic Sensor implementation on Windows depends on certain COM
objects being registered on the system. To assist in debugging issues
with these being missing on (it is believed) Windows 10 N editions this
change adds one-time logging when CoCreateInstance fails.

Bug: 756986
Change-Id: I159b7b379a94caa6980d17b9e02a61209154eade
Reviewed-on: https://chromium-review.googlesource.com/923383
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Reviewed-by: default avatarConley Owens <cco3@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537429}
parent da8150a6
...@@ -4,8 +4,11 @@ ...@@ -4,8 +4,11 @@
#include "services/device/generic_sensor/platform_sensor_provider_win.h" #include "services/device/generic_sensor/platform_sensor_provider_win.h"
#include <comdef.h>
#include <objbase.h> #include <objbase.h>
#include <iomanip>
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "base/task_runner_util.h" #include "base/task_runner_util.h"
...@@ -33,8 +36,19 @@ class PlatformSensorProviderWin::SensorThread final : public base::Thread { ...@@ -33,8 +36,19 @@ class PlatformSensorProviderWin::SensorThread final : public base::Thread {
void Init() override { void Init() override {
if (sensor_manager_) if (sensor_manager_)
return; return;
::CoCreateInstance(CLSID_SensorManager, nullptr, CLSCTX_ALL, HRESULT hr = ::CoCreateInstance(CLSID_SensorManager, nullptr, CLSCTX_ALL,
IID_PPV_ARGS(&sensor_manager_)); IID_PPV_ARGS(&sensor_manager_));
if (FAILED(hr)) {
// Only log this error the first time.
static bool logged_failure = false;
if (!logged_failure) {
LOG(ERROR) << "Unable to create instance of SensorManager: "
<< _com_error(hr).ErrorMessage() << " (0x " << std::hex
<< std::uppercase << std::setfill('0') << std::setw(8) << hr
<< ")";
logged_failure = true;
}
}
} }
void CleanUp() override { sensor_manager_.Reset(); } void CleanUp() override { sensor_manager_.Reset(); }
......
...@@ -5,8 +5,11 @@ ...@@ -5,8 +5,11 @@
#include "services/device/generic_sensor/platform_sensor_reader_win.h" #include "services/device/generic_sensor/platform_sensor_reader_win.h"
#include <Sensors.h> #include <Sensors.h>
#include <comdef.h>
#include <objbase.h> #include <objbase.h>
#include <iomanip>
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
...@@ -454,21 +457,29 @@ void PlatformSensorReaderWin::ListenSensorEvent() { ...@@ -454,21 +457,29 @@ void PlatformSensorReaderWin::ListenSensorEvent() {
bool PlatformSensorReaderWin::SetReportingInterval( bool PlatformSensorReaderWin::SetReportingInterval(
const PlatformSensorConfiguration& configuration) { const PlatformSensorConfiguration& configuration) {
Microsoft::WRL::ComPtr<IPortableDeviceValues> props; Microsoft::WRL::ComPtr<IPortableDeviceValues> props;
if (SUCCEEDED(::CoCreateInstance(CLSID_PortableDeviceValues, nullptr, HRESULT hr = ::CoCreateInstance(CLSID_PortableDeviceValues, nullptr,
CLSCTX_ALL, IID_PPV_ARGS(&props)))) { CLSCTX_ALL, IID_PPV_ARGS(&props));
unsigned interval = if (FAILED(hr)) {
(1 / configuration.frequency()) * base::Time::kMillisecondsPerSecond; static bool logged_failure = false;
if (!logged_failure) {
HRESULT hr = props->SetUnsignedIntegerValue( LOG(ERROR) << "Unable to create instance of PortableDeviceValues: "
SENSOR_PROPERTY_CURRENT_REPORT_INTERVAL, interval); << _com_error(hr).ErrorMessage() << " (0x " << std::hex
<< std::uppercase << std::setfill('0') << std::setw(8) << hr
if (SUCCEEDED(hr)) { << ")";
Microsoft::WRL::ComPtr<IPortableDeviceValues> return_props; logged_failure = true;
hr = sensor_->SetProperties(props.Get(), return_props.GetAddressOf());
return SUCCEEDED(hr);
} }
} }
return false;
unsigned interval =
(1 / configuration.frequency()) * base::Time::kMillisecondsPerSecond;
hr = props->SetUnsignedIntegerValue(SENSOR_PROPERTY_CURRENT_REPORT_INTERVAL,
interval);
if (FAILED(hr))
return false;
Microsoft::WRL::ComPtr<IPortableDeviceValues> return_props;
hr = sensor_->SetProperties(props.Get(), return_props.GetAddressOf());
return SUCCEEDED(hr);
} }
HRESULT PlatformSensorReaderWin::SensorReadingChanged( HRESULT PlatformSensorReaderWin::SensorReadingChanged(
......
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