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

Side by Side Diff: device/sensors/mojo/sensor_impl.cc

Issue 2078433002: [sensors] Introduce Generic Sensor API interfaces (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Interfaces + implementation of common part. Created 4 years, 6 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/sensors/mojo/sensor_impl.h"
6
7 #include "device/sensors/mojo/sensor_type_converters.h"
8 #include "device/sensors/platform/platform_sensor_configuration.h"
9
10 namespace device {
11 namespace sensors {
12
13 SensorImpl::SensorImpl(mojo::InterfaceRequest<Sensor> request,
14 scoped_refptr<device::PlatformSensor> sensor)
15 : sensor_(sensor), binding_(this, std::move(request)) {
16 sensor_->AddClient(this);
17 }
18
19 SensorImpl::~SensorImpl() {
20 sensor_->RemoveClient(this);
21 }
22
23 void SensorImpl::SetClient(SensorClientPtr client) {
24 client_ = std::move(client);
25 }
26
27 void SensorImpl::Start(SensorConfigurationPtr configuration,
28 const StartCallback& callback) {
29 Result result =
30 sensor_->StartListening(
31 this, configuration.To<device::PlatformSensorConfiguration>())
32 ? Result::SUCCESS
33 : Result::FAILURE;
34 callback.Run(result);
35 }
36
37 void SensorImpl::Stop(SensorConfigurationPtr configuration,
38 const StopCallback& callback) {
39 Result result =
40 sensor_->StopListening(
41 this, configuration.To<device::PlatformSensorConfiguration>())
42 ? Result::SUCCESS
43 : Result::FAILURE;
44 callback.Run(result);
45 }
46
47 void SensorImpl::OnSensorReadingChanged() {
48 if (client_)
49 client_->OnSensorReadingChanged();
50 }
51
52 void SensorImpl::OnSensorError() {
53 if (client_)
54 client_->OnSensorError();
55 }
56
57 } // namespace sensors
58 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698