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_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_ | 5 #ifndef DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_ |
6 #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_ | 6 #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 | 9 |
10 #include "base/threading/non_thread_safe.h" | 10 #include "base/threading/thread_checker.h" |
11 #include "device/generic_sensor/generic_sensor_export.h" | 11 #include "device/generic_sensor/generic_sensor_export.h" |
12 #include "device/generic_sensor/platform_sensor.h" | 12 #include "device/generic_sensor/platform_sensor.h" |
13 | 13 |
14 namespace device { | 14 namespace device { |
15 | 15 |
16 // Base class that defines factory methods for PlatformSensor creation. | 16 // Base class that defines factory methods for PlatformSensor creation. |
17 // Its implementations must be accessed via GetInstance() method. | 17 // Its implementations must be accessed via GetInstance() method. |
18 class DEVICE_GENERIC_SENSOR_EXPORT PlatformSensorProviderBase | 18 class DEVICE_GENERIC_SENSOR_EXPORT PlatformSensorProviderBase { |
19 : public base::NonThreadSafe { | |
20 public: | 19 public: |
21 using CreateSensorCallback = | 20 using CreateSensorCallback = |
22 base::Callback<void(scoped_refptr<PlatformSensor>)>; | 21 base::Callback<void(scoped_refptr<PlatformSensor>)>; |
23 | 22 |
24 // Creates new instance of PlatformSensor. | 23 // Creates new instance of PlatformSensor. |
25 void CreateSensor(mojom::SensorType type, | 24 void CreateSensor(mojom::SensorType type, |
26 const CreateSensorCallback& callback); | 25 const CreateSensorCallback& callback); |
27 | 26 |
28 // Gets previously created instance of PlatformSensor by sensor type |type|. | 27 // Gets previously created instance of PlatformSensor by sensor type |type|. |
29 scoped_refptr<PlatformSensor> GetSensor(mojom::SensorType type); | 28 scoped_refptr<PlatformSensor> GetSensor(mojom::SensorType type); |
(...skipping 24 matching lines...) Expand all Loading... |
54 virtual void AllSensorsRemoved() {} | 53 virtual void AllSensorsRemoved() {} |
55 | 54 |
56 void NotifySensorCreated(mojom::SensorType type, | 55 void NotifySensorCreated(mojom::SensorType type, |
57 scoped_refptr<PlatformSensor> sensor); | 56 scoped_refptr<PlatformSensor> sensor); |
58 | 57 |
59 std::vector<mojom::SensorType> GetPendingRequestTypes(); | 58 std::vector<mojom::SensorType> GetPendingRequestTypes(); |
60 | 59 |
61 mojo::ScopedSharedBufferMapping MapSharedBufferForType( | 60 mojo::ScopedSharedBufferMapping MapSharedBufferForType( |
62 mojom::SensorType type); | 61 mojom::SensorType type); |
63 | 62 |
| 63 THREAD_CHECKER(thread_checker_); |
| 64 |
64 private: | 65 private: |
65 friend class PlatformSensor; // To call RemoveSensor(); | 66 friend class PlatformSensor; // To call RemoveSensor(); |
66 | 67 |
67 bool CreateSharedBufferIfNeeded(); | 68 bool CreateSharedBufferIfNeeded(); |
68 void RemoveSensor(mojom::SensorType type); | 69 void RemoveSensor(mojom::SensorType type); |
69 | 70 |
70 private: | 71 private: |
71 using CallbackQueue = std::vector<CreateSensorCallback>; | 72 using CallbackQueue = std::vector<CreateSensorCallback>; |
72 | 73 |
73 std::map<mojom::SensorType, PlatformSensor*> sensor_map_; | 74 std::map<mojom::SensorType, PlatformSensor*> sensor_map_; |
74 std::map<mojom::SensorType, CallbackQueue> requests_map_; | 75 std::map<mojom::SensorType, CallbackQueue> requests_map_; |
75 mojo::ScopedSharedBufferHandle shared_buffer_handle_; | 76 mojo::ScopedSharedBufferHandle shared_buffer_handle_; |
76 | 77 |
77 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderBase); | 78 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderBase); |
78 }; | 79 }; |
79 | 80 |
80 } // namespace device | 81 } // namespace device |
81 | 82 |
82 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_ | 83 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_ |
OLD | NEW |