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_mac.h" | |
| 6 | |
| 7 #include "base/message_loop/message_loop.h" | |
| 8 | |
| 9 namespace device { | |
| 10 | |
| 11 PlatformSensorMac::PlatformSensorMac( | |
| 12 mojom::SensorType type, | |
| 13 mojo::ScopedSharedBufferMapping mapping, | |
| 14 PlatformSensorProvider* provider, | |
| 15 scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner) | |
| 16 : PlatformSensor(type, std::move(mapping), provider), | |
| 17 polling_thread_task_runner_(polling_thread_task_runner), | |
|
Mikhail
2016/09/19 06:25:18
nit: polling_thread_task_runner_(std::move(polling
| |
| 18 ui_task_runner_(base::MessageLoop::current()->task_runner()) {} | |
| 19 | |
| 20 PlatformSensorMac::~PlatformSensorMac() = default; | |
| 21 | |
| 22 bool PlatformSensorMac::StartSensor( | |
| 23 const PlatformSensorConfiguration& configuration) { | |
| 24 polling_thread_task_runner_->PostTask( | |
| 25 FROM_HERE, | |
| 26 base::Bind(&PlatformSensorMac::BeginPoll, this, configuration)); | |
| 27 return true; | |
| 28 } | |
| 29 | |
| 30 void PlatformSensorMac::BeginPoll( | |
| 31 const PlatformSensorConfiguration& configuration) { | |
| 32 DCHECK(polling_thread_task_runner_->BelongsToCurrentThread()); | |
| 33 timer_.reset(new base::RepeatingTimer()); | |
| 34 timer_->Start(FROM_HERE, base::TimeDelta::FromMicroseconds( | |
| 35 base::Time::kMicrosecondsPerSecond / | |
| 36 configuration.frequency()), | |
| 37 this, &PlatformSensorMac::UpdateReading); | |
| 38 } | |
| 39 | |
| 40 void PlatformSensorMac::StopSensor() { | |
| 41 polling_thread_task_runner_->PostTask( | |
| 42 FROM_HERE, base::Bind(&PlatformSensorMac::StopPoll, this)); | |
| 43 } | |
| 44 | |
| 45 void PlatformSensorMac::StopPoll() { | |
| 46 DCHECK(polling_thread_task_runner_->BelongsToCurrentThread()); | |
| 47 timer_.reset(); | |
| 48 } | |
| 49 | |
| 50 } // namespace device | |
| OLD | NEW |