hid_connection_linux.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright (c) 2014 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_HID_HID_CONNECTION_LINUX_H_
  5. #define SERVICES_DEVICE_HID_HID_CONNECTION_LINUX_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include "base/files/scoped_file.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "base/task/sequenced_task_runner.h"
  11. #include "services/device/hid/hid_connection.h"
  12. namespace base {
  13. class SequencedTaskRunner;
  14. }
  15. namespace device {
  16. class HidConnectionLinux : public HidConnection {
  17. public:
  18. HidConnectionLinux(
  19. scoped_refptr<HidDeviceInfo> device_info,
  20. base::ScopedFD fd,
  21. scoped_refptr<base::SequencedTaskRunner> blocking_task_runner,
  22. bool allow_protected_reports,
  23. bool allow_fido_reports);
  24. HidConnectionLinux(HidConnectionLinux&) = delete;
  25. HidConnectionLinux& operator=(HidConnectionLinux&) = delete;
  26. private:
  27. friend class base::RefCountedThreadSafe<HidConnectionLinux>;
  28. class BlockingTaskRunnerHelper;
  29. ~HidConnectionLinux() override;
  30. // HidConnection implementation.
  31. void PlatformClose() override;
  32. void PlatformWrite(scoped_refptr<base::RefCountedBytes> buffer,
  33. WriteCallback callback) override;
  34. void PlatformGetFeatureReport(uint8_t report_id,
  35. ReadCallback callback) override;
  36. void PlatformSendFeatureReport(scoped_refptr<base::RefCountedBytes> buffer,
  37. WriteCallback callback) override;
  38. // |helper_| lives on the sequence to which |blocking_task_runner_| posts
  39. // tasks so all calls must be posted there including this object's
  40. // destruction.
  41. std::unique_ptr<BlockingTaskRunnerHelper, base::OnTaskRunnerDeleter> helper_;
  42. const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
  43. base::WeakPtrFactory<HidConnectionLinux> weak_factory_{this};
  44. };
  45. } // namespace device
  46. #endif // SERVICES_DEVICE_HID_HID_CONNECTION_LINUX_H_