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

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

Issue 1892083002: Generic Sensor API : Ambient Light Sensor API. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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/sensor/sensor_impl.h"
6
7 #include <utility>
8
9 #include "base/bind.h"
10
11 namespace device {
12
13 // static
14 void SensorImpl::Create(mojo::InterfaceRequest<AmbientLightSensor> request) {
15 new SensorImpl(std::move(request));
16 }
17
18 SensorImpl::SensorImpl(mojo::InterfaceRequest<AmbientLightSensor> request)
19 : binding_(this, std::move(request)), reading_to_report_(false) {
20 // NOTE: DidChange may be called before AddCallback returns. This is done to
21 // report current reading.
22 subscription_ = SensorService::GetInstance()->AddCallback(
23 base::Bind(&SensorImpl::DidChange, base::Unretained(this)));
24 }
25
26 SensorImpl::~SensorImpl() {}
27
28 void SensorImpl::QueryNextReading(const SensorReadingCallback& callback) {
29 if (!callback_.is_null()) {
30 DVLOG(1) << "Overlapped call to QueryNextReading!";
31 delete this;
32 return;
33 }
34 callback_ = callback;
35
36 if (reading_to_report_)
37 ReportReading();
38 }
39
40 void SensorImpl::StartReading() {
41 // TODO(riju): To be implemented.
42 }
43
44 void SensorImpl::StopReading() {
45 // TODO(riju): To be implemented.
46 }
47
48 void SensorImpl::DidChange(const AmbientLightSensorReading& sensor_reading) {
49 reading_ = sensor_reading;
50 reading_to_report_ = true;
51
52 if (!callback_.is_null())
53 ReportReading();
54 }
55
56 void SensorImpl::ReportReading() {
57 callback_.Run(reading_.Clone());
58 callback_.reset();
59
60 reading_to_report_ = false;
61 }
62
63 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698