usb_device_linux.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_USB_USB_DEVICE_LINUX_H_
  5. #define SERVICES_DEVICE_USB_USB_DEVICE_LINUX_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include <string>
  9. #include <utility>
  10. #include "base/files/scoped_file.h"
  11. #include "base/sequence_checker.h"
  12. #include "build/build_config.h"
  13. #include "services/device/usb/usb_device.h"
  14. namespace base {
  15. class SequencedTaskRunner;
  16. }
  17. namespace device {
  18. struct UsbDeviceDescriptor;
  19. class UsbDeviceLinux : public UsbDevice {
  20. public:
  21. UsbDeviceLinux(const UsbDeviceLinux&) = delete;
  22. UsbDeviceLinux& operator=(const UsbDeviceLinux&) = delete;
  23. // UsbDevice implementation:
  24. #if BUILDFLAG(IS_CHROMEOS)
  25. void CheckUsbAccess(ResultCallback callback) override;
  26. #endif // BUILDFLAG(IS_CHROMEOS)
  27. void Open(OpenCallback callback) override;
  28. const std::string& device_path() const { return device_path_; }
  29. // This function is used during enumeration only. The values must not
  30. // change during the object's lifetime.
  31. void set_webusb_landing_page(const GURL& url) {
  32. device_info_->webusb_landing_page = url;
  33. }
  34. protected:
  35. friend class UsbServiceLinux;
  36. // Called by UsbServiceLinux only.
  37. UsbDeviceLinux(const std::string& device_path,
  38. std::unique_ptr<UsbDeviceDescriptor> descriptor);
  39. ~UsbDeviceLinux() override;
  40. private:
  41. #if BUILDFLAG(IS_CHROMEOS)
  42. void OnOpenRequestComplete(OpenCallback callback,
  43. base::ScopedFD fd,
  44. const std::string& client_id,
  45. base::ScopedFD lifeline_fd);
  46. void OnOpenRequestError(OpenCallback callback,
  47. const std::string& error_name,
  48. const std::string& error_message);
  49. #else
  50. void OpenOnBlockingThread(
  51. OpenCallback callback,
  52. scoped_refptr<base::SequencedTaskRunner> task_runner,
  53. scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
  54. #endif // BUILDFLAG(IS_CHROMEOS)
  55. void Opened(base::ScopedFD fd,
  56. base::ScopedFD lifeline_fd,
  57. const std::string& client_id,
  58. OpenCallback callback,
  59. scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
  60. SEQUENCE_CHECKER(sequence_checker_);
  61. const std::string device_path_;
  62. };
  63. } // namespace device
  64. #endif // SERVICES_DEVICE_USB_USB_DEVICE_LINUX_H_