| 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/non_thread_safe.h" |
| 11 #include "device/generic_sensor/platform_sensor.h" | 11 #include "device/generic_sensor/platform_sensor.h" |
| 12 | 12 |
| 13 namespace device { | 13 namespace device { |
| 14 | 14 |
| 15 // Base class that defines factory methods for PlatformSensor creation. | 15 // Base class that defines factory methods for PlatformSensor creation. |
| 16 // Its implementations must be accessed via GetInstance() method. | 16 // Its implementations must be accessed via GetInstance() method. |
| 17 class PlatformSensorProviderBase : public base::NonThreadSafe { | 17 class PlatformSensorProviderBase : public base::NonThreadSafe { |
| 18 public: | 18 public: |
| 19 using CreateSensorCallback = |
| 20 base::Callback<void(scoped_refptr<PlatformSensor>)>; |
| 21 |
| 19 // Creates new instance of PlatformSensor. | 22 // Creates new instance of PlatformSensor. |
| 20 scoped_refptr<PlatformSensor> CreateSensor(mojom::SensorType type, | 23 void CreateSensor(mojom::SensorType type, |
| 21 uint64_t size, | 24 uint64_t size, |
| 22 uint64_t offset); | 25 uint64_t offset, |
| 26 const CreateSensorCallback& callback); |
| 23 | 27 |
| 24 // Gets previously created instance of PlatformSensor by sensor type |type|. | 28 // Gets previously created instance of PlatformSensor by sensor type |type|. |
| 25 scoped_refptr<PlatformSensor> GetSensor(mojom::SensorType type); | 29 scoped_refptr<PlatformSensor> GetSensor(mojom::SensorType type); |
| 26 | 30 |
| 27 // Shared buffer getters. | 31 // Shared buffer getters. |
| 28 mojo::ScopedSharedBufferHandle CloneSharedBufferHandle(); | 32 mojo::ScopedSharedBufferHandle CloneSharedBufferHandle(); |
| 29 | 33 |
| 30 protected: | 34 protected: |
| 31 PlatformSensorProviderBase(); | 35 PlatformSensorProviderBase(); |
| 32 virtual ~PlatformSensorProviderBase(); | 36 virtual ~PlatformSensorProviderBase(); |
| 33 | 37 |
| 34 // Method that must be implemented by platform specific classes. | 38 // Method that must be implemented by platform specific classes. |
| 35 virtual scoped_refptr<PlatformSensor> CreateSensorInternal( | 39 virtual void CreateSensorInternal(mojom::SensorType type, |
| 36 mojom::SensorType type, | 40 mojo::ScopedSharedBufferMapping mapping, |
| 37 mojo::ScopedSharedBufferMapping mapping, | 41 uint64_t buffer_size, |
| 38 uint64_t buffer_size) = 0; | 42 const CreateSensorCallback& callback) = 0; |
| 39 | 43 |
| 40 private: | 44 private: |
| 41 friend class PlatformSensor; // To call RemoveSensor(); | 45 friend class PlatformSensor; // To call RemoveSensor(); |
| 42 | 46 |
| 43 bool CreateSharedBufferIfNeeded(); | 47 bool CreateSharedBufferIfNeeded(); |
| 44 void RemoveSensor(mojom::SensorType type); | 48 void RemoveSensor(mojom::SensorType type); |
| 49 void NotifySensorCreated(mojom::SensorType type, |
| 50 scoped_refptr<PlatformSensor> sensor); |
| 45 | 51 |
| 46 private: | 52 private: |
| 53 using CallbackQueue = std::vector<CreateSensorCallback>; |
| 54 |
| 47 std::map<mojom::SensorType, PlatformSensor*> sensor_map_; | 55 std::map<mojom::SensorType, PlatformSensor*> sensor_map_; |
| 56 std::map<mojom::SensorType, CallbackQueue> requests_map_; |
| 48 mojo::ScopedSharedBufferHandle shared_buffer_handle_; | 57 mojo::ScopedSharedBufferHandle shared_buffer_handle_; |
| 49 | 58 |
| 50 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderBase); | 59 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderBase); |
| 51 }; | 60 }; |
| 52 | 61 |
| 53 } // namespace device | 62 } // namespace device |
| 54 | 63 |
| 55 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_ | 64 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_ |
| OLD | NEW |