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

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: Definition for PlatformSensorProvider ctor/dtor Created 4 years, 3 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
« no previous file with comments | « device/generic_sensor/sensor_impl.h ('k') | device/generic_sensor/sensor_provider_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // 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
OLDNEW
« no previous file with comments | « device/generic_sensor/sensor_impl.h ('k') | device/generic_sensor/sensor_provider_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698