| 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_provider_win.h" | 5 #include "device/generic_sensor/platform_sensor_provider_win.h" |
| 6 | 6 |
| 7 #include <objbase.h> | 7 #include <objbase.h> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 base::Unretained(this), type, base::Passed(&mapping), | 47 base::Unretained(this), type, base::Passed(&mapping), |
| 48 callback)); | 48 callback)); |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool PlatformSensorProviderWin::InitializeSensorManager() { | 51 bool PlatformSensorProviderWin::InitializeSensorManager() { |
| 52 if (sensor_manager_) | 52 if (sensor_manager_) |
| 53 return true; | 53 return true; |
| 54 | 54 |
| 55 HRESULT hr = ::CoCreateInstance(CLSID_SensorManager, nullptr, CLSCTX_ALL, | 55 HRESULT hr = ::CoCreateInstance(CLSID_SensorManager, nullptr, CLSCTX_ALL, |
| 56 IID_PPV_ARGS(&sensor_manager_)); | 56 IID_PPV_ARGS(&sensor_manager_)); |
| 57 return SUCCEEDED(hr); | 57 return SUCCEEDED(hr) && sensor_manager_; |
| 58 } | 58 } |
| 59 | 59 |
| 60 void PlatformSensorProviderWin::AllSensorsRemoved() { | 60 void PlatformSensorProviderWin::AllSensorsRemoved() { |
| 61 StopSensorThread(); | 61 StopSensorThread(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 bool PlatformSensorProviderWin::StartSensorThread() { | 64 bool PlatformSensorProviderWin::StartSensorThread() { |
| 65 if (!sensor_thread_) { | 65 if (!sensor_thread_) { |
| 66 sensor_thread_ = base::MakeUnique<base::Thread>("Sensor thread"); | 66 sensor_thread_ = base::MakeUnique<base::Thread>("Sensor thread"); |
| 67 sensor_thread_->init_com_with_mta(true); | 67 sensor_thread_->init_com_with_mta(true); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 100 |
| 101 std::unique_ptr<PlatformSensorReaderWin> | 101 std::unique_ptr<PlatformSensorReaderWin> |
| 102 PlatformSensorProviderWin::CreateSensorReader(mojom::SensorType type) { | 102 PlatformSensorProviderWin::CreateSensorReader(mojom::SensorType type) { |
| 103 DCHECK(sensor_thread_->task_runner()->BelongsToCurrentThread()); | 103 DCHECK(sensor_thread_->task_runner()->BelongsToCurrentThread()); |
| 104 if (!InitializeSensorManager()) | 104 if (!InitializeSensorManager()) |
| 105 return nullptr; | 105 return nullptr; |
| 106 return PlatformSensorReaderWin::Create(type, sensor_manager_); | 106 return PlatformSensorReaderWin::Create(type, sensor_manager_); |
| 107 } | 107 } |
| 108 | 108 |
| 109 } // namespace device | 109 } // namespace device |
| OLD | NEW |