| 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/ExecutionContextTask.h" | 9 #include "core/dom/ExecutionContextTask.h" |
| 10 #include "core/dom/TaskRunnerHelper.h" | 10 #include "core/dom/TaskRunnerHelper.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 JSMessageSource, InfoMessageLevel, "Frequency is limited to 60 Hz."); | 57 JSMessageSource, InfoMessageLevel, "Frequency is limited to 60 Hz."); |
| 58 executionContext->addConsoleMessage(consoleMessage); | 58 executionContext->addConsoleMessage(consoleMessage); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 Sensor::~Sensor() = default; | 63 Sensor::~Sensor() = default; |
| 64 | 64 |
| 65 void Sensor::start(ScriptState* scriptState, ExceptionState& exceptionState) { | 65 void Sensor::start(ScriptState* scriptState, ExceptionState& exceptionState) { |
| 66 if (m_state != Sensor::SensorState::Idle && | 66 if (m_state != Sensor::SensorState::Idle && |
| 67 m_state != Sensor::SensorState::Errored) { | 67 m_state != Sensor::SensorState::Errored) |
| 68 exceptionState.throwDOMException( | |
| 69 InvalidStateError, | |
| 70 "Cannot start because SensorState is not Idle or errored"); | |
| 71 return; | 68 return; |
| 72 } | |
| 73 | 69 |
| 74 initSensorProxyIfNeeded(); | 70 initSensorProxyIfNeeded(); |
| 75 | 71 |
| 76 if (!m_sensorProxy) { | 72 if (!m_sensorProxy) { |
| 77 exceptionState.throwDOMException( | 73 exceptionState.throwDOMException( |
| 78 InvalidStateError, "The Sensor is no longer associated to a frame."); | 74 InvalidStateError, "The Sensor is no longer associated to a frame."); |
| 79 return; | 75 return; |
| 80 } | 76 } |
| 81 m_lastUpdateTimestamp = WTF::monotonicallyIncreasingTime(); | 77 m_lastUpdateTimestamp = WTF::monotonicallyIncreasingTime(); |
| 82 startListening(); | 78 startListening(); |
| 83 } | 79 } |
| 84 | 80 |
| 85 void Sensor::stop(ScriptState*, ExceptionState& exceptionState) { | 81 void Sensor::stop(ScriptState*, ExceptionState& exceptionState) { |
| 86 if (m_state == Sensor::SensorState::Idle || | 82 if (m_state == Sensor::SensorState::Idle || |
| 87 m_state == Sensor::SensorState::Errored) { | 83 m_state == Sensor::SensorState::Errored) |
| 88 exceptionState.throwDOMException( | |
| 89 InvalidStateError, | |
| 90 "Cannot stop because SensorState is either Idle or errored"); | |
| 91 return; | 84 return; |
| 92 } | |
| 93 | 85 |
| 94 stopListening(); | 86 stopListening(); |
| 95 } | 87 } |
| 96 | 88 |
| 97 static String ToString(Sensor::SensorState state) { | 89 static String ToString(Sensor::SensorState state) { |
| 98 switch (state) { | 90 switch (state) { |
| 99 case Sensor::SensorState::Idle: | 91 case Sensor::SensorState::Idle: |
| 100 return "idle"; | 92 return "idle"; |
| 101 case Sensor::SensorState::Activating: | 93 case Sensor::SensorState::Activating: |
| 102 return "activating"; | 94 return "activating"; |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 } | 316 } |
| 325 | 317 |
| 326 bool Sensor::canReturnReadings() const { | 318 bool Sensor::canReturnReadings() const { |
| 327 if (m_state != Sensor::SensorState::Activated) | 319 if (m_state != Sensor::SensorState::Activated) |
| 328 return false; | 320 return false; |
| 329 DCHECK(m_sensorProxy); | 321 DCHECK(m_sensorProxy); |
| 330 return m_sensorProxy->reading().timestamp != 0.0; | 322 return m_sensorProxy->reading().timestamp != 0.0; |
| 331 } | 323 } |
| 332 | 324 |
| 333 } // namespace blink | 325 } // namespace blink |
| OLD | NEW |