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" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 | 31 |
32 protected: | 32 protected: |
33 PlatformSensorProviderBase(); | 33 PlatformSensorProviderBase(); |
34 virtual ~PlatformSensorProviderBase(); | 34 virtual ~PlatformSensorProviderBase(); |
35 | 35 |
36 // Method that must be implemented by platform specific classes. | 36 // Method that must be implemented by platform specific classes. |
37 virtual void CreateSensorInternal(mojom::SensorType type, | 37 virtual void CreateSensorInternal(mojom::SensorType type, |
38 mojo::ScopedSharedBufferMapping mapping, | 38 mojo::ScopedSharedBufferMapping mapping, |
39 const CreateSensorCallback& callback) = 0; | 39 const CreateSensorCallback& callback) = 0; |
40 | 40 |
41 // Implementations might override this method to free resources when there | |
42 // are no sensors left. | |
43 virtual void AllSensorsRemoved() {} | |
shalamov
2016/10/20 06:37:26
Can you also add bool HasSensors() const;
| |
44 | |
41 private: | 45 private: |
42 friend class PlatformSensor; // To call RemoveSensor(); | 46 friend class PlatformSensor; // To call RemoveSensor(); |
43 | 47 |
44 bool CreateSharedBufferIfNeeded(); | 48 bool CreateSharedBufferIfNeeded(); |
45 void RemoveSensor(mojom::SensorType type); | 49 void RemoveSensor(mojom::SensorType type); |
46 void NotifySensorCreated(mojom::SensorType type, | 50 void NotifySensorCreated(mojom::SensorType type, |
47 scoped_refptr<PlatformSensor> sensor); | 51 scoped_refptr<PlatformSensor> sensor); |
48 | 52 |
49 private: | 53 private: |
50 using CallbackQueue = std::vector<CreateSensorCallback>; | 54 using CallbackQueue = std::vector<CreateSensorCallback>; |
51 | 55 |
52 std::map<mojom::SensorType, PlatformSensor*> sensor_map_; | 56 std::map<mojom::SensorType, PlatformSensor*> sensor_map_; |
53 std::map<mojom::SensorType, CallbackQueue> requests_map_; | 57 std::map<mojom::SensorType, CallbackQueue> requests_map_; |
54 mojo::ScopedSharedBufferHandle shared_buffer_handle_; | 58 mojo::ScopedSharedBufferHandle shared_buffer_handle_; |
55 | 59 |
56 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderBase); | 60 DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderBase); |
57 }; | 61 }; |
58 | 62 |
59 } // namespace device | 63 } // namespace device |
60 | 64 |
61 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_ | 65 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_PROVIDER_BASE_H_ |
OLD | NEW |