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

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

Issue 2927263002: Add |notify_client_on_reading_change| flag to sensor configuration (Closed)
Patch Set: fix browser test Created 3 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/generic_sensor/sensor_impl.h" 5 #include "device/generic_sensor/sensor_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "mojo/public/cpp/bindings/strong_binding.h" 9 #include "mojo/public/cpp/bindings/strong_binding.h"
10 10
11 namespace device { 11 namespace device {
12 12
13 SensorImpl::SensorImpl(scoped_refptr<PlatformSensor> sensor) 13 SensorImpl::SensorImpl(scoped_refptr<PlatformSensor> sensor)
14 : sensor_(std::move(sensor)), suspended_(false) { 14 : sensor_(std::move(sensor)),
15 suspended_(false),
16 notify_client_on_reading_change_count_(0) {
15 sensor_->AddClient(this); 17 sensor_->AddClient(this);
16 } 18 }
17 19
18 SensorImpl::~SensorImpl() { 20 SensorImpl::~SensorImpl() {
19 sensor_->RemoveClient(this); 21 sensor_->RemoveClient(this);
20 } 22 }
21 23
22 mojom::SensorClientRequest SensorImpl::GetClient() { 24 mojom::SensorClientRequest SensorImpl::GetClient() {
23 return mojo::MakeRequest(&client_); 25 return mojo::MakeRequest(&client_);
24 } 26 }
25 27
26 void SensorImpl::AddConfiguration( 28 void SensorImpl::AddConfiguration(
27 const PlatformSensorConfiguration& configuration, 29 const PlatformSensorConfiguration& configuration,
28 AddConfigurationCallback callback) { 30 AddConfigurationCallback callback) {
31 if (configuration.notify_client_on_reading_change())
32 ++notify_client_on_reading_change_count_;
Reilly Grant (use Gerrit) 2017/06/09 18:03:39 This field should only be updated if the sensor ac
juncai 2017/06/09 19:00:51 Done.
29 // TODO(Mikhail): To avoid overflowing browser by repeated AddConfigs 33 // TODO(Mikhail): To avoid overflowing browser by repeated AddConfigs
30 // (maybe limit the number of configs per client). 34 // (maybe limit the number of configs per client).
31 std::move(callback).Run(sensor_->StartListening(this, configuration)); 35 std::move(callback).Run(sensor_->StartListening(this, configuration));
32 } 36 }
33 37
34 void SensorImpl::GetDefaultConfiguration( 38 void SensorImpl::GetDefaultConfiguration(
35 GetDefaultConfigurationCallback callback) { 39 GetDefaultConfigurationCallback callback) {
36 std::move(callback).Run(sensor_->GetDefaultConfiguration()); 40 std::move(callback).Run(sensor_->GetDefaultConfiguration());
37 } 41 }
38 42
39 void SensorImpl::RemoveConfiguration( 43 void SensorImpl::RemoveConfiguration(
40 const PlatformSensorConfiguration& configuration, 44 const PlatformSensorConfiguration& configuration,
41 RemoveConfigurationCallback callback) { 45 RemoveConfigurationCallback callback) {
46 if (configuration.notify_client_on_reading_change())
47 --notify_client_on_reading_change_count_;
42 std::move(callback).Run(sensor_->StopListening(this, configuration)); 48 std::move(callback).Run(sensor_->StopListening(this, configuration));
43 } 49 }
44 50
45 void SensorImpl::Suspend() { 51 void SensorImpl::Suspend() {
46 suspended_ = true; 52 suspended_ = true;
47 sensor_->UpdateSensor(); 53 sensor_->UpdateSensor();
48 } 54 }
49 55
50 void SensorImpl::Resume() { 56 void SensorImpl::Resume() {
51 suspended_ = false; 57 suspended_ = false;
52 sensor_->UpdateSensor(); 58 sensor_->UpdateSensor();
53 } 59 }
54 60
55 void SensorImpl::OnSensorReadingChanged() { 61 void SensorImpl::OnSensorReadingChanged() {
56 DCHECK(!suspended_); 62 DCHECK(!suspended_);
57 if (client_) 63 if (client_ && notify_client_on_reading_change_count_ > 0)
58 client_->SensorReadingChanged(); 64 client_->SensorReadingChanged();
59 } 65 }
60 66
61 void SensorImpl::OnSensorError() { 67 void SensorImpl::OnSensorError() {
62 DCHECK(!suspended_); 68 DCHECK(!suspended_);
63 if (client_) 69 if (client_)
64 client_->RaiseError(); 70 client_->RaiseError();
65 } 71 }
66 72
67 bool SensorImpl::IsNotificationSuspended() { 73 bool SensorImpl::IsNotificationSuspended() {
68 return suspended_; 74 return suspended_;
69 } 75 }
70 76
71 } // namespace device 77 } // namespace device
OLDNEW
« device/generic_sensor/sensor_impl.h ('K') | « device/generic_sensor/sensor_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698