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

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

Issue 2332903002: [sensors] [mac] Implement ambient light sensor for macOS (Closed)
Patch Set: few more nits 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_PLATFORM_SENSOR_AMBIENT_LIGHT_SENSOR_MAC_H_
6 #define DEVICE_GENERIC_PLATFORM_SENSOR_AMBIENT_LIGHT_SENSOR_MAC_H_
7
8 #include <IOKit/IOKitLib.h>
9
10 #include "base/mac/scoped_ionotificationport_ref.h"
11 #include "base/mac/scoped_ioobject.h"
12 #include "device/generic_sensor/platform_sensor.h"
13
14 namespace base {
15 class SingleThreadTaskRunner;
16 }
17
18 namespace device {
19
20 // Implementation of PlatformSensor for macOS to query the ambient light sensor.
21 // This is a single instance object per browser process which is created by
22 // The singleton PlatformSensorProviderMac. If there are no clients, this
23 // instance is not created.
24 class PlatformSensorAmbientLightMac : public PlatformSensor {
25 public:
26 // Construct a platform sensor of |type| AMBIENT_LIGHT, given
27 // a buffer |mapping| to write the result back. |task_runner| is
28 // used to post the notification that the sensor reading has changed.
29 PlatformSensorAmbientLightMac(
30 mojom::SensorType type,
31 mojo::ScopedSharedBufferMapping mapping,
32 PlatformSensorProvider* provider,
33 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
34
35 mojom::ReportingMode GetReportingMode() override;
36 // Can only be called once, the first time or after a StopSensor call.
37 bool StartSensor(const PlatformSensorConfiguration& configuration) override;
38 void StopSensor() override;
39
40 protected:
41 ~PlatformSensorAmbientLightMac() override;
42 bool CheckSensorConfiguration(
43 const PlatformSensorConfiguration& configuration) override;
44 PlatformSensorConfiguration GetDefaultConfiguration() override;
45 void UpdateReading(uint64_t lux_values[2]);
46
47 private:
48 static void IOServiceCallback(void* context,
49 io_service_t service,
50 natural_t message_type,
51 void* message_argument);
52
53 // IOService representing the LMU sensor.
54 base::mac::ScopedIOObject<io_service_t> light_sensor_service_;
55 // Port used to get the notifications from the sensor.
56 base::mac::ScopedIONotificationPortRef light_sensor_port_;
57 // IO Object used to query the value of the sensor.
58 base::mac::ScopedIOObject<io_object_t> light_sensor_object_;
59 // IO Notifications created by IOServiceAddInterestNotification.
60 base::mac::ScopedIOObject<io_object_t> light_sensor_notification_;
61 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
62 double current_lux_;
63
64 DISALLOW_COPY_AND_ASSIGN(PlatformSensorAmbientLightMac);
65 };
66
67 } // namespace device
68
69 #endif // DEVICE_GENERIC_PLATFORM_SENSOR_AMBIENT_LIGHT_SENSOR_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698