Commit aa03d3a0 authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

Read initial sensor reading from shared memory on initialization

A sensor's initial reading is checked to see if an event should be
fired immediately after it is activated. Unfortunately this initial
reading was not actually read from shared memory. Depending on timing
the reading might be refreshed by the polling timer or upon receiving
a SensorReadingChanged message.

This patch updates the code to take this initial reading on
initialization so that we can reliably decide whether to send an
initial reading event.

Bug: 789515,809537
Change-Id: I96f441aad3ec474ef94fd634aa34bf9b29b9edf9
Reviewed-on: https://chromium-review.googlesource.com/1103178Reviewed-by: default avatarJun Cai <juncai@chromium.org>
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568169}
parent 6e366244
...@@ -122,14 +122,7 @@ class GenericSensorBrowserTest : public ContentBrowserTest { ...@@ -122,14 +122,7 @@ class GenericSensorBrowserTest : public ContentBrowserTest {
DISALLOW_COPY_AND_ASSIGN(GenericSensorBrowserTest); DISALLOW_COPY_AND_ASSIGN(GenericSensorBrowserTest);
}; };
// Flakily crashes on Linux ASAN/TSAN bots. https://crbug.com/789515 IN_PROC_BROWSER_TEST_F(GenericSensorBrowserTest, AmbientLightSensorTest) {
// Flakily times out on Windows bots. https://crbug.com/809537
#if defined(OS_LINUX) || defined(OS_WIN)
#define MAYBE_AmbientLightSensorTest DISABLED_AmbientLightSensorTest
#else
#define MAYBE_AmbientLightSensorTest AmbientLightSensorTest
#endif
IN_PROC_BROWSER_TEST_F(GenericSensorBrowserTest, MAYBE_AmbientLightSensorTest) {
// The test page will create an AmbientLightSensor object in Javascript, // The test page will create an AmbientLightSensor object in Javascript,
// expects to get events with fake values then navigates to #pass. // expects to get events with fake values then navigates to #pass.
GURL test_url = GURL test_url =
......
...@@ -4,10 +4,17 @@ ...@@ -4,10 +4,17 @@
<script type="text/javascript"> <script type="text/javascript">
var timeOrigin; var timeOrigin;
var sensor; var sensor;
var activated = false;
function onAmbientLightActivate() {
activated = true;
}
function onAmbientLightReading() { function onAmbientLightReading() {
if (sensor.illuminance == 50 && if (activated &&
sensor.timestamp > timeOrigin && sensor.illuminance == 50 &&
sensor.timestamp < window.performance.now()) { sensor.timestamp >= timeOrigin &&
sensor.timestamp <= window.performance.now()) {
pass(); pass();
} else { } else {
fail(); fail();
...@@ -17,8 +24,8 @@ ...@@ -17,8 +24,8 @@
function start() { function start() {
sensor = new AmbientLightSensor(); sensor = new AmbientLightSensor();
timeOrigin = window.performance.now(); timeOrigin = window.performance.now();
sensor.onreading = sensor.onactivate = onAmbientLightActivate;
onAmbientLightReading; sensor.onreading = onAmbientLightReading;
sensor.start(); sensor.start();
} }
......
...@@ -95,12 +95,13 @@ void SensorProxyImpl::Resume() { ...@@ -95,12 +95,13 @@ void SensorProxyImpl::Resume() {
void SensorProxyImpl::UpdateSensorReading() { void SensorProxyImpl::UpdateSensorReading() {
DCHECK(ShouldProcessReadings()); DCHECK(ShouldProcessReadings());
DCHECK(shared_buffer_handle_->is_valid());
// Try to read the latest value from shared memory. Failure should not be
// fatal because we only retry a finite number of times.
device::SensorReading reading_data; device::SensorReading reading_data;
if (!shared_buffer_handle_->is_valid() || if (!shared_buffer_reader_->GetReading(&reading_data))
!shared_buffer_reader_->GetReading(&reading_data)) {
HandleSensorError();
return; return;
}
double latest_timestamp = reading_data.timestamp(); double latest_timestamp = reading_data.timestamp();
if (reading_.timestamp() != latest_timestamp && if (reading_.timestamp() != latest_timestamp &&
...@@ -191,8 +192,10 @@ void SensorProxyImpl::OnSensorCreated(SensorCreationResult result, ...@@ -191,8 +192,10 @@ void SensorProxyImpl::OnSensorCreated(SensorCreationResult result,
const auto* buffer = static_cast<const device::SensorReadingSharedBuffer*>( const auto* buffer = static_cast<const device::SensorReadingSharedBuffer*>(
shared_buffer_.get()); shared_buffer_.get());
shared_buffer_reader_.reset( shared_buffer_reader_ =
new device::SensorReadingSharedBufferReader(buffer)); std::make_unique<device::SensorReadingSharedBufferReader>(buffer);
shared_buffer_reader_->GetReading(&reading_);
frequency_limits_.first = params->minimum_frequency; frequency_limits_.first = params->minimum_frequency;
frequency_limits_.second = params->maximum_frequency; frequency_limits_.second = params->maximum_frequency;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment