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

Side by Side Diff: services/device/generic_sensor/platform_sensor_reader_linux.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
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/platform_sensor_reader_linux.h" 5 #include "services/device/generic_sensor/platform_sensor_reader_linux.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/threading/thread_restrictions.h" 12 #include "base/threading/thread_restrictions.h"
13 #include "base/timer/timer.h" 13 #include "base/timer/timer.h"
14 #include "device/generic_sensor/linux/sensor_data_linux.h" 14 #include "services/device/generic_sensor/linux/sensor_data_linux.h"
15 #include "device/generic_sensor/platform_sensor_linux.h" 15 #include "services/device/generic_sensor/platform_sensor_linux.h"
16 #include "device/generic_sensor/public/cpp/sensor_reading.h" 16 #include "services/device/public/cpp/generic_sensor/sensor_reading.h"
17 17
18 namespace device { 18 namespace device {
19 19
20 class PollingSensorReader : public SensorReader { 20 class PollingSensorReader : public SensorReader {
21 public: 21 public:
22 PollingSensorReader(const SensorInfoLinux* sensor_device, 22 PollingSensorReader(const SensorInfoLinux* sensor_device,
23 base::WeakPtr<PlatformSensorLinux> sensor, 23 base::WeakPtr<PlatformSensorLinux> sensor,
24 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 24 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
25 ~PollingSensorReader() override; 25 ~PollingSensorReader() override;
26 26
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 void PollingSensorReader::StopFetchingData() { 79 void PollingSensorReader::StopFetchingData() {
80 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 80 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
81 is_reading_active_ = false; 81 is_reading_active_ = false;
82 timer_.Stop(); 82 timer_.Stop();
83 } 83 }
84 84
85 void PollingSensorReader::InitializeTimer( 85 void PollingSensorReader::InitializeTimer(
86 const PlatformSensorConfiguration& configuration) { 86 const PlatformSensorConfiguration& configuration) {
87 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 87 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
88 DCHECK(!is_reading_active_); 88 DCHECK(!is_reading_active_);
89 timer_.Start(FROM_HERE, base::TimeDelta::FromMicroseconds( 89 timer_.Start(
90 base::Time::kMicrosecondsPerSecond / 90 FROM_HERE,
91 configuration.frequency()), 91 base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond /
92 this, &PollingSensorReader::PollForData); 92 configuration.frequency()),
93 this, &PollingSensorReader::PollForData);
93 is_reading_active_ = true; 94 is_reading_active_ = true;
94 } 95 }
95 96
96 void PollingSensorReader::PollForData() { 97 void PollingSensorReader::PollForData() {
97 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 98 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
98 99
99 SensorReading readings; 100 SensorReading readings;
100 DCHECK_LE(sensor_file_paths_.size(), arraysize(readings.values)); 101 DCHECK_LE(sensor_file_paths_.size(), arraysize(readings.values));
101 int i = 0; 102 int i = 0;
102 for (const auto& path : sensor_file_paths_) { 103 for (const auto& path : sensor_file_paths_) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 void SensorReader::NotifyReadError() { 155 void SensorReader::NotifyReadError() {
155 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 156 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
156 if (is_reading_active_) { 157 if (is_reading_active_) {
157 task_runner_->PostTask( 158 task_runner_->PostTask(
158 FROM_HERE, 159 FROM_HERE,
159 base::Bind(&PlatformSensorLinux::NotifyPlatformSensorError, sensor_)); 160 base::Bind(&PlatformSensorLinux::NotifyPlatformSensorError, sensor_));
160 } 161 }
161 } 162 }
162 163
163 } // namespace device 164 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698