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

Unified Diff: device/generic_sensor/platform_sensor_provider.h

Issue 2144623003: [sensors] Introduce Generic Sensor API interfaces (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from Reilly Created 4 years, 4 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_provider.h
diff --git a/device/generic_sensor/platform_sensor_provider.h b/device/generic_sensor/platform_sensor_provider.h
new file mode 100644
index 0000000000000000000000000000000000000000..3f8d2347382ee46c668b45cc4c0cc6fd078a55c4
--- /dev/null
+++ b/device/generic_sensor/platform_sensor_provider.h
@@ -0,0 +1,57 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DEVICE_SENSORS_PLATFORM_SENSOR_PROVIDER_H_
+#define DEVICE_SENSORS_PLATFORM_SENSOR_PROVIDER_H_
+
+#include "base/macros.h"
+
+#include "base/threading/non_thread_safe.h"
+#include "device/generic_sensor/platform_sensor.h"
+
+namespace device {
+
+// Base class that defines factory methods for PlatformSensor creation.
+class PlatformSensorProvider : public base::NonThreadSafe {
+ public:
+ static PlatformSensorProvider* Create(uint64_t shared_buffer_size);
+
+ // Creates new instance of PlatformSensor.
+ scoped_refptr<PlatformSensor> CreateSensor(mojom::SensorType type,
+ uint64_t size,
+ uint64_t offset);
+
+ // Gets previously created instance of PlatformSensor by sensor type |type|.
+ scoped_refptr<PlatformSensor> GetSensor(mojom::SensorType type);
+
+ // Shared buffer getters.
+ mojo::ScopedSharedBufferHandle GetClonedSharedBufferHandle();
Reilly Grant (use Gerrit) 2016/08/11 20:59:37 CloneSharedBufferHandle() would be a shorter/clear
Mikhail 2016/08/12 10:21:48 Done.
+
+ protected:
+ explicit PlatformSensorProvider(uint64_t shared_buffer_size);
+ virtual ~PlatformSensorProvider();
+
+ // Method that must be implemented by platform specific classes.
+ virtual scoped_refptr<PlatformSensor> CreateSensor(
+ mojom::SensorType type,
+ mojo::ScopedSharedBufferMapping mapping,
+ uint64_t buffer_size) = 0;
Reilly Grant (use Gerrit) 2016/08/11 20:59:37 This overload is definitely confusing. Please name
Mikhail 2016/08/12 10:21:48 Done.
+
+ private:
+ bool CreateSharedBufferIfNeeded();
+
+ friend class PlatformSensor; // To call RemoveSensor();
Reilly Grant (use Gerrit) 2016/08/11 20:59:37 Move this line to the top of the private: section.
Mikhail 2016/08/12 10:21:48 Done.
+ void RemoveSensor(mojom::SensorType type);
+
+ private:
+ using SensorMap = std::map<mojom::SensorType, PlatformSensor*>;
Reilly Grant (use Gerrit) 2016/08/11 20:59:37 This typedef is used only once here. Don't worry a
Mikhail 2016/08/12 10:21:48 Done.
+ SensorMap sensor_map_;
+ mojo::ScopedSharedBufferHandle shared_buffer_handle_;
+ uint64_t shared_buffer_size_;
+ DISALLOW_COPY_AND_ASSIGN(PlatformSensorProvider);
+};
+
+} // namespace device
+
+#endif // DEVICE_SENSORS_PLATFORM_SENSOR_PROVIDER_H_

Powered by Google App Engine
This is Rietveld 408576698