| OLD | NEW |
| 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/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 return base::WrapUnique( | 350 return base::WrapUnique( |
| 351 new PlatformSensorReaderWin(sensor, std::move(params))); | 351 new PlatformSensorReaderWin(sensor, std::move(params))); |
| 352 } | 352 } |
| 353 | 353 |
| 354 // static | 354 // static |
| 355 base::win::ScopedComPtr<ISensor> PlatformSensorReaderWin::GetSensorForType( | 355 base::win::ScopedComPtr<ISensor> PlatformSensorReaderWin::GetSensorForType( |
| 356 REFSENSOR_TYPE_ID sensor_type, | 356 REFSENSOR_TYPE_ID sensor_type, |
| 357 base::win::ScopedComPtr<ISensorManager> sensor_manager) { | 357 base::win::ScopedComPtr<ISensorManager> sensor_manager) { |
| 358 base::win::ScopedComPtr<ISensor> sensor; | 358 base::win::ScopedComPtr<ISensor> sensor; |
| 359 base::win::ScopedComPtr<ISensorCollection> sensor_collection; | 359 base::win::ScopedComPtr<ISensorCollection> sensor_collection; |
| 360 HRESULT hr = sensor_manager->GetSensorsByType(sensor_type, | 360 HRESULT hr = sensor_manager->GetSensorsByType( |
| 361 sensor_collection.Receive()); | 361 sensor_type, sensor_collection.GetAddressOf()); |
| 362 if (FAILED(hr) || !sensor_collection) | 362 if (FAILED(hr) || !sensor_collection) |
| 363 return sensor; | 363 return sensor; |
| 364 | 364 |
| 365 ULONG count = 0; | 365 ULONG count = 0; |
| 366 hr = sensor_collection->GetCount(&count); | 366 hr = sensor_collection->GetCount(&count); |
| 367 if (SUCCEEDED(hr) && count > 0) | 367 if (SUCCEEDED(hr) && count > 0) |
| 368 sensor_collection->GetAt(0, sensor.Receive()); | 368 sensor_collection->GetAt(0, sensor.GetAddressOf()); |
| 369 return sensor; | 369 return sensor; |
| 370 } | 370 } |
| 371 | 371 |
| 372 PlatformSensorReaderWin::PlatformSensorReaderWin( | 372 PlatformSensorReaderWin::PlatformSensorReaderWin( |
| 373 base::win::ScopedComPtr<ISensor> sensor, | 373 base::win::ScopedComPtr<ISensor> sensor, |
| 374 std::unique_ptr<ReaderInitParams> params) | 374 std::unique_ptr<ReaderInitParams> params) |
| 375 : init_params_(std::move(params)), | 375 : init_params_(std::move(params)), |
| 376 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 376 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 377 sensor_active_(false), | 377 sensor_active_(false), |
| 378 client_(nullptr), | 378 client_(nullptr), |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 base::win::ScopedComPtr<IPortableDeviceValues> props; | 432 base::win::ScopedComPtr<IPortableDeviceValues> props; |
| 433 if (SUCCEEDED(props.CreateInstance(CLSID_PortableDeviceValues))) { | 433 if (SUCCEEDED(props.CreateInstance(CLSID_PortableDeviceValues))) { |
| 434 unsigned interval = | 434 unsigned interval = |
| 435 (1 / configuration.frequency()) * base::Time::kMillisecondsPerSecond; | 435 (1 / configuration.frequency()) * base::Time::kMillisecondsPerSecond; |
| 436 | 436 |
| 437 HRESULT hr = props->SetUnsignedIntegerValue( | 437 HRESULT hr = props->SetUnsignedIntegerValue( |
| 438 SENSOR_PROPERTY_CURRENT_REPORT_INTERVAL, interval); | 438 SENSOR_PROPERTY_CURRENT_REPORT_INTERVAL, interval); |
| 439 | 439 |
| 440 if (SUCCEEDED(hr)) { | 440 if (SUCCEEDED(hr)) { |
| 441 base::win::ScopedComPtr<IPortableDeviceValues> return_props; | 441 base::win::ScopedComPtr<IPortableDeviceValues> return_props; |
| 442 hr = sensor_->SetProperties(props.Get(), return_props.Receive()); | 442 hr = sensor_->SetProperties(props.Get(), return_props.GetAddressOf()); |
| 443 return SUCCEEDED(hr); | 443 return SUCCEEDED(hr); |
| 444 } | 444 } |
| 445 } | 445 } |
| 446 return false; | 446 return false; |
| 447 } | 447 } |
| 448 | 448 |
| 449 HRESULT PlatformSensorReaderWin::SensorReadingChanged( | 449 HRESULT PlatformSensorReaderWin::SensorReadingChanged( |
| 450 ISensorDataReport& report, | 450 ISensorDataReport& report, |
| 451 SensorReading& reading) const { | 451 SensorReading& reading) const { |
| 452 if (!client_) | 452 if (!client_) |
| 453 return E_FAIL; | 453 return E_FAIL; |
| 454 | 454 |
| 455 HRESULT hr = init_params_->reader_func.Run(report, reading); | 455 HRESULT hr = init_params_->reader_func.Run(report, reading); |
| 456 if (SUCCEEDED(hr)) | 456 if (SUCCEEDED(hr)) |
| 457 client_->OnReadingUpdated(reading); | 457 client_->OnReadingUpdated(reading); |
| 458 return hr; | 458 return hr; |
| 459 } | 459 } |
| 460 | 460 |
| 461 void PlatformSensorReaderWin::SensorError() { | 461 void PlatformSensorReaderWin::SensorError() { |
| 462 if (client_) | 462 if (client_) |
| 463 client_->OnSensorError(); | 463 client_->OnSensorError(); |
| 464 } | 464 } |
| 465 | 465 |
| 466 unsigned long PlatformSensorReaderWin::GetMinimalReportingIntervalMs() const { | 466 unsigned long PlatformSensorReaderWin::GetMinimalReportingIntervalMs() const { |
| 467 return init_params_->min_reporting_interval_ms; | 467 return init_params_->min_reporting_interval_ms; |
| 468 } | 468 } |
| 469 | 469 |
| 470 } // namespace device | 470 } // namespace device |
| OLD | NEW |