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

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

Issue 2323683002: [Sensors] Implement sensor data polling (Closed)
Patch Set: Applied Tim's suggestions 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/sensor/SensorPollingStrategy.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 070b3b88aa3107e7257ddbff65b4110899b8bd19..6269f7162258b4d688ab5b11d14af4e8d0f7f4ac 100644
--- a/third_party/WebKit/Source/modules/sensor/Sensor.cpp
+++ b/third_party/WebKit/Source/modules/sensor/Sensor.cpp
@@ -160,7 +160,8 @@ void Sensor::onStartRequestCompleted(bool result)
DCHECK(m_configuration);
DCHECK(m_sensorProxy);
auto pollCallback = WTF::bind(&Sensor::pollForData, wrapWeakPersistent(this));
- m_polling = SensorPollingStrategy::create(m_configuration->frequency, std::move(pollCallback), m_sensorProxy->reportingMode());
+ DCHECK_GT(m_configuration->frequency, 0);
+ m_polling = SensorPollingStrategy::create(1 / m_configuration->frequency, std::move(pollCallback), m_sensorProxy->reportingMode());
updateState(Sensor::SensorState::ACTIVE);
}
@@ -179,6 +180,15 @@ void Sensor::onStopRequestCompleted(bool result)
void Sensor::pageVisibilityChanged()
{
updatePollingStatus();
+
+ if (!m_sensorProxy || !m_sensorProxy->isInitialized())
+ return;
+
+ if (page()->visibilityState() != PageVisibilityStateVisible) {
+ m_sensorProxy->suspend();
+ } else {
+ m_sensorProxy->resume();
+ }
}
void Sensor::startListening()
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/sensor/SensorPollingStrategy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698