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