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

Side by Side 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 Alex comments 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 unified diff | Download patch
« no previous file with comments | « device/generic_sensor/platform_sensor_reader_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/generic_sensor/platform_sensor_reader_win.h" 5 #include "device/generic_sensor/platform_sensor_reader_win.h"
6 6
7 #include <Sensors.h> 7 #include <Sensors.h>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 235 }
236 236
237 PlatformSensorReaderWin::PlatformSensorReaderWin( 237 PlatformSensorReaderWin::PlatformSensorReaderWin(
238 base::win::ScopedComPtr<ISensor> sensor, 238 base::win::ScopedComPtr<ISensor> sensor,
239 std::unique_ptr<ReaderInitParams> params) 239 std::unique_ptr<ReaderInitParams> params)
240 : init_params_(std::move(params)), 240 : init_params_(std::move(params)),
241 task_runner_(base::ThreadTaskRunnerHandle::Get()), 241 task_runner_(base::ThreadTaskRunnerHandle::Get()),
242 sensor_active_(false), 242 sensor_active_(false),
243 client_(nullptr), 243 client_(nullptr),
244 sensor_(sensor), 244 sensor_(sensor),
245 event_listener_(new EventListener(this)) { 245 event_listener_(new EventListener(this)),
246 weak_factory_(this) {
246 DCHECK(init_params_); 247 DCHECK(init_params_);
247 DCHECK(!init_params_->reader_func.is_null()); 248 DCHECK(!init_params_->reader_func.is_null());
248 DCHECK(sensor_); 249 DCHECK(sensor_);
249 } 250 }
250 251
251 void PlatformSensorReaderWin::SetClient(Client* client) { 252 void PlatformSensorReaderWin::SetClient(Client* client) {
252 base::AutoLock autolock(lock_); 253 base::AutoLock autolock(lock_);
253 // Can be null. 254 // Can be null.
254 client_ = client; 255 client_ = client;
255 } 256 }
(...skipping 10 matching lines...) Expand all
266 DCHECK(task_runner_->BelongsToCurrentThread()); 267 DCHECK(task_runner_->BelongsToCurrentThread());
267 } 268 }
268 269
269 bool PlatformSensorReaderWin::StartSensor( 270 bool PlatformSensorReaderWin::StartSensor(
270 const PlatformSensorConfiguration& configuration) { 271 const PlatformSensorConfiguration& configuration) {
271 base::AutoLock autolock(lock_); 272 base::AutoLock autolock(lock_);
272 273
273 if (!SetReportingInterval(configuration)) 274 if (!SetReportingInterval(configuration))
274 return false; 275 return false;
275 276
276 // Set event listener.
277 if (!sensor_active_) { 277 if (!sensor_active_) {
278 base::win::ScopedComPtr<ISensorEvents> sensor_events; 278 task_runner_->PostTask(
279 HRESULT hr = event_listener_->QueryInterface(__uuidof(ISensorEvents), 279 FROM_HERE, base::Bind(&PlatformSensorReaderWin::ListenSensorEvent,
280 sensor_events.ReceiveVoid()); 280 weak_factory_.GetWeakPtr()));
281
282 if (FAILED(hr) || !sensor_events)
283 return false;
284
285 if (FAILED(sensor_->SetEventSink(sensor_events.get())))
286 return false;
287
288 sensor_active_ = true; 281 sensor_active_ = true;
289 } 282 }
290 283
291 return true; 284 return true;
292 } 285 }
293 286
287 void PlatformSensorReaderWin::ListenSensorEvent() {
288 event_listener_->AddRef();
Mikhail 2016/11/21 11:17:40 why is that needed?
289 // Set event listener.
290 if (FAILED(sensor_->SetEventSink(event_listener_.get()))) {
291 SensorError();
292 StopSensor();
293 }
294 }
295
294 bool PlatformSensorReaderWin::SetReportingInterval( 296 bool PlatformSensorReaderWin::SetReportingInterval(
295 const PlatformSensorConfiguration& configuration) { 297 const PlatformSensorConfiguration& configuration) {
296 base::win::ScopedComPtr<IPortableDeviceValues> props; 298 base::win::ScopedComPtr<IPortableDeviceValues> props;
297 if (SUCCEEDED(props.CreateInstance(CLSID_PortableDeviceValues))) { 299 if (SUCCEEDED(props.CreateInstance(CLSID_PortableDeviceValues))) {
298 unsigned interval = 300 unsigned interval =
299 (1 / configuration.frequency()) * base::Time::kMillisecondsPerSecond; 301 (1 / configuration.frequency()) * base::Time::kMillisecondsPerSecond;
300 302
301 HRESULT hr = props->SetUnsignedIntegerValue( 303 HRESULT hr = props->SetUnsignedIntegerValue(
302 SENSOR_PROPERTY_CURRENT_REPORT_INTERVAL, interval); 304 SENSOR_PROPERTY_CURRENT_REPORT_INTERVAL, interval);
303 305
(...skipping 25 matching lines...) Expand all
329 331
330 unsigned long PlatformSensorReaderWin::GetMinimalReportingIntervalMs() const { 332 unsigned long PlatformSensorReaderWin::GetMinimalReportingIntervalMs() const {
331 return init_params_->min_reporting_interval_ms; 333 return init_params_->min_reporting_interval_ms;
332 } 334 }
333 335
334 mojom::ReportingMode PlatformSensorReaderWin::GetReportingMode() const { 336 mojom::ReportingMode PlatformSensorReaderWin::GetReportingMode() const {
335 return init_params_->reporting_mode; 337 return init_params_->reporting_mode;
336 } 338 }
337 339
338 } // namespace device 340 } // namespace device
OLDNEW
« 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