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> |
| 8 |
7 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
8 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
9 #include "base/task_runner_util.h" | 11 #include "base/task_runner_util.h" |
10 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
11 #include "device/generic_sensor/platform_sensor_win.h" | 13 #include "device/generic_sensor/platform_sensor_win.h" |
12 | 14 |
13 namespace device { | 15 namespace device { |
14 | 16 |
15 // static | 17 // static |
16 PlatformSensorProviderWin* PlatformSensorProviderWin::GetInstance() { | 18 PlatformSensorProviderWin* PlatformSensorProviderWin::GetInstance() { |
(...skipping 26 matching lines...) Expand all Loading... |
43 base::Unretained(this), type), | 45 base::Unretained(this), type), |
44 base::Bind(&PlatformSensorProviderWin::SensorReaderCreated, | 46 base::Bind(&PlatformSensorProviderWin::SensorReaderCreated, |
45 base::Unretained(this), type, base::Passed(&mapping), | 47 base::Unretained(this), type, base::Passed(&mapping), |
46 callback)); | 48 callback)); |
47 } | 49 } |
48 | 50 |
49 bool PlatformSensorProviderWin::InitializeSensorManager() { | 51 bool PlatformSensorProviderWin::InitializeSensorManager() { |
50 if (sensor_manager_) | 52 if (sensor_manager_) |
51 return true; | 53 return true; |
52 | 54 |
53 HRESULT hr = sensor_manager_.CreateInstance(CLSID_SensorManager); | 55 HRESULT hr = ::CoCreateInstance(CLSID_SensorManager, nullptr, CLSCTX_ALL, |
| 56 IID_PPV_ARGS(&sensor_manager_)); |
54 return SUCCEEDED(hr); | 57 return SUCCEEDED(hr); |
55 } | 58 } |
56 | 59 |
57 void PlatformSensorProviderWin::AllSensorsRemoved() { | 60 void PlatformSensorProviderWin::AllSensorsRemoved() { |
58 StopSensorThread(); | 61 StopSensorThread(); |
59 } | 62 } |
60 | 63 |
61 bool PlatformSensorProviderWin::StartSensorThread() { | 64 bool PlatformSensorProviderWin::StartSensorThread() { |
62 if (!sensor_thread_) { | 65 if (!sensor_thread_) { |
63 sensor_thread_ = base::MakeUnique<base::Thread>("Sensor thread"); | 66 sensor_thread_ = base::MakeUnique<base::Thread>("Sensor thread"); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 100 |
98 std::unique_ptr<PlatformSensorReaderWin> | 101 std::unique_ptr<PlatformSensorReaderWin> |
99 PlatformSensorProviderWin::CreateSensorReader(mojom::SensorType type) { | 102 PlatformSensorProviderWin::CreateSensorReader(mojom::SensorType type) { |
100 DCHECK(sensor_thread_->task_runner()->BelongsToCurrentThread()); | 103 DCHECK(sensor_thread_->task_runner()->BelongsToCurrentThread()); |
101 if (!InitializeSensorManager()) | 104 if (!InitializeSensorManager()) |
102 return nullptr; | 105 return nullptr; |
103 return PlatformSensorReaderWin::Create(type, sensor_manager_); | 106 return PlatformSensorReaderWin::Create(type, sensor_manager_); |
104 } | 107 } |
105 | 108 |
106 } // namespace device | 109 } // namespace device |
OLD | NEW |