Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Unified Diff: device/generic_sensor/platform_sensor.h

Issue 2395853003: [Sensors] Improvements in shared buffer managing (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: device/generic_sensor/platform_sensor.h
diff --git a/device/generic_sensor/platform_sensor.h b/device/generic_sensor/platform_sensor.h
index 0485fc6861fcc2bd68dbcd30970dee2c1ecc8113..2ec1d5200195c3660a41b3c0c0416de5ba8da205 100644
--- a/device/generic_sensor/platform_sensor.h
+++ b/device/generic_sensor/platform_sensor.h
@@ -12,6 +12,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
+#include "device/base/synchronization/shared_memory_seqlock_buffer.h"
#include "device/generic_sensor/public/interfaces/sensor.mojom.h"
#include "mojo/public/cpp/system/buffer.h"
@@ -50,6 +51,12 @@ class PlatformSensor : public base::RefCountedThreadSafe<PlatformSensor> {
void RemoveClient(Client*);
protected:
+ using ReadingBuffer = SharedMemorySeqLockBuffer<mojom::SensorReading>;
+
+ public:
+ static const size_t kReadingBufferSize = sizeof(ReadingBuffer);
+
+ protected:
virtual ~PlatformSensor();
PlatformSensor(mojom::SensorType type,
mojo::ScopedSharedBufferMapping mapping,
@@ -64,17 +71,19 @@ class PlatformSensor : public base::RefCountedThreadSafe<PlatformSensor> {
virtual bool CheckSensorConfiguration(
const PlatformSensorConfiguration& configuration) = 0;
+ // Updates shared buffer with new sensor reading data.
+ // Note: this method is thread-safe.
+ void UpdateSensorReading(const mojom::SensorReading& reading);
+
void NotifySensorReadingChanged();
void NotifySensorError();
- mojo::ScopedSharedBufferMapping shared_buffer_mapping_;
-
// For testing purposes.
const ConfigMap& config_map() const { return config_map_; }
private:
friend class base::RefCountedThreadSafe<PlatformSensor>;
-
+ mojo::ScopedSharedBufferMapping shared_buffer_mapping_;
mojom::SensorType type_;
base::ObserverList<Client, true> clients_;
ConfigMap config_map_;

Powered by Google App Engine
This is Rietveld 408576698