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

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

Issue 2878653002: Remove base::NonThreadSafe from //device/generic_sensor/ (Closed)
Patch Set: Remove base::NonThreadSafe from //device/generic_sensor/ 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/platform_sensor_reader_linux.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 const SensorInfoLinux* sensor_device, 57 const SensorInfoLinux* sensor_device,
58 base::WeakPtr<PlatformSensorLinux> sensor, 58 base::WeakPtr<PlatformSensorLinux> sensor,
59 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 59 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
60 : SensorReader(sensor, std::move(task_runner)), 60 : SensorReader(sensor, std::move(task_runner)),
61 sensor_file_paths_(sensor_device->device_reading_files), 61 sensor_file_paths_(sensor_device->device_reading_files),
62 scaling_value_(sensor_device->device_scaling_value), 62 scaling_value_(sensor_device->device_scaling_value),
63 offset_value_(sensor_device->device_offset_value), 63 offset_value_(sensor_device->device_offset_value),
64 apply_scaling_func_(sensor_device->apply_scaling_func) {} 64 apply_scaling_func_(sensor_device->apply_scaling_func) {}
65 65
66 PollingSensorReader::~PollingSensorReader() { 66 PollingSensorReader::~PollingSensorReader() {
67 DCHECK(thread_checker_.CalledOnValidThread()); 67 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
68 } 68 }
69 69
70 void PollingSensorReader::StartFetchingData( 70 void PollingSensorReader::StartFetchingData(
71 const PlatformSensorConfiguration& configuration) { 71 const PlatformSensorConfiguration& configuration) {
72 DCHECK(thread_checker_.CalledOnValidThread()); 72 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
73 if (is_reading_active_) 73 if (is_reading_active_)
74 StopFetchingData(); 74 StopFetchingData();
75 InitializeTimer(configuration); 75 InitializeTimer(configuration);
76 } 76 }
77 77
78 void PollingSensorReader::StopFetchingData() { 78 void PollingSensorReader::StopFetchingData() {
79 DCHECK(thread_checker_.CalledOnValidThread()); 79 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
80 is_reading_active_ = false; 80 is_reading_active_ = false;
81 timer_.Stop(); 81 timer_.Stop();
82 } 82 }
83 83
84 void PollingSensorReader::InitializeTimer( 84 void PollingSensorReader::InitializeTimer(
85 const PlatformSensorConfiguration& configuration) { 85 const PlatformSensorConfiguration& configuration) {
86 DCHECK(thread_checker_.CalledOnValidThread()); 86 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
87 DCHECK(!is_reading_active_); 87 DCHECK(!is_reading_active_);
88 timer_.Start(FROM_HERE, base::TimeDelta::FromMicroseconds( 88 timer_.Start(FROM_HERE, base::TimeDelta::FromMicroseconds(
89 base::Time::kMicrosecondsPerSecond / 89 base::Time::kMicrosecondsPerSecond /
90 configuration.frequency()), 90 configuration.frequency()),
91 this, &PollingSensorReader::PollForData); 91 this, &PollingSensorReader::PollForData);
92 is_reading_active_ = true; 92 is_reading_active_ = true;
93 } 93 }
94 94
95 void PollingSensorReader::PollForData() { 95 void PollingSensorReader::PollForData() {
96 DCHECK(thread_checker_.CalledOnValidThread()); 96 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
97 97
98 SensorReading readings; 98 SensorReading readings;
99 DCHECK_LE(sensor_file_paths_.size(), arraysize(readings.values)); 99 DCHECK_LE(sensor_file_paths_.size(), arraysize(readings.values));
100 int i = 0; 100 int i = 0;
101 for (const auto& path : sensor_file_paths_) { 101 for (const auto& path : sensor_file_paths_) {
102 std::string new_read_value; 102 std::string new_read_value;
103 if (!base::ReadFileToString(path, &new_read_value)) { 103 if (!base::ReadFileToString(path, &new_read_value)) {
104 NotifyReadError(); 104 NotifyReadError();
105 StopFetchingData(); 105 StopFetchingData();
106 return; 106 return;
(...skipping 29 matching lines...) Expand all
136 return base::MakeUnique<PollingSensorReader>(sensor_device, sensor, 136 return base::MakeUnique<PollingSensorReader>(sensor_device, sensor,
137 std::move(task_runner)); 137 std::move(task_runner));
138 } 138 }
139 139
140 SensorReader::SensorReader( 140 SensorReader::SensorReader(
141 base::WeakPtr<PlatformSensorLinux> sensor, 141 base::WeakPtr<PlatformSensorLinux> sensor,
142 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 142 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
143 : sensor_(sensor), 143 : sensor_(sensor),
144 task_runner_(std::move(task_runner)), 144 task_runner_(std::move(task_runner)),
145 is_reading_active_(false) { 145 is_reading_active_(false) {
146 thread_checker_.DetachFromThread(); 146 DETACH_FROM_THREAD(thread_checker_);
147 } 147 }
148 148
149 SensorReader::~SensorReader() { 149 SensorReader::~SensorReader() {
150 DCHECK(thread_checker_.CalledOnValidThread()); 150 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
151 } 151 }
152 152
153 void SensorReader::NotifyReadError() { 153 void SensorReader::NotifyReadError() {
154 DCHECK(thread_checker_.CalledOnValidThread()); 154 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
155 if (is_reading_active_) { 155 if (is_reading_active_) {
156 task_runner_->PostTask( 156 task_runner_->PostTask(
157 FROM_HERE, 157 FROM_HERE,
158 base::Bind(&PlatformSensorLinux::NotifyPlatformSensorError, sensor_)); 158 base::Bind(&PlatformSensorLinux::NotifyPlatformSensorError, sensor_));
159 } 159 }
160 } 160 }
161 161
162 } // namespace device 162 } // namespace device
OLDNEW
« no previous file with comments | « device/generic_sensor/platform_sensor_reader_linux.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698