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

Side by Side Diff: device/generic_sensor/sensor_impl.cc

Issue 2144623003: [sensors] Introduce Generic Sensor API interfaces (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from Reilly Created 4 years, 4 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 unified diff | Download patch
OLDNEW
(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 callback.Run(sensor_->StartListening(this, configuration));
timvolodine 2016/08/18 22:52:14 add TODO to avoid overflowing browser by repeated
Mikhail 2016/08/19 09:29:55 Done.
31 }
32
33 void SensorImpl::RemoveConfiguration(
34 const PlatformSensorConfiguration& configuration,
35 const RemoveConfigurationCallback& callback) {
36 callback.Run(sensor_->StopListening(this, configuration));
37 }
38
39 void SensorImpl::SuspendNotification() {
40 suspended_ = true;
41 sensor_->UpdateSensor();
42 }
43
44 void SensorImpl::ResumeNotification() {
45 suspended_ = false;
46 sensor_->UpdateSensor();
47 }
48
49 void SensorImpl::OnSensorReadingChanged() {
50 DCHECK(!suspended_);
51 if (client_)
timvolodine 2016/08/18 22:52:14 is client_ set anywhere? should this be a DCHECK?
Mikhail 2016/08/19 09:29:55 It might be null if hasn't been actually bound to
52 client_->SensorReadingChanged();
53 }
54
55 void SensorImpl::OnSensorError() {
56 DCHECK(!suspended_);
57 if (client_)
58 client_->RaiseError();
59 }
60
61 bool SensorImpl::IsNotificationSuspended() {
62 return suspended_;
63 }
64
65 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698