usb_context.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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_CONTEXT_H_
  5. #define SERVICES_DEVICE_USB_USB_CONTEXT_H_
  6. #include <memory>
  7. #include "base/memory/ref_counted.h"
  8. #include "base/threading/thread_checker.h"
  9. struct libusb_context;
  10. namespace device {
  11. typedef libusb_context* PlatformUsbContext;
  12. // Ref-counted wrapper for libusb_context*.
  13. // It also manages the life-cycle of UsbEventHandler.
  14. // It is a blocking operation to delete UsbContext.
  15. // Destructor must be called on FILE thread.
  16. class UsbContext : public base::RefCountedThreadSafe<UsbContext> {
  17. public:
  18. explicit UsbContext(PlatformUsbContext context);
  19. UsbContext(const UsbContext&) = delete;
  20. UsbContext& operator=(const UsbContext&) = delete;
  21. PlatformUsbContext context() const { return context_; }
  22. protected:
  23. friend class base::RefCountedThreadSafe<UsbContext>;
  24. virtual ~UsbContext();
  25. private:
  26. class UsbEventHandler;
  27. PlatformUsbContext context_;
  28. std::unique_ptr<UsbEventHandler> event_handler_;
  29. };
  30. } // namespace device
  31. #endif // SERVICES_DEVICE_USB_USB_CONTEXT_H_