| 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;
|
|
|