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

Unified Diff: device/generic_sensor/polling_platform_sensor.h

Issue 2370343002: [sensors] Ambient light sensor implementation for ChromeOS and Linux. (Closed)
Patch Set: rebased on top of Mihail's cl 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/polling_platform_sensor.h
diff --git a/device/generic_sensor/polling_platform_sensor.h b/device/generic_sensor/polling_platform_sensor.h
new file mode 100644
index 0000000000000000000000000000000000000000..32bad835397316d7f529d5db9607a6b982d117cd
--- /dev/null
+++ b/device/generic_sensor/polling_platform_sensor.h
@@ -0,0 +1,64 @@
+// 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_GENERIC_SENSOR_POLLING_PLATFORM_SENSOR_H_
+#define DEVICE_GENERIC_SENSOR_POLLING_PLATFORM_SENSOR_H_
+
+#include "device/generic_sensor/platform_sensor.h"
+
+#include "base/timer/timer.h"
+
+namespace base {
+class SingleThreadTaskRunner;
+}
+
+namespace device {
+
+class PollingPlatformSensor : public PlatformSensor {
+ public:
+ class Deleter {
+ public:
+ Deleter();
+ ~Deleter();
+
+ void operator()(base::RepeatingTimer* timer) const;
+
+ void set_helper(scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
+ task_runner_ = task_runner;
+ }
+
+ private:
+ void destroy_timer(base::RepeatingTimer* timer) const { delete (timer); }
+
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+ };
+
+ PollingPlatformSensor(
+ mojom::SensorType type,
+ mojo::ScopedSharedBufferMapping mapping,
+ PlatformSensorProvider* provider,
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
+
+ virtual void UpdateReading() = 0;
+
+ protected:
+ ~PollingPlatformSensor() override;
+ bool StartSensor(const PlatformSensorConfiguration& configuration) override;
+ void StopSensor() override;
+ scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner_;
+
+ private:
+ void BeginPoll(const PlatformSensorConfiguration& configuration);
+ void StopPoll();
+ void OnStop();
+
+ std::unique_ptr<base::RepeatingTimer, PollingPlatformSensor::Deleter> timer_;
+ base::WeakPtrFactory<PollingPlatformSensor> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(PollingPlatformSensor);
+};
+
+} // namespace device
+
+#endif // DEVICE_GENERIC_SENSOR_POLLING_PLATFORM_SENSOR_H_

Powered by Google App Engine
This is Rietveld 408576698