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

Unified Diff: third_party/WebKit/Source/modules/sensor/SensorUpdateNotifier.h

Issue 2551223003: [Sensors] Align sensor reading updates and 'onchange' notification with rAF. (Closed)
Patch Set: Created 4 years 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: third_party/WebKit/Source/modules/sensor/SensorUpdateNotifier.h
diff --git a/third_party/WebKit/Source/modules/sensor/SensorUpdateNotifier.h b/third_party/WebKit/Source/modules/sensor/SensorUpdateNotifier.h
new file mode 100644
index 0000000000000000000000000000000000000000..6b5169bd951c04adfd2a464808808e4ae4e29c88
--- /dev/null
+++ b/third_party/WebKit/Source/modules/sensor/SensorUpdateNotifier.h
@@ -0,0 +1,39 @@
+// 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 SensorUpdateNotifier_h
+#define SensorUpdateNotifier_h
+
+#include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h"
+#include "wtf/Functional.h"
+
+namespace blink {
+
+// This class encapsulates sensor reading update notification logic:
+// the callback is invoked after client calls 'onSensorReadingChanged()'
+// however considering the given sample frequency.
+class SensorUpdateNotifier {
+ public:
+ static std::unique_ptr<SensorUpdateNotifier> create(
+ double frequency,
+ std::unique_ptr<Function<void()>>,
+ device::mojom::blink::ReportingMode);
+
+ // Please see SensorProxy::Observer comments explaining
+ // the |timestamp| argument.
+ virtual void onSensorReadingChanged(double timestamp) = 0;
+ virtual void cancelPendingNotifications() = 0;
+ virtual ~SensorUpdateNotifier() {}
+
+ protected:
+ SensorUpdateNotifier(double period, std::unique_ptr<Function<void()>>);
+
+ double m_period;
+ std::unique_ptr<Function<void()>> m_func;
+ double m_lastTimestamp;
+};
+
+} // namespace blink
+
+#endif // SensorUpdateNotifier_h

Powered by Google App Engine
This is Rietveld 408576698