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

Unified Diff: device/generic_sensor/platform_sensor_provider_base.h

Issue 2368193003: [sensors] Introduce asynchronous way to create sensors. (Closed)
Patch Set: Created 4 years, 3 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_base.h
diff --git a/device/generic_sensor/platform_sensor_provider_base.h b/device/generic_sensor/platform_sensor_provider_base.h
index 6d38d8596f24f64e2a9226bd6d232c73dddf5673..6a7002480b0a7fab720087b284ce59b35406646d 100644
--- a/device/generic_sensor/platform_sensor_provider_base.h
+++ b/device/generic_sensor/platform_sensor_provider_base.h
@@ -16,10 +16,14 @@ namespace device {
// Its implementations must be accessed via GetInstance() method.
class PlatformSensorProviderBase : public base::NonThreadSafe {
public:
+ using CreateSensorCallback =
+ base::Callback<void(scoped_refptr<PlatformSensor>)>;
+
// Creates new instance of PlatformSensor.
- scoped_refptr<PlatformSensor> CreateSensor(mojom::SensorType type,
- uint64_t size,
- uint64_t offset);
+ void CreateSensor(mojom::SensorType type,
+ uint64_t size,
+ uint64_t offset,
+ const CreateSensorCallback& callback);
// Gets previously created instance of PlatformSensor by sensor type |type|.
scoped_refptr<PlatformSensor> GetSensor(mojom::SensorType type);
@@ -32,19 +36,25 @@ class PlatformSensorProviderBase : public base::NonThreadSafe {
virtual ~PlatformSensorProviderBase();
// Method that must be implemented by platform specific classes.
- virtual scoped_refptr<PlatformSensor> CreateSensorInternal(
- mojom::SensorType type,
- mojo::ScopedSharedBufferMapping mapping,
- uint64_t buffer_size) = 0;
+ virtual void CreateSensorInternal(mojom::SensorType type,
+ mojo::ScopedSharedBufferMapping mapping,
+ uint64_t buffer_size,
+ const CreateSensorCallback& callback) = 0;
private:
friend class PlatformSensor; // To call RemoveSensor();
bool CreateSharedBufferIfNeeded();
void RemoveSensor(mojom::SensorType type);
+ void NotifySensorCreated(mojom::SensorType type,
+ scoped_refptr<PlatformSensor> sensor);
private:
+ using CallbackQueue =
+ std::vector<base::Callback<void(scoped_refptr<PlatformSensor>)>>;
+
std::map<mojom::SensorType, PlatformSensor*> sensor_map_;
+ std::map<mojom::SensorType, CallbackQueue> requests_map_;
Mikhail 2016/09/26 09:52:23 let's keep PlatformSensorProvider simple and move
maksims (do not use this acc) 2016/09/27 10:17:25 We cannot do so. SensorProviderImpl is not a singl
mojo::ScopedSharedBufferHandle shared_buffer_handle_;
DISALLOW_COPY_AND_ASSIGN(PlatformSensorProviderBase);

Powered by Google App Engine
This is Rietveld 408576698