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

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

Issue 2332903002: [sensors] [mac] Implement ambient light sensor for macOS (Closed)
Patch Set: More style fixes and build fixes 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/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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698