| 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/SensorReading.h" | 5 #include "modules/sensor/SensorReading.h" |
| 6 | 6 |
| 7 #include "core/dom/ExecutionContext.h" |
| 8 #include "core/frame/LocalDOMWindow.h" |
| 9 #include "core/timing/DOMWindowPerformance.h" |
| 10 #include "core/timing/Performance.h" |
| 11 #include "modules/sensor/SensorProxy.h" |
| 12 |
| 7 namespace blink { | 13 namespace blink { |
| 8 | 14 |
| 9 SensorReading::SensorReading() | 15 SensorReading::SensorReading(ExecutionContext* context) |
| 10 { | 16 : m_context(context) |
| 11 } | |
| 12 | |
| 13 SensorReading::SensorReading(bool providesTimeStamp, DOMHighResTimeStamp timeSta
mp) | |
| 14 : m_canProvideTimeStamp(providesTimeStamp) | |
| 15 , m_timeStamp(timeStamp) | |
| 16 { | |
| 17 } | |
| 18 | |
| 19 DOMHighResTimeStamp SensorReading::timeStamp(bool& isNull) | |
| 20 { | |
| 21 if (m_canProvideTimeStamp) | |
| 22 return m_timeStamp; | |
| 23 | |
| 24 isNull = true; | |
| 25 return 0; | |
| 26 } | |
| 27 | |
| 28 SensorReading::~SensorReading() | |
| 29 { | 17 { |
| 30 } | 18 } |
| 31 | 19 |
| 32 DEFINE_TRACE(SensorReading) | 20 DEFINE_TRACE(SensorReading) |
| 33 { | 21 { |
| 22 visitor->trace(m_sensorProxy); |
| 23 visitor->trace(m_context); |
| 24 } |
| 25 |
| 26 void SensorReading::attach(SensorProxy* sensorProxy) |
| 27 { |
| 28 DCHECK(sensorProxy); |
| 29 m_sensorProxy = sensorProxy; |
| 30 } |
| 31 |
| 32 void SensorReading::detach() |
| 33 { |
| 34 m_sensorProxy = nullptr; |
| 35 } |
| 36 |
| 37 DOMHighResTimeStamp SensorReading::timeStamp() const |
| 38 { |
| 39 if (!m_context) |
| 40 return 0.0; |
| 41 |
| 42 LocalDOMWindow* window = m_context->executingWindow(); |
| 43 if (!window) |
| 44 return 0.0; |
| 45 |
| 46 Performance* performance = DOMWindowPerformance::performance(*window); |
| 47 if (!performance) |
| 48 return 0.0; |
| 49 |
| 50 return performance->monotonicTimeToDOMHighResTimeStamp(platformTimeStamp()); |
| 34 } | 51 } |
| 35 | 52 |
| 36 } // namespace blink | 53 } // namespace blink |
| OLD | NEW |