| 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 #ifndef Sensor_h | 5 #ifndef Sensor_h |
| 6 #define Sensor_h | 6 #define Sensor_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ActiveScriptWrappable.h" | 8 #include "bindings/core/v8/ActiveScriptWrappable.h" |
| 9 #include "bindings/core/v8/ScriptWrappable.h" | 9 #include "bindings/core/v8/ScriptWrappable.h" |
| 10 #include "core/dom/ContextLifecycleObserver.h" | 10 #include "core/dom/ContextLifecycleObserver.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 device::mojom::blink::SensorType); | 67 device::mojom::blink::SensorType); |
| 68 | 68 |
| 69 using SensorConfigurationPtr = device::mojom::blink::SensorConfigurationPtr; | 69 using SensorConfigurationPtr = device::mojom::blink::SensorConfigurationPtr; |
| 70 using SensorConfiguration = device::mojom::blink::SensorConfiguration; | 70 using SensorConfiguration = device::mojom::blink::SensorConfiguration; |
| 71 | 71 |
| 72 // The default implementation will init frequency configuration parameter, | 72 // The default implementation will init frequency configuration parameter, |
| 73 // concrete sensor implementations can override this method to handle other | 73 // concrete sensor implementations can override this method to handle other |
| 74 // parameters if needed. | 74 // parameters if needed. |
| 75 virtual SensorConfigurationPtr createSensorConfig(); | 75 virtual SensorConfigurationPtr createSensorConfig(); |
| 76 double readingValue(int index, bool& isNull) const; | 76 double readingValue(int index, bool& isNull) const; |
| 77 double readingValueUnchecked(int index) const; |
| 78 bool canReturnReadings() const; |
| 79 bool isActivated() const { return m_state == SensorState::Activated; } |
| 77 | 80 |
| 78 private: | 81 private: |
| 79 void initSensorProxyIfNeeded(); | 82 void initSensorProxyIfNeeded(); |
| 80 | 83 |
| 81 // ContextLifecycleObserver overrides. | 84 // ContextLifecycleObserver overrides. |
| 82 void contextDestroyed(ExecutionContext*) override; | 85 void contextDestroyed(ExecutionContext*) override; |
| 83 | 86 |
| 84 // SensorController::Observer overrides. | 87 // SensorController::Observer overrides. |
| 85 void onSensorInitialized() override; | 88 void onSensorInitialized() override; |
| 86 void onSensorReadingChanged(double timestamp) override; | 89 void onSensorReadingChanged(double timestamp) override; |
| 87 void onSensorError(ExceptionCode, | 90 void onSensorError(ExceptionCode, |
| 88 const String& sanitizedMessage, | 91 const String& sanitizedMessage, |
| 89 const String& unsanitizedMessage) override; | 92 const String& unsanitizedMessage) override; |
| 90 | 93 |
| 91 void onStartRequestCompleted(bool); | 94 void onStartRequestCompleted(bool); |
| 92 void onStopRequestCompleted(bool); | 95 void onStopRequestCompleted(bool); |
| 93 | 96 |
| 94 void startListening(); | 97 void startListening(); |
| 95 void stopListening(); | 98 void stopListening(); |
| 96 | 99 |
| 97 void updateState(SensorState newState); | 100 void updateState(SensorState newState); |
| 98 void reportError(ExceptionCode = UnknownError, | 101 void reportError(ExceptionCode = UnknownError, |
| 99 const String& sanitizedMessage = String(), | 102 const String& sanitizedMessage = String(), |
| 100 const String& unsanitizedMessage = String()); | 103 const String& unsanitizedMessage = String()); |
| 101 | 104 |
| 102 void notifySensorReadingChanged(); | 105 void notifySensorReadingChanged(); |
| 103 void notifyOnActivate(); | 106 void notifyOnActivate(); |
| 104 void notifyError(DOMException* error); | 107 void notifyError(DOMException* error); |
| 105 | 108 |
| 106 bool canReturnReadings() const; | |
| 107 | |
| 108 private: | 109 private: |
| 109 SensorOptions m_sensorOptions; | 110 SensorOptions m_sensorOptions; |
| 110 device::mojom::blink::SensorType m_type; | 111 device::mojom::blink::SensorType m_type; |
| 111 SensorState m_state; | 112 SensorState m_state; |
| 112 Member<SensorProxy> m_sensorProxy; | 113 Member<SensorProxy> m_sensorProxy; |
| 113 device::SensorReading m_storedData; | 114 device::SensorReading m_storedData; |
| 114 SensorConfigurationPtr m_configuration; | 115 SensorConfigurationPtr m_configuration; |
| 115 double m_lastUpdateTimestamp; | 116 double m_lastUpdateTimestamp; |
| 116 }; | 117 }; |
| 117 | 118 |
| 118 } // namespace blink | 119 } // namespace blink |
| 119 | 120 |
| 120 #endif // Sensor_h | 121 #endif // Sensor_h |
| OLD | NEW |