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 #ifndef DEVICE_SENSORS_DEVICE_SENSOR_HOST_H_ | 5 #ifndef DEVICE_SENSORS_DEVICE_SENSOR_HOST_H_ |
6 #define DEVICE_SENSORS_DEVICE_SENSOR_HOST_H_ | 6 #define DEVICE_SENSORS_DEVICE_SENSOR_HOST_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
10 #include "device/sensors/device_sensors_consts.h" | 10 #include "device/sensors/device_sensors_consts.h" |
11 #include "device/sensors/public/interfaces/light.mojom.h" | |
12 #include "device/sensors/public/interfaces/motion.mojom.h" | 11 #include "device/sensors/public/interfaces/motion.mojom.h" |
13 #include "device/sensors/public/interfaces/orientation.mojom.h" | 12 #include "device/sensors/public/interfaces/orientation.mojom.h" |
14 #include "mojo/public/cpp/bindings/interface_request.h" | 13 #include "mojo/public/cpp/bindings/interface_request.h" |
15 | 14 |
16 namespace device { | 15 namespace device { |
17 | 16 |
18 // A base class for device sensor related mojo interface implementations. | 17 // A base class for device sensor related mojo interface implementations. |
19 template <typename MojoInterface, ConsumerType consumer_type> | 18 template <typename MojoInterface, ConsumerType consumer_type> |
20 class DeviceSensorHost : NON_EXPORTED_BASE(public MojoInterface) { | 19 class DeviceSensorHost : NON_EXPORTED_BASE(public MojoInterface) { |
21 public: | 20 public: |
22 static void Create(mojo::InterfaceRequest<MojoInterface> request); | 21 static void Create(mojo::InterfaceRequest<MojoInterface> request); |
23 | 22 |
24 // All methods below to be called on the IO thread. | 23 // All methods below to be called on the IO thread. |
25 ~DeviceSensorHost() override; | 24 ~DeviceSensorHost() override; |
26 | 25 |
27 private: | 26 private: |
28 DeviceSensorHost(); | 27 DeviceSensorHost(); |
29 | 28 |
30 void StartPolling( | 29 void StartPolling( |
31 const typename MojoInterface::StartPollingCallback& callback) override; | 30 const typename MojoInterface::StartPollingCallback& callback) override; |
32 void StopPolling() override; | 31 void StopPolling() override; |
33 | 32 |
34 bool is_started_; | 33 bool is_started_; |
35 | 34 |
36 base::ThreadChecker thread_checker_; | 35 base::ThreadChecker thread_checker_; |
37 | 36 |
38 DISALLOW_COPY_AND_ASSIGN(DeviceSensorHost); | 37 DISALLOW_COPY_AND_ASSIGN(DeviceSensorHost); |
39 }; | 38 }; |
40 | 39 |
41 using DeviceLightHost = | |
42 DeviceSensorHost<device::mojom::LightSensor, CONSUMER_TYPE_LIGHT>; | |
43 using DeviceMotionHost = | 40 using DeviceMotionHost = |
44 DeviceSensorHost<device::mojom::MotionSensor, CONSUMER_TYPE_MOTION>; | 41 DeviceSensorHost<device::mojom::MotionSensor, CONSUMER_TYPE_MOTION>; |
45 using DeviceOrientationHost = DeviceSensorHost<device::mojom::OrientationSensor, | 42 using DeviceOrientationHost = DeviceSensorHost<device::mojom::OrientationSensor, |
46 CONSUMER_TYPE_ORIENTATION>; | 43 CONSUMER_TYPE_ORIENTATION>; |
47 using DeviceOrientationAbsoluteHost = | 44 using DeviceOrientationAbsoluteHost = |
48 DeviceSensorHost<device::mojom::OrientationAbsoluteSensor, | 45 DeviceSensorHost<device::mojom::OrientationAbsoluteSensor, |
49 CONSUMER_TYPE_ORIENTATION_ABSOLUTE>; | 46 CONSUMER_TYPE_ORIENTATION_ABSOLUTE>; |
50 | 47 |
51 } // namespace device | 48 } // namespace device |
52 | 49 |
53 #endif // DEVICE_SENSORS_DEVICE_SENSOR_HOST_H_ | 50 #endif // DEVICE_SENSORS_DEVICE_SENSOR_HOST_H_ |
OLD | NEW |