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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
Index: device/generic_sensor/platform_sensor_reader_win.h
diff --git a/device/generic_sensor/platform_sensor_reader_win.h b/device/generic_sensor/platform_sensor_reader_win.h
new file mode 100644
index 0000000000000000000000000000000000000000..be5727b19edfce629ab535b2d3b9e0c9c65addad
--- /dev/null
+++ b/device/generic_sensor/platform_sensor_reader_win.h
@@ -0,0 +1,76 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_WIN_H_
+#define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_WIN_H_
+
+#include <SensorsApi.h>
+
+#include "base/win/scoped_comptr.h"
+#include "device/generic_sensor/public/interfaces/sensor.mojom.h"
+
+namespace device {
+
+class PlatformSensorConfiguration;
+struct ReaderInitParams;
+struct SensorReading;
+
+// Generic class that uses ISensor interface to fetch sensor data. Used
+// by PlatformSensorWin and delivers notifications via Client interface.
+// 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.
+class PlatformSensorReaderWin {
+ public:
+ // Client interface that can be used to receive notifications about sensor
+ // error or data change events.
+ class Client {
+ public:
+ virtual void OnReadingUpdated(const SensorReading& reading) = 0;
+ virtual void OnSensorError() = 0;
+
+ protected:
+ virtual ~Client() {}
+ };
+
+ static std::unique_ptr<PlatformSensorReaderWin> Create(
+ mojom::SensorType type,
+ base::win::ScopedComPtr<ISensorManager> sensor_manager);
+
+ // Following methods are thread safe.
+ void SetClient(Client* client);
+ unsigned long GetMinimalReportingIntervalMs() const;
+ mojom::ReportingMode GetReportingMode() const;
+ bool StartSensor(const PlatformSensorConfiguration& configuration);
+ void StopSensor();
+
+ // Must be destructed on sensor thread.
+ ~PlatformSensorReaderWin();
+
+ private:
+ PlatformSensorReaderWin(base::win::ScopedComPtr<ISensor> sensor,
+ std::unique_ptr<ReaderInitParams> params);
+
+ static base::win::ScopedComPtr<ISensor> GetSensorForType(
+ REFSENSOR_TYPE_ID sensor_type,
+ base::win::ScopedComPtr<ISensorManager> sensor_manager);
+
+ bool SetReportingInterval(const PlatformSensorConfiguration& configuration);
+ HRESULT SensorReadingChanged(ISensorDataReport& report,
+ SensorReading& reading) const;
+ void SensorError();
+
+ private:
+ 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.
+ 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
+ bool sensor_active_;
+ Client* client_;
+ const std::unique_ptr<ReaderInitParams> init_params_;
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+ base::win::ScopedComPtr<ISensor> sensor_;
+ scoped_refptr<EventListener> event_listener_;
+ DISALLOW_COPY_AND_ASSIGN(PlatformSensorReaderWin);
+};
+
+} // namespace device
+
+#endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_WIN_H_

Powered by Google App Engine
This is Rietveld 408576698