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

Side by Side Diff: chromeos/accelerometer/accelerometer_reader.cc

Issue 560903003: Remove implicit conversions from scoped_refptr to T* in chromeos/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 | « no previous file | chromeos/cert_loader_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chromeos/accelerometer/accelerometer_reader.h" 5 #include "chromeos/accelerometer/accelerometer_reader.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 AccelerometerReader::ConfigurationData::~ConfigurationData() { 152 AccelerometerReader::ConfigurationData::~ConfigurationData() {
153 } 153 }
154 154
155 AccelerometerReader::AccelerometerReader( 155 AccelerometerReader::AccelerometerReader(
156 base::TaskRunner* task_runner, 156 base::TaskRunner* task_runner,
157 AccelerometerReader::Delegate* delegate) 157 AccelerometerReader::Delegate* delegate)
158 : task_runner_(task_runner), 158 : task_runner_(task_runner),
159 delegate_(delegate), 159 delegate_(delegate),
160 configuration_(new AccelerometerReader::Configuration()), 160 configuration_(new AccelerometerReader::Configuration()),
161 weak_factory_(this) { 161 weak_factory_(this) {
162 DCHECK(task_runner_); 162 DCHECK(task_runner_.get());
163 DCHECK(delegate_); 163 DCHECK(delegate_);
164 // Asynchronously detect and initialize the accelerometer to avoid delaying 164 // Asynchronously detect and initialize the accelerometer to avoid delaying
165 // startup. 165 // startup.
166 base::PostTaskAndReplyWithResult(task_runner_.get(), FROM_HERE, 166 base::PostTaskAndReplyWithResult(task_runner_.get(), FROM_HERE,
167 base::Bind(&DetectAndReadAccelerometerConfiguration, configuration_), 167 base::Bind(&DetectAndReadAccelerometerConfiguration, configuration_),
168 base::Bind(&AccelerometerReader::OnInitialized, 168 base::Bind(&AccelerometerReader::OnInitialized,
169 weak_factory_.GetWeakPtr(), configuration_)); 169 weak_factory_.GetWeakPtr(), configuration_));
170 } 170 }
171 171
172 AccelerometerReader::~AccelerometerReader() { 172 AccelerometerReader::~AccelerometerReader() {
173 } 173 }
174 174
175 void AccelerometerReader::OnInitialized( 175 void AccelerometerReader::OnInitialized(
176 scoped_refptr<AccelerometerReader::Configuration> configuration, 176 scoped_refptr<AccelerometerReader::Configuration> configuration,
177 bool success) { 177 bool success) {
178 if (success) 178 if (success)
179 TriggerRead(); 179 TriggerRead();
180 } 180 }
181 181
182 void AccelerometerReader::TriggerRead() { 182 void AccelerometerReader::TriggerRead() {
183 DCHECK(!task_runner_->RunsTasksOnCurrentThread()); 183 DCHECK(!task_runner_->RunsTasksOnCurrentThread());
184 184
185 scoped_refptr<AccelerometerReader::Reading> reading( 185 scoped_refptr<AccelerometerReader::Reading> reading(
186 new AccelerometerReader::Reading()); 186 new AccelerometerReader::Reading());
187 base::PostTaskAndReplyWithResult(task_runner_, FROM_HERE, 187 base::PostTaskAndReplyWithResult(task_runner_.get(),
188 base::Bind(&ReadAccelerometer, reading), 188 FROM_HERE,
189 base::Bind(&AccelerometerReader::OnDataRead, 189 base::Bind(&ReadAccelerometer, reading),
190 weak_factory_.GetWeakPtr(), reading)); 190 base::Bind(&AccelerometerReader::OnDataRead,
191 weak_factory_.GetWeakPtr(),
192 reading));
191 } 193 }
192 194
193 void AccelerometerReader::OnDataRead( 195 void AccelerometerReader::OnDataRead(
194 scoped_refptr<AccelerometerReader::Reading> reading, 196 scoped_refptr<AccelerometerReader::Reading> reading,
195 bool success) { 197 bool success) {
196 DCHECK(!task_runner_->RunsTasksOnCurrentThread()); 198 DCHECK(!task_runner_->RunsTasksOnCurrentThread());
197 199
198 if (success) { 200 if (success) {
199 int16* values = reinterpret_cast<int16*>(reading->data); 201 int16* values = reinterpret_cast<int16*>(reading->data);
200 float lid_scale = kMeanGravity / configuration_->data.lid_scale; 202 float lid_scale = kMeanGravity / configuration_->data.lid_scale;
(...skipping 11 matching lines...) Expand all
212 214
213 // Trigger another read after the current sampling delay. 215 // Trigger another read after the current sampling delay.
214 base::MessageLoop::current()->PostDelayedTask( 216 base::MessageLoop::current()->PostDelayedTask(
215 FROM_HERE, 217 FROM_HERE,
216 base::Bind(&AccelerometerReader::TriggerRead, 218 base::Bind(&AccelerometerReader::TriggerRead,
217 weak_factory_.GetWeakPtr()), 219 weak_factory_.GetWeakPtr()),
218 base::TimeDelta::FromMilliseconds(kDelayBetweenReadsMs)); 220 base::TimeDelta::FromMilliseconds(kDelayBetweenReadsMs));
219 } 221 }
220 222
221 } // namespace chromeos 223 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chromeos/cert_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698