Chromium Code Reviews| Index: device/generic_sensor/sensor_impl.cc |
| diff --git a/device/generic_sensor/sensor_impl.cc b/device/generic_sensor/sensor_impl.cc |
| index 33e9cd0bb2a0f14e81f6cbcdaedfbe5e4c4da948..d29f6d33867a6173f980791181eef32df51484a2 100644 |
| --- a/device/generic_sensor/sensor_impl.cc |
| +++ b/device/generic_sensor/sensor_impl.cc |
| @@ -11,7 +11,9 @@ |
| namespace device { |
| SensorImpl::SensorImpl(scoped_refptr<PlatformSensor> sensor) |
| - : sensor_(std::move(sensor)), suspended_(false) { |
| + : sensor_(std::move(sensor)), |
| + suspended_(false), |
| + notify_client_on_reading_change_count_(0) { |
| sensor_->AddClient(this); |
| } |
| @@ -26,6 +28,8 @@ mojom::SensorClientRequest SensorImpl::GetClient() { |
| void SensorImpl::AddConfiguration( |
| const PlatformSensorConfiguration& configuration, |
| AddConfigurationCallback callback) { |
| + if (configuration.notify_client_on_reading_change()) |
| + ++notify_client_on_reading_change_count_; |
|
Reilly Grant (use Gerrit)
2017/06/09 18:03:39
This field should only be updated if the sensor ac
juncai
2017/06/09 19:00:51
Done.
|
| // TODO(Mikhail): To avoid overflowing browser by repeated AddConfigs |
| // (maybe limit the number of configs per client). |
| std::move(callback).Run(sensor_->StartListening(this, configuration)); |
| @@ -39,6 +43,8 @@ void SensorImpl::GetDefaultConfiguration( |
| void SensorImpl::RemoveConfiguration( |
| const PlatformSensorConfiguration& configuration, |
| RemoveConfigurationCallback callback) { |
| + if (configuration.notify_client_on_reading_change()) |
| + --notify_client_on_reading_change_count_; |
| std::move(callback).Run(sensor_->StopListening(this, configuration)); |
| } |
| @@ -54,7 +60,7 @@ void SensorImpl::Resume() { |
| void SensorImpl::OnSensorReadingChanged() { |
| DCHECK(!suspended_); |
| - if (client_) |
| + if (client_ && notify_client_on_reading_change_count_ > 0) |
| client_->SensorReadingChanged(); |
| } |