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

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

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
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 #ifndef DEVICE_GENERIC_SENSOR_POLLING_PLATFORM_SENSOR_H_
6 #define DEVICE_GENERIC_SENSOR_POLLING_PLATFORM_SENSOR_H_
7
8 #include "device/generic_sensor/platform_sensor.h"
9
10 #include "base/timer/timer.h"
11
12 namespace base {
13 class SingleThreadTaskRunner;
14 }
15
16 namespace device {
17
18 class PollingPlatformSensor : public PlatformSensor {
19 public:
20 class Deleter {
21 public:
22 Deleter();
23 ~Deleter();
24
25 void operator()(base::RepeatingTimer* timer) const;
26
27 void set_helper(scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
28 task_runner_ = task_runner;
29 }
30
31 private:
32 void destroy_timer(base::RepeatingTimer* timer) const { delete (timer); }
33
34 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
35 };
36
37 PollingPlatformSensor(
38 mojom::SensorType type,
39 mojo::ScopedSharedBufferMapping mapping,
40 PlatformSensorProvider* provider,
41 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
42
43 virtual void UpdateReading() = 0;
44
45 protected:
46 ~PollingPlatformSensor() override;
47 bool StartSensor(const PlatformSensorConfiguration& configuration) override;
48 void StopSensor() override;
49 scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner_;
50
51 private:
52 void BeginPoll(const PlatformSensorConfiguration& configuration);
53 void StopPoll();
54 void OnStop();
55
56 std::unique_ptr<base::RepeatingTimer, PollingPlatformSensor::Deleter> timer_;
57 base::WeakPtrFactory<PollingPlatformSensor> weak_factory_;
58
59 DISALLOW_COPY_AND_ASSIGN(PollingPlatformSensor);
60 };
61
62 } // namespace device
63
64 #endif // DEVICE_GENERIC_SENSOR_POLLING_PLATFORM_SENSOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698