usb_device_impl.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_IMPL_H_
  5. #define SERVICES_DEVICE_USB_USB_DEVICE_IMPL_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include <string>
  9. #include <utility>
  10. #include "base/callback.h"
  11. #include "base/files/scoped_file.h"
  12. #include "base/sequence_checker.h"
  13. #include "build/build_config.h"
  14. #include "services/device/usb/scoped_libusb_device_ref.h"
  15. #include "services/device/usb/usb_descriptors.h"
  16. #include "services/device/usb/usb_device.h"
  17. struct libusb_device_descriptor;
  18. namespace base {
  19. class SequencedTaskRunner;
  20. }
  21. namespace device {
  22. class ScopedLibusbDeviceHandle;
  23. class UsbDeviceHandleImpl;
  24. class UsbDeviceImpl : public UsbDevice {
  25. public:
  26. UsbDeviceImpl(ScopedLibusbDeviceRef platform_device,
  27. const libusb_device_descriptor& descriptor);
  28. UsbDeviceImpl(const UsbDeviceImpl&) = delete;
  29. UsbDeviceImpl& operator=(const UsbDeviceImpl&) = delete;
  30. // UsbDevice implementation:
  31. void Open(OpenCallback callback) override;
  32. // These functions are used during enumeration only. The values must not
  33. // change during the object's lifetime.
  34. void set_manufacturer_string(const std::u16string& value) {
  35. device_info_->manufacturer_name = value;
  36. }
  37. void set_product_string(const std::u16string& value) {
  38. device_info_->product_name = value;
  39. }
  40. void set_serial_number(const std::u16string& value) {
  41. device_info_->serial_number = value;
  42. }
  43. void set_webusb_landing_page(const GURL& url) {
  44. device_info_->webusb_landing_page = url;
  45. }
  46. libusb_device* platform_device() const { return platform_device_.get(); }
  47. protected:
  48. friend class UsbServiceImpl;
  49. friend class UsbDeviceHandleImpl;
  50. ~UsbDeviceImpl() override;
  51. void ReadAllConfigurations();
  52. void RefreshActiveConfiguration();
  53. // Called only by UsbServiceImpl.
  54. void set_visited(bool visited) { visited_ = visited; }
  55. bool was_visited() const { return visited_; }
  56. private:
  57. void GetAllConfigurations();
  58. void OpenOnBlockingThread(
  59. OpenCallback callback,
  60. scoped_refptr<base::TaskRunner> task_runner,
  61. scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
  62. void Opened(ScopedLibusbDeviceHandle platform_handle,
  63. OpenCallback callback,
  64. scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
  65. SEQUENCE_CHECKER(sequence_checker_);
  66. bool visited_ = false;
  67. const ScopedLibusbDeviceRef platform_device_;
  68. };
  69. } // namespace device
  70. #endif // SERVICES_DEVICE_USB_USB_DEVICE_IMPL_H_