hid_service_linux.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 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_SERVICE_LINUX_H_
  5. #define SERVICES_DEVICE_HID_HID_SERVICE_LINUX_H_
  6. #include <memory>
  7. #include "base/compiler_specific.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 "build/build_config.h"
  12. #include "build/chromeos_buildflags.h"
  13. #include "services/device/hid/hid_device_info.h"
  14. #include "services/device/hid/hid_service.h"
  15. namespace device {
  16. class HidServiceLinux : public HidService {
  17. public:
  18. HidServiceLinux();
  19. HidServiceLinux(HidServiceLinux&) = delete;
  20. HidServiceLinux& operator=(HidServiceLinux&) = delete;
  21. ~HidServiceLinux() override;
  22. // HidService:
  23. void Connect(const std::string& device_id,
  24. bool allow_protected_reports,
  25. bool allow_fido_reports,
  26. ConnectCallback callback) override;
  27. base::WeakPtr<HidService> GetWeakPtr() override;
  28. private:
  29. struct ConnectParams;
  30. class BlockingTaskRunnerHelper;
  31. // These functions implement the process of locating, requesting access to and
  32. // opening a device. Because this operation crosses multiple threads these
  33. // functions are static and the necessary parameters are passed as a single
  34. // struct.
  35. #if BUILDFLAG(IS_CHROMEOS_ASH)
  36. static void OnPathOpenComplete(std::unique_ptr<ConnectParams> params,
  37. base::ScopedFD fd);
  38. static void OnPathOpenError(const std::string& device_path,
  39. ConnectCallback callback,
  40. const std::string& error_name,
  41. const std::string& error_message);
  42. #else
  43. static void OpenOnBlockingThread(std::unique_ptr<ConnectParams> params);
  44. #endif
  45. static void FinishOpen(std::unique_ptr<ConnectParams> params);
  46. const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
  47. // |helper_| lives on the sequence |blocking_task_runner_| posts to and holds
  48. // a weak reference back to the service that owns it.
  49. std::unique_ptr<BlockingTaskRunnerHelper, base::OnTaskRunnerDeleter> helper_;
  50. base::WeakPtrFactory<HidServiceLinux> weak_factory_{this};
  51. };
  52. } // namespace device
  53. #endif // SERVICES_DEVICE_HID_HID_SERVICE_LINUX_H_