platform_sensor_win.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #ifndef SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_WIN_H_
  5. #define SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_WIN_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "base/memory/weak_ptr.h"
  8. #include "services/device/generic_sensor/platform_sensor.h"
  9. #include "services/device/generic_sensor/platform_sensor_reader_win.h"
  10. namespace base {
  11. class SingleThreadTaskRunner;
  12. }
  13. namespace device {
  14. // Implementation of PlatformSensor interface for Windows platform. Instance
  15. // of PlatformSensorWin is bound to IPC thread where PlatformSensorProvider is
  16. // running and communication with Windows platform sensor is done through
  17. // PlatformSensorReaderWinBase |sensor_reader_| interface which is bound to
  18. // sensor thread and communicates with PlatformSensorWin using
  19. // PlatformSensorReaderWinBase::Client interface. The error and data change
  20. // events are forwarded to IPC task runner.
  21. class PlatformSensorWin final : public PlatformSensor,
  22. public PlatformSensorReaderWinBase::Client {
  23. public:
  24. PlatformSensorWin(
  25. mojom::SensorType type,
  26. SensorReadingSharedBuffer* reading_buffer,
  27. PlatformSensorProvider* provider,
  28. scoped_refptr<base::SingleThreadTaskRunner> sensor_thread_runner,
  29. std::unique_ptr<PlatformSensorReaderWinBase> sensor_reader);
  30. PlatformSensorWin(const PlatformSensorWin&) = delete;
  31. PlatformSensorWin& operator=(const PlatformSensorWin&) = delete;
  32. PlatformSensorConfiguration GetDefaultConfiguration() override;
  33. mojom::ReportingMode GetReportingMode() override;
  34. double GetMaximumSupportedFrequency() override;
  35. // PlatformSensorReaderWinBase::Client interface implementation.
  36. void OnReadingUpdated(const SensorReading& reading) override;
  37. void OnSensorError() override;
  38. protected:
  39. ~PlatformSensorWin() override;
  40. // PlatformSensor interface implementation.
  41. bool StartSensor(const PlatformSensorConfiguration& configuration) override;
  42. void StopSensor() override;
  43. bool CheckSensorConfiguration(
  44. const PlatformSensorConfiguration& configuration) override;
  45. private:
  46. scoped_refptr<base::SingleThreadTaskRunner> sensor_thread_runner_;
  47. const raw_ptr<PlatformSensorReaderWinBase> sensor_reader_;
  48. base::WeakPtrFactory<PlatformSensorWin> weak_factory_{this};
  49. };
  50. } // namespace device
  51. #endif // SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_WIN_H_