OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "device/generic_sensor/sensor_impl.h" |
| 6 |
| 7 #include <utility> |
| 8 |
| 9 namespace device { |
| 10 |
| 11 SensorImpl::SensorImpl(mojo::InterfaceRequest<Sensor> request, |
| 12 scoped_refptr<PlatformSensor> sensor) |
| 13 : sensor_(std::move(sensor)), |
| 14 binding_(this, std::move(request)), |
| 15 suspended_(false) { |
| 16 sensor_->AddClient(this); |
| 17 } |
| 18 |
| 19 SensorImpl::~SensorImpl() { |
| 20 sensor_->RemoveClient(this); |
| 21 } |
| 22 |
| 23 mojom::SensorClientRequest SensorImpl::GetClient() { |
| 24 return mojo::GetProxy(&client_); |
| 25 } |
| 26 |
| 27 void SensorImpl::AddConfiguration( |
| 28 const PlatformSensorConfiguration& configuration, |
| 29 const AddConfigurationCallback& callback) { |
| 30 // TODO(Mikhail): To avoid overflowing browser by repeated AddConfigs |
| 31 // (maybe limit the number of configs per client). |
| 32 callback.Run(sensor_->StartListening(this, configuration)); |
| 33 } |
| 34 |
| 35 void SensorImpl::RemoveConfiguration( |
| 36 const PlatformSensorConfiguration& configuration, |
| 37 const RemoveConfigurationCallback& callback) { |
| 38 callback.Run(sensor_->StopListening(this, configuration)); |
| 39 } |
| 40 |
| 41 void SensorImpl::Suspend() { |
| 42 suspended_ = true; |
| 43 sensor_->UpdateSensor(); |
| 44 } |
| 45 |
| 46 void SensorImpl::Resume() { |
| 47 suspended_ = false; |
| 48 sensor_->UpdateSensor(); |
| 49 } |
| 50 |
| 51 void SensorImpl::OnSensorReadingChanged() { |
| 52 DCHECK(!suspended_); |
| 53 if (client_) |
| 54 client_->SensorReadingChanged(); |
| 55 } |
| 56 |
| 57 void SensorImpl::OnSensorError() { |
| 58 DCHECK(!suspended_); |
| 59 if (client_) |
| 60 client_->RaiseError(); |
| 61 } |
| 62 |
| 63 bool SensorImpl::IsNotificationSuspended() { |
| 64 return suspended_; |
| 65 } |
| 66 |
| 67 } // namespace device |
OLD | NEW |