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 DEVICE_SENSORS_PLATFORM_SENSOR_PROVIDER_H_ |
| 6 #define DEVICE_SENSORS_PLATFORM_SENSOR_PROVIDER_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 |
| 10 #include "base/threading/non_thread_safe.h" |
| 11 #include "device/sensors/platform_sensor.h" |
| 12 |
| 13 namespace device { |
| 14 |
| 15 // Base class that defines factory methods for PlatformSensor creation. |
| 16 class PlatformSensorProvider : public base::NonThreadSafe { |
| 17 public: |
| 18 static PlatformSensorProvider* Create(uint64_t shared_buffer_size); |
| 19 |
| 20 // Creates new instance of PlatformSensor. |
| 21 scoped_refptr<PlatformSensor> CreateSensor(SensorType type, |
| 22 uint64_t size, |
| 23 uint64_t offset); |
| 24 |
| 25 // Gets previously created instance of PlatformSensor by sensor type |type|. |
| 26 scoped_refptr<PlatformSensor> GetSensor(SensorType type); |
| 27 |
| 28 // Shared buffer getters. |
| 29 mojo::ScopedSharedBufferHandle GetClonedSharedBufferHandle(); |
| 30 |
| 31 protected: |
| 32 explicit PlatformSensorProvider(uint64_t shared_buffer_size); |
| 33 virtual ~PlatformSensorProvider(); |
| 34 |
| 35 // Method that must be implemented by platform specific classes. |
| 36 virtual scoped_refptr<PlatformSensor> CreateSensor( |
| 37 SensorType type, |
| 38 mojo::ScopedSharedBufferMapping mapping, |
| 39 uint64_t buffer_size) = 0; |
| 40 |
| 41 private: |
| 42 bool CreateSharedBufferIfNeeded(); |
| 43 |
| 44 friend class PlatformSensor; // To call RemoveSensor(); |
| 45 void RemoveSensor(SensorType type); |
| 46 |
| 47 private: |
| 48 using SensorMap = std::map<SensorType, PlatformSensor*>; |
| 49 SensorMap sensor_map_; |
| 50 mojo::ScopedSharedBufferHandle shared_buffer_handle_; |
| 51 uint64_t shared_buffer_size_; |
| 52 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProvider); |
| 53 }; |
| 54 |
| 55 } // namespace device |
| 56 |
| 57 #endif // DEVICE_SENSORS_PLATFORM_SENSOR_PROVIDER_H_ |
OLD | NEW |