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

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

Issue 2332903002: [sensors] [mac] Implement ambient light sensor for macOS (Closed)
Patch Set: Fix comments from Mikhail Created 4 years, 3 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
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::PollingPlatformSensor(
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_(std::move(polling_thread_task_runner)),
18 ui_task_runner_(base::MessageLoop::current()->task_runner()) {}
19
20 PollingPlatformSensor::~PollingPlatformSensor() = default;
21
22 bool PollingPlatformSensor::StartSensor(
23 const PlatformSensorConfiguration& configuration) {
24 polling_thread_task_runner_->PostTask(
25 FROM_HERE,
26 base::Bind(&PollingPlatformSensor::BeginPoll, this, configuration));
27 return true;
28 }
29
30 void PollingPlatformSensor::BeginPoll(
31 const PlatformSensorConfiguration& configuration) {
32 DCHECK(polling_thread_task_runner_->BelongsToCurrentThread());
33 timer_.Start(FROM_HERE, base::TimeDelta::FromMicroseconds(
maksims (do not use this acc) 2016/09/21 08:20:14 You cannot create timer on one thread and kill it
34 base::Time::kMicrosecondsPerSecond /
35 configuration.frequency()),
36 this, &PollingPlatformSensor::UpdateReading);
37 }
38
39 void PollingPlatformSensor::StopSensor() {
40 polling_thread_task_runner_->PostTask(
41 FROM_HERE, base::Bind(&PollingPlatformSensor::StopPoll, this));
42 }
43
44 void PollingPlatformSensor::StopPoll() {
45 DCHECK(polling_thread_task_runner_->BelongsToCurrentThread());
46 timer_.Stop();
47 }
48
49 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698