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

Unified Diff: third_party/WebKit/Source/modules/sensor/Sensor.cpp

Issue 2746573002: [Sensors] Implement bindings for AbsoluteOrientationSensor (Closed)
Patch Set: Comments from Reilly Created 3 years, 9 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: third_party/WebKit/Source/modules/sensor/Sensor.cpp
diff --git a/third_party/WebKit/Source/modules/sensor/Sensor.cpp b/third_party/WebKit/Source/modules/sensor/Sensor.cpp
index c864dda453a3745afea78a6724a0b6802ee1b347..d47061645ee0c58c3f83411af53705adc8533b66 100644
--- a/third_party/WebKit/Source/modules/sensor/Sensor.cpp
+++ b/third_party/WebKit/Source/modules/sensor/Sensor.cpp
@@ -163,10 +163,11 @@ auto Sensor::createSensorConfig() -> SensorConfigurationPtr {
}
double Sensor::readingValue(int index, bool& isNull) const {
- if (!canReturnReadings()) {
- isNull = true;
- return 0.0;
- }
+ isNull = !canReturnReadings();
+ return isNull ? 0.0 : readingValueUnchecked(index);
+}
+
+double Sensor::readingValueUnchecked(int index) const {
DCHECK(m_sensorProxy);
DCHECK(index >= 0 && index < device::SensorReading::kValuesCount);
return m_sensorProxy->reading().values[index];
@@ -200,12 +201,13 @@ void Sensor::onSensorInitialized() {
startListening();
}
-void Sensor::onSensorReadingChanged(double timestamp) {
+void Sensor::notifySensorChanged(double timestamp) {
if (m_state != Sensor::SensorState::Activated)
return;
DCHECK_GT(m_configuration->frequency, 0.0);
double period = 1 / m_configuration->frequency;
+
if (timestamp - m_lastUpdateTimestamp >= period) {
m_lastUpdateTimestamp = timestamp;
notifySensorReadingChanged();
@@ -318,7 +320,7 @@ void Sensor::notifyError(DOMException* error) {
}
bool Sensor::canReturnReadings() const {
- if (m_state != Sensor::SensorState::Activated)
+ if (!isActivated())
return false;
DCHECK(m_sensorProxy);
return m_sensorProxy->reading().timestamp != 0.0;

Powered by Google App Engine
This is Rietveld 408576698