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

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

Issue 2465363004: [Sensors] Consider maximum supported frequency (Closed)
Patch Set: Comment from Tim Created 4 years, 1 month 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 c9f902d42ad470d7f9d58be39494524c9fa69d63..0a0ded64b3d126ed3e66cfde7491dc0d3b350ee7 100644
--- a/third_party/WebKit/Source/modules/sensor/Sensor.cpp
+++ b/third_party/WebKit/Source/modules/sensor/Sensor.cpp
@@ -138,6 +138,23 @@ bool Sensor::hasPendingActivity() const {
return hasEventListeners();
}
+auto Sensor::createSensorConfig() -> SensorConfigurationPtr {
+ auto result = SensorConfiguration::New();
+
+ double defaultFrequency = m_sensorProxy->defaultConfig()->frequency;
+ double maximumFrequency = m_sensorProxy->maximumFrequency();
+
+ double frequency = m_sensorOptions.hasFrequency()
+ ? m_sensorOptions.frequency()
+ : defaultFrequency;
+
+ if (frequency > maximumFrequency)
+ frequency = maximumFrequency;
+
+ result->frequency = frequency;
+ return result;
+}
+
void Sensor::initSensorProxyIfNeeded() {
if (m_sensorProxy)
return;
@@ -235,9 +252,10 @@ void Sensor::startListening() {
}
if (!m_configuration) {
- m_configuration =
- createSensorConfig(m_sensorOptions, *m_sensorProxy->defaultConfig());
+ m_configuration = createSensorConfig();
DCHECK(m_configuration);
+ DCHECK(m_configuration->frequency > 0 &&
+ m_configuration->frequency <= m_sensorProxy->maximumFrequency());
}
auto startCallback =
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/Sensor.h ('k') | third_party/WebKit/Source/modules/sensor/SensorProxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698