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

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

Issue 2865263002: Move //device/generic_sensor to be part of the internal implementation of the Device Service. (Closed)
Patch Set: code rebase Created 3 years, 7 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 #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
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