OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_WIN_H_ | |
6 #define SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_WIN_H_ | |
7 | |
8 #include <SensorsApi.h> | |
9 | |
10 #include "base/win/scoped_comptr.h" | |
11 #include "services/device/generic_sensor/platform_sensor_provider.h" | |
12 | |
13 namespace base { | |
14 template <typename T> | |
15 struct DefaultSingletonTraits; | |
16 class Thread; | |
17 } | |
18 | |
19 namespace device { | |
20 | |
21 class PlatformSensorReaderWin; | |
22 | |
23 // Implementation of PlatformSensorProvider for Windows platform. | |
24 // PlatformSensorProviderWin is responsible for following tasks: | |
25 // - Starts sensor thread and stops it when there are no active sensors. | |
26 // - Initialises ISensorManager and creates sensor reader on sensor thread. | |
27 // - Constructs PlatformSensorWin on IPC thread and returns it to requester. | |
28 class PlatformSensorProviderWin final : public PlatformSensorProvider { | |
29 public: | |
30 static PlatformSensorProviderWin* GetInstance(); | |
31 | |
32 // Overrides ISensorManager COM interface provided by the system, used | |
33 // only for testing purposes. | |
34 void SetSensorManagerForTesting( | |
35 base::win::ScopedComPtr<ISensorManager> sensor_manager); | |
36 | |
37 protected: | |
38 ~PlatformSensorProviderWin() override; | |
39 | |
40 // PlatformSensorProvider interface implementation. | |
41 void AllSensorsRemoved() override; | |
42 void CreateSensorInternal(mojom::SensorType type, | |
43 mojo::ScopedSharedBufferMapping mapping, | |
44 const CreateSensorCallback& callback) override; | |
45 | |
46 private: | |
47 PlatformSensorProviderWin(); | |
48 | |
49 bool InitializeSensorManager(); | |
50 bool StartSensorThread(); | |
51 void StopSensorThread(); | |
52 std::unique_ptr<PlatformSensorReaderWin> CreateSensorReader( | |
53 mojom::SensorType type); | |
54 void SensorReaderCreated( | |
55 mojom::SensorType type, | |
56 mojo::ScopedSharedBufferMapping mapping, | |
57 const CreateSensorCallback& callback, | |
58 std::unique_ptr<PlatformSensorReaderWin> sensor_reader); | |
59 | |
60 private: | |
61 friend struct base::DefaultSingletonTraits<PlatformSensorProviderWin>; | |
62 | |
63 base::win::ScopedComPtr<ISensorManager> sensor_manager_; | |
64 std::unique_ptr<base::Thread> sensor_thread_; | |
65 | |
66 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderWin); | |
67 }; | |
68 | |
69 } // namespace device | |
70 | |
71 #endif // SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_WIN_H_ | |
OLD | NEW |