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

Unified Diff: device/generic_sensor/platform_sensor_reader_win.cc

Issue 2495073002: [sensors] [win] Fix ambient light not working properly Windows 10. (Closed)
Patch Set: Fix typo Created 4 years, 1 month 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 | « device/generic_sensor/platform_sensor_reader_win.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/generic_sensor/platform_sensor_reader_win.cc
diff --git a/device/generic_sensor/platform_sensor_reader_win.cc b/device/generic_sensor/platform_sensor_reader_win.cc
index bbcdcc59492a31cb9edf1ba4e1e1609d534f4166..9cacb63f4f915da6ff33d733a576fbecaf334109 100644
--- a/device/generic_sensor/platform_sensor_reader_win.cc
+++ b/device/generic_sensor/platform_sensor_reader_win.cc
@@ -344,7 +344,8 @@ PlatformSensorReaderWin::PlatformSensorReaderWin(
sensor_active_(false),
client_(nullptr),
sensor_(sensor),
- event_listener_(new EventListener(this)) {
+ event_listener_(new EventListener(this)),
+ weak_factory_(this) {
DCHECK(init_params_);
DCHECK(!init_params_->reader_func.is_null());
DCHECK(sensor_);
@@ -375,24 +376,24 @@ bool PlatformSensorReaderWin::StartSensor(
if (!SetReportingInterval(configuration))
return false;
- // Set event listener.
if (!sensor_active_) {
- base::win::ScopedComPtr<ISensorEvents> sensor_events;
- HRESULT hr = event_listener_->QueryInterface(__uuidof(ISensorEvents),
- sensor_events.ReceiveVoid());
-
- if (FAILED(hr) || !sensor_events)
- return false;
-
- if (FAILED(sensor_->SetEventSink(sensor_events.get())))
- return false;
-
+ task_runner_->PostTask(
+ FROM_HERE, base::Bind(&PlatformSensorReaderWin::ListenSensorEvent,
+ weak_factory_.GetWeakPtr()));
sensor_active_ = true;
}
return true;
}
+void PlatformSensorReaderWin::ListenSensorEvent() {
+ // Set event listener.
+ if (FAILED(sensor_->SetEventSink(event_listener_.get()))) {
+ SensorError();
+ StopSensor();
+ }
+}
+
bool PlatformSensorReaderWin::SetReportingInterval(
const PlatformSensorConfiguration& configuration) {
base::win::ScopedComPtr<IPortableDeviceValues> props;
« no previous file with comments | « device/generic_sensor/platform_sensor_reader_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698