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

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

Issue 2447973003: [sensors] [win] Implement ambient light sensor for Windows platform (Closed)
Patch Set: Fixes for review comments from Mikhail. Created 4 years, 1 month 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_PLATFORM_SENSOR_READER_WIN_H_
6 #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_WIN_H_
7
8 #include <SensorsApi.h>
9
10 #include "base/win/scoped_comptr.h"
11 #include "device/generic_sensor/public/interfaces/sensor.mojom.h"
12
13 namespace device {
14
15 class PlatformSensorConfiguration;
16 struct ReaderInitParams;
17 struct SensorReading;
18
19 // Generic class that uses ISensor interface to fetch sensor data. Used
20 // by PlatformSensorWin and delivers notifications via Client interface.
21 // Instances of this class must be created and destucted on sensor thread.
Mikhail 2016/10/26 13:35:31 nit: destucted on same thread. ?
Reilly Grant (use Gerrit) 2016/10/27 00:59:20 s/destucted/destructed/
shalamov 2016/10/27 13:51:07 Done.
shalamov 2016/10/27 13:51:08 Done.
22 class PlatformSensorReaderWin {
23 public:
24 // Client interface that can be used to receive notifications about sensor
25 // error or data change events.
26 class Client {
27 public:
28 virtual void OnReadingUpdated(const SensorReading& reading) = 0;
29 virtual void OnSensorError() = 0;
30
31 protected:
32 virtual ~Client() {}
33 };
34
35 static std::unique_ptr<PlatformSensorReaderWin> Create(
36 mojom::SensorType type,
37 base::win::ScopedComPtr<ISensorManager> sensor_manager);
38
39 // Following methods are thread safe.
40 void SetClient(Client* client);
41 unsigned long GetMinimalReportingIntervalMs() const;
42 mojom::ReportingMode GetReportingMode() const;
43 bool StartSensor(const PlatformSensorConfiguration& configuration);
44 void StopSensor();
45
46 // Must be destructed on sensor thread.
47 ~PlatformSensorReaderWin();
48
49 private:
50 PlatformSensorReaderWin(base::win::ScopedComPtr<ISensor> sensor,
51 std::unique_ptr<ReaderInitParams> params);
52
53 static base::win::ScopedComPtr<ISensor> GetSensorForType(
54 REFSENSOR_TYPE_ID sensor_type,
55 base::win::ScopedComPtr<ISensorManager> sensor_manager);
56
57 bool SetReportingInterval(const PlatformSensorConfiguration& configuration);
58 HRESULT SensorReadingChanged(ISensorDataReport& report,
59 SensorReading& reading) const;
60 void SensorError();
61
62 private:
63 friend class EventListener;
Reilly Grant (use Gerrit) 2016/10/27 00:59:20 nit: spaces between friends, fields and the DISALL
shalamov 2016/10/27 13:51:08 Done.
64 base::Lock lock_;
Reilly Grant (use Gerrit) 2016/10/27 00:59:19 Document why these fields (and which ones) must be
shalamov 2016/10/27 13:51:08 Yes. MTA allows to use COM interfaces from differe
65 bool sensor_active_;
66 Client* client_;
67 const std::unique_ptr<ReaderInitParams> init_params_;
68 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
69 base::win::ScopedComPtr<ISensor> sensor_;
70 scoped_refptr<EventListener> event_listener_;
71 DISALLOW_COPY_AND_ASSIGN(PlatformSensorReaderWin);
72 };
73
74 } // namespace device
75
76 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698