Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/platform_sensor_iio.h> | |
| 6 #include "base/message_loop/message_loop.h" | |
| 7 | |
| 8 namespace device { | |
| 9 | |
| 10 PlatformSensorIio::PlatformSensorIio( | |
|
Mikhail
2016/10/11 14:46:47
pls add thread checks to methods
Mikhail
2016/10/11 14:46:47
pls add thread check to methods
maksims (do not use this acc)
2016/10/14 12:31:45
Done.
| |
| 11 mojom::SensorType type, | |
| 12 mojo::ScopedSharedBufferMapping mapping, | |
| 13 PlatformSensorProvider* provider, | |
| 14 scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner) | |
| 15 : PlatformSensor(type, std::move(mapping), provider), | |
| 16 polling_thread_task_runner_(polling_task_runner), | |
| 17 timer_(new base::RepeatingTimer()), | |
| 18 weak_factory_(this) {} | |
| 19 | |
| 20 PlatformSensorIio::~PlatformSensorIio() { | |
| 21 polling_thread_task_runner_->DeleteSoon(FROM_HERE, timer_); | |
| 22 } | |
| 23 | |
| 24 bool PlatformSensorIio::StartSensor( | |
| 25 const PlatformSensorConfiguration& configuration) { | |
| 26 return polling_thread_task_runner_->PostTask( | |
| 27 FROM_HERE, base::Bind(&PlatformSensorIio::BeginPoll, | |
| 28 weak_factory_.GetWeakPtr(), configuration)); | |
| 29 } | |
| 30 | |
| 31 void PlatformSensorIio::BeginPoll( | |
| 32 const PlatformSensorConfiguration& configuration) { | |
| 33 DCHECK(polling_thread_task_runner_->BelongsToCurrentThread()); | |
| 34 timer_->Start(FROM_HERE, base::TimeDelta::FromMicroseconds( | |
| 35 base::Time::kMicrosecondsPerSecond / | |
| 36 configuration.frequency()), | |
| 37 this, &PlatformSensorIio::UpdateReading); | |
| 38 } | |
| 39 | |
| 40 void PlatformSensorIio::StopSensor() { | |
| 41 polling_thread_task_runner_->PostTask( | |
| 42 FROM_HERE, base::Bind(&PlatformSensorIio::StopPoll, this)); | |
| 43 } | |
| 44 | |
| 45 void PlatformSensorIio::StopPoll() { | |
| 46 timer_->Stop(); | |
| 47 } | |
| 48 | |
| 49 void PlatformSensorIio::OnSensorReadFailed() { | |
| 50 StopSensor(); | |
|
Mikhail
2016/10/11 14:46:47
is it called on polling thread? if so, than just c
| |
| 51 task_runner_->PostTask(FROM_HERE, | |
| 52 base::Bind(&PlatformSensorIio::NotifySensorError, | |
| 53 weak_factory_.GetWeakPtr())); | |
| 54 } | |
| 55 | |
| 56 bool PlatformSensorIio::CheckSensorConfiguration( | |
| 57 const PlatformSensorConfiguration& configuration) { | |
| 58 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 59 return configuration.frequency() > 0 && | |
| 60 configuration.frequency() <= | |
| 61 mojom::SensorConfiguration::kMaxAllowedFrequency; | |
| 62 } | |
| 63 | |
| 64 } // namespace device | |
| OLD | NEW |