Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Unified Diff: third_party/WebKit/Source/modules/sensor/SensorReading.cpp

Issue 2356133002: Reland of [sensors] Ambient light sensor bindings implementation (Closed)
Patch Set: Rebased and fixed review comment from haraken. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/SensorReading.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/sensor/SensorReading.cpp
diff --git a/third_party/WebKit/Source/modules/sensor/SensorReading.cpp b/third_party/WebKit/Source/modules/sensor/SensorReading.cpp
index 12c14881bc9af7be3a74f93e364ea500abd8c641..675d6c286fa83c730c5fee569fb26bc80f4c5108 100644
--- a/third_party/WebKit/Source/modules/sensor/SensorReading.cpp
+++ b/third_party/WebKit/Source/modules/sensor/SensorReading.cpp
@@ -14,9 +14,10 @@ namespace blink {
SensorReading::SensorReading(SensorProxy* sensorProxy)
: m_sensorProxy(sensorProxy)
{
- DCHECK(m_sensorProxy);
}
+SensorReading::~SensorReading() = default;
+
DEFINE_TRACE(SensorReading)
{
visitor->trace(m_sensorProxy);
@@ -31,6 +32,15 @@ DOMHighResTimeStamp SensorReading::timeStamp(ScriptState* scriptState) const
Performance* performance = DOMWindowPerformance::performance(*window);
DCHECK(performance);
+ if (!m_sensorProxy) {
+ // In cases when SensorReading derived classes are constructed from JS
+ // side, e.g. to create syntetic SensorReadingEvent for testing
+ // purposes, |m_sensorProxy| will be null and SensorReading.timeStamp
+ // would return current DOMHighResTimeStamp, while reading value should
+ // be provided by derived classes.
+ return performance->now();
+ }
+
return performance->monotonicTimeToDOMHighResTimeStamp(m_sensorProxy->reading().timestamp);
}
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/SensorReading.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698