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