Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(400)

Side by Side Diff: device/generic_sensor/polling_platform_sensor.cc

Issue 2370343002: [sensors] Ambient light sensor implementation for ChromeOS and Linux. (Closed)
Patch Set: rebased on top of Mihail's cl Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/generic_sensor/polling_platform_sensor.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « device/generic_sensor/polling_platform_sensor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698