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

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

Issue 2323683002: [Sensors] Implement sensor data polling (Closed)
Patch Set: 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
Index: third_party/WebKit/Source/modules/sensor/SensorProxy.cpp
diff --git a/third_party/WebKit/Source/modules/sensor/SensorProxy.cpp b/third_party/WebKit/Source/modules/sensor/SensorProxy.cpp
index 7b84ebc67fd698dda12789e0dae0914b0348f5b0..c2d3edc23efeaa470a7eb8c46722fc11f80bcb8c 100644
--- a/third_party/WebKit/Source/modules/sensor/SensorProxy.cpp
+++ b/third_party/WebKit/Source/modules/sensor/SensorProxy.cpp
@@ -12,8 +12,9 @@ using namespace device::mojom::blink;
namespace blink {
-SensorProxy::SensorProxy(SensorType sensorType, SensorProviderProxy* provider)
- : m_type(sensorType)
+SensorProxy::SensorProxy(SensorType sensorType, Page* page, SensorProviderProxy* provider)
+ : PageVisibilityObserver(page)
+ , m_type(sensorType)
, m_mode(ReportingMode::CONTINUOUS)
, m_provider(provider)
, m_clientBinding(this)
@@ -35,6 +36,7 @@ DEFINE_TRACE(SensorProxy)
{
visitor->trace(m_observers);
visitor->trace(m_provider);
+ PageVisibilityObserver::trace(visitor);
}
void SensorProxy::addObserver(Observer* observer)
@@ -94,6 +96,18 @@ void SensorProxy::SensorReadingChanged()
observer->onSensorReadingChanged();
}
+void SensorProxy::pageVisibilityChanged()
+{
+ if (!isInitialized())
+ return;
+
+ if (page()->visibilityState() != PageVisibilityStateVisible) {
+ m_sensor->Suspend();
+ } else {
+ m_sensor->Resume();
+ }
+}
+
void SensorProxy::handleSensorError()
{
m_state = Uninitialized;

Powered by Google App Engine
This is Rietveld 408576698