| 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 "core/dom/TaskRunnerHelper.h" | 9 #include "core/dom/TaskRunnerHelper.h" |
| 10 #include "core/inspector/ConsoleMessage.h" | 10 #include "core/inspector/ConsoleMessage.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 if (frequency > maximumFrequency) | 156 if (frequency > maximumFrequency) |
| 157 frequency = maximumFrequency; | 157 frequency = maximumFrequency; |
| 158 if (frequency < minimumFrequency) | 158 if (frequency < minimumFrequency) |
| 159 frequency = minimumFrequency; | 159 frequency = minimumFrequency; |
| 160 | 160 |
| 161 result->frequency = frequency; | 161 result->frequency = frequency; |
| 162 return result; | 162 return result; |
| 163 } | 163 } |
| 164 | 164 |
| 165 double Sensor::readingValue(int index, bool& isNull) const { | 165 double Sensor::readingValue(int index, bool& isNull) const { |
| 166 if (!canReturnReadings()) { | 166 isNull = !canReturnReadings(); |
| 167 isNull = true; | 167 return isNull ? 0.0 : readingValueUnchecked(index); |
| 168 return 0.0; | 168 } |
| 169 } | 169 |
| 170 double Sensor::readingValueUnchecked(int index) const { |
| 170 DCHECK(m_sensorProxy); | 171 DCHECK(m_sensorProxy); |
| 171 DCHECK(index >= 0 && index < device::SensorReading::kValuesCount); | 172 DCHECK(index >= 0 && index < device::SensorReading::kValuesCount); |
| 172 return m_sensorProxy->reading().values[index]; | 173 return m_sensorProxy->reading().values[index]; |
| 173 } | 174 } |
| 174 | 175 |
| 175 void Sensor::initSensorProxyIfNeeded() { | 176 void Sensor::initSensorProxyIfNeeded() { |
| 176 if (m_sensorProxy) | 177 if (m_sensorProxy) |
| 177 return; | 178 return; |
| 178 | 179 |
| 179 Document* document = toDocument(getExecutionContext()); | 180 Document* document = toDocument(getExecutionContext()); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 void Sensor::notifyOnActivate() { | 312 void Sensor::notifyOnActivate() { |
| 312 dispatchEvent(Event::create(EventTypeNames::activate)); | 313 dispatchEvent(Event::create(EventTypeNames::activate)); |
| 313 } | 314 } |
| 314 | 315 |
| 315 void Sensor::notifyError(DOMException* error) { | 316 void Sensor::notifyError(DOMException* error) { |
| 316 dispatchEvent( | 317 dispatchEvent( |
| 317 SensorErrorEvent::create(EventTypeNames::error, std::move(error))); | 318 SensorErrorEvent::create(EventTypeNames::error, std::move(error))); |
| 318 } | 319 } |
| 319 | 320 |
| 320 bool Sensor::canReturnReadings() const { | 321 bool Sensor::canReturnReadings() const { |
| 321 if (m_state != Sensor::SensorState::Activated) | 322 if (!isActivated()) |
| 322 return false; | 323 return false; |
| 323 DCHECK(m_sensorProxy); | 324 DCHECK(m_sensorProxy); |
| 324 return m_sensorProxy->reading().timestamp != 0.0; | 325 return m_sensorProxy->reading().timestamp != 0.0; |
| 325 } | 326 } |
| 326 | 327 |
| 327 } // namespace blink | 328 } // namespace blink |
| OLD | NEW |