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_polling_mac.h" |
| 6 |
| 7 #include "device/generic_sensor/platform_sensor_mac.h" |
| 8 |
| 9 namespace device { |
| 10 |
| 11 SensorsPollingThreadMac::SensorsPollingThreadMac(const char* name) |
| 12 : base::Thread(name) {} |
| 13 |
| 14 SensorsPollingThreadMac::~SensorsPollingThreadMac() = default; |
| 15 |
| 16 void SensorsPollingThreadMac::BeginPollingSensor( |
| 17 PlatformSensorMac* sensor, |
| 18 const PlatformSensorConfiguration& configuration) { |
| 19 auto it = sensors_.find(sensor); |
| 20 if (it != sensors_.end()) |
| 21 return; |
| 22 |
| 23 std::unique_ptr<base::RepeatingTimer> timer(new base::RepeatingTimer); |
| 24 timer->Start(FROM_HERE, base::TimeDelta::FromMicroseconds( |
| 25 base::Time::kMicrosecondsPerSecond / |
| 26 configuration.frequency()), |
| 27 sensor, &PlatformSensorMac::UpdateReading); |
| 28 sensors_.insert({sensor, std::move(timer)}); |
| 29 } |
| 30 |
| 31 void SensorsPollingThreadMac::StopPollingSensor(PlatformSensorMac* sensor) { |
| 32 auto it = sensors_.find(sensor); |
| 33 if (it == sensors_.end()) |
| 34 return; |
| 35 |
| 36 it->second.reset(); |
| 37 sensors_.erase(it); |
| 38 } |
| 39 |
| 40 } // namespace device |
OLD | NEW |