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 const scoped_refptr<base::SingleThreadTaskRunner>& | |
16 polling_thread_task_runner) | |
17 : PlatformSensor(type, std::move(mapping), provider), | |
18 polling_thread_task_runner_(polling_thread_task_runner), | |
19 ui_task_runner_(base::MessageLoop::current()->task_runner()) {} | |
20 | |
21 PlatformSensorMac::~PlatformSensorMac() { | |
22 timer_.reset(); | |
Mikhail
2016/09/16 16:23:54
won't it get reset automatically when deleted?
| |
23 } | |
24 | |
25 bool PlatformSensorMac::StartSensor( | |
26 const PlatformSensorConfiguration& configuration) { | |
27 polling_thread_task_runner_->PostTask( | |
28 FROM_HERE, base::Bind(&PlatformSensorMac::BeginPoll, | |
29 base::Unretained(this), configuration)); | |
30 return true; | |
31 } | |
32 | |
33 void PlatformSensorMac::BeginPoll( | |
34 const PlatformSensorConfiguration& configuration) { | |
Mikhail
2016/09/16 16:23:54
DCHECK to make sure this is a polling thread would
| |
35 timer_.reset(new base::RepeatingTimer()); | |
36 timer_->Start(FROM_HERE, base::TimeDelta::FromMicroseconds( | |
37 base::Time::kMicrosecondsPerSecond / | |
38 configuration.frequency()), | |
39 this, &PlatformSensorMac::UpdateReading); | |
40 } | |
41 | |
42 void PlatformSensorMac::StopSensor() { | |
43 polling_thread_task_runner_->PostTask( | |
44 FROM_HERE, | |
45 base::Bind(&PlatformSensorMac::StopPoll, base::Unretained(this))); | |
Mikhail
2016/09/16 16:23:54
base::Unretained(this) can lead to raise condition
| |
46 } | |
47 | |
48 void PlatformSensorMac::StopPoll() { | |
49 timer_.reset(); | |
50 } | |
51 | |
52 } // namespace device | |
OLD | NEW |