| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/sensor/Sensor.h" | 5 #include "modules/sensor/Sensor.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/dom/ExceptionCode.h" | 8 #include "core/dom/ExceptionCode.h" |
| 9 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" | 9 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" |
| 10 #include "modules/sensor/SensorErrorEvent.h" | 10 #include "modules/sensor/SensorErrorEvent.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 if (!result) | 172 if (!result) |
| 173 reportError(); | 173 reportError(); |
| 174 | 174 |
| 175 DCHECK(m_sensorProxy); | 175 DCHECK(m_sensorProxy); |
| 176 m_sensorProxy->removeObserver(this); | 176 m_sensorProxy->removeObserver(this); |
| 177 } | 177 } |
| 178 | 178 |
| 179 void Sensor::pageVisibilityChanged() | 179 void Sensor::pageVisibilityChanged() |
| 180 { | 180 { |
| 181 updatePollingStatus(); | 181 updatePollingStatus(); |
| 182 |
| 183 if (!m_sensorProxy || !m_sensorProxy->isInitialized()) |
| 184 return; |
| 185 |
| 186 if (page()->visibilityState() != PageVisibilityStateVisible) { |
| 187 m_sensorProxy->suspend(); |
| 188 } else { |
| 189 m_sensorProxy->resume(); |
| 190 } |
| 182 } | 191 } |
| 183 | 192 |
| 184 void Sensor::startListening() | 193 void Sensor::startListening() |
| 185 { | 194 { |
| 186 DCHECK(m_sensorProxy); | 195 DCHECK(m_sensorProxy); |
| 187 updateState(Sensor::SensorState::ACTIVATING); | 196 updateState(Sensor::SensorState::ACTIVATING); |
| 188 if (!m_sensorReading) | 197 if (!m_sensorReading) |
| 189 m_sensorReading = createSensorReading(m_sensorProxy); | 198 m_sensorReading = createSensorReading(m_sensorProxy); |
| 190 | 199 |
| 191 m_sensorProxy->addObserver(this); | 200 m_sensorProxy->addObserver(this); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 | 263 |
| 255 if (m_state != Sensor::SensorState::ACTIVE | 264 if (m_state != Sensor::SensorState::ACTIVE |
| 256 || page()->visibilityState() != PageVisibilityStateVisible) { | 265 || page()->visibilityState() != PageVisibilityStateVisible) { |
| 257 m_polling->stopPolling(); | 266 m_polling->stopPolling(); |
| 258 } else { | 267 } else { |
| 259 m_polling->startPolling(); | 268 m_polling->startPolling(); |
| 260 } | 269 } |
| 261 } | 270 } |
| 262 | 271 |
| 263 } // namespace blink | 272 } // namespace blink |
| OLD | NEW |