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/polling_platform_sensor.h" | |
6 | |
7 #include "base/message_loop/message_loop.h" | |
8 | |
9 namespace device { | |
10 | |
11 PollingPlatformSensor::Deleter::Deleter() = default; | |
12 PollingPlatformSensor::Deleter::~Deleter() = default; | |
13 | |
14 void PollingPlatformSensor::Deleter::operator()( | |
15 base::RepeatingTimer* timer) const { | |
16 DCHECK(task_runner_); | |
17 task_runner_->PostTask(FROM_HERE, base::Bind(&Deleter::destroy_timer, | |
18 base::Unretained(this), timer)); | |
19 } | |
20 | |
21 PollingPlatformSensor::PollingPlatformSensor( | |
22 mojom::SensorType type, | |
23 mojo::ScopedSharedBufferMapping mapping, | |
24 PlatformSensorProvider* provider, | |
25 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner) | |
26 : PlatformSensor(type, | |
27 std::move(mapping), | |
28 provider, | |
29 std::move(ipc_task_runner)), | |
30 polling_thread_task_runner_(base::MessageLoop::current()->task_runner()), | |
darktears
2016/10/10 16:27:14
This is deprecated. Use base::ThreadTaskRunnerHand
| |
31 weak_factory_(this) {} | |
32 | |
33 PollingPlatformSensor::~PollingPlatformSensor() = default; | |
34 | |
35 bool PollingPlatformSensor::StartSensor( | |
36 const PlatformSensorConfiguration& configuration) { | |
37 return polling_thread_task_runner_->PostTask( | |
38 FROM_HERE, base::Bind(&PollingPlatformSensor::BeginPoll, | |
39 weak_factory_.GetWeakPtr(), configuration)); | |
40 } | |
41 | |
42 void PollingPlatformSensor::BeginPoll( | |
43 const PlatformSensorConfiguration& configuration) { | |
44 timer_.reset(new base::RepeatingTimer()); | |
45 timer_.get_deleter().set_helper(polling_thread_task_runner_); | |
46 timer_->Start(FROM_HERE, base::TimeDelta::FromMicroseconds( | |
47 base::Time::kMicrosecondsPerSecond / | |
48 configuration.frequency()), | |
49 this, &PollingPlatformSensor::UpdateReading); | |
50 } | |
51 | |
52 void PollingPlatformSensor::StopSensor() { | |
53 polling_thread_task_runner_->PostTask( | |
54 FROM_HERE, base::Bind(&PollingPlatformSensor::StopPoll, this)); | |
55 } | |
56 | |
57 void PollingPlatformSensor::StopPoll() { | |
58 timer_->Stop(); | |
59 } | |
60 | |
61 } // namespace device | |
OLD | NEW |