Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / components / usb_service / usb_device_impl.h
blobe27a692853b1c6a740ff7566934a2e501e801103
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.
5 #ifndef COMPONENTS_USB_SERVICE_USB_DEVICE_IMPL_H_
6 #define COMPONENTS_USB_SERVICE_USB_DEVICE_IMPL_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/threading/thread_checker.h"
13 #include "components/usb_service/usb_device.h"
15 struct libusb_device;
16 struct libusb_config_descriptor;
18 namespace usb_service {
20 class UsbDeviceHandleImpl;
21 class UsbContext;
23 typedef libusb_device* PlatformUsbDevice;
24 typedef libusb_config_descriptor* PlatformUsbConfigDescriptor;
26 class UsbDeviceImpl : public UsbDevice {
27 public:
28 // UsbDevice implementation:
29 #if defined(OS_CHROMEOS)
30 virtual void RequestUsbAccess(
31 int interface_id,
32 const base::Callback<void(bool success)>& callback) OVERRIDE;
33 #endif // OS_CHROMEOS
34 virtual scoped_refptr<UsbDeviceHandle> Open() OVERRIDE;
35 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) OVERRIDE;
36 virtual scoped_refptr<UsbConfigDescriptor> ListInterfaces() OVERRIDE;
38 protected:
39 friend class UsbServiceImpl;
41 // Called by UsbServiceImpl only;
42 UsbDeviceImpl(scoped_refptr<UsbContext> context,
43 PlatformUsbDevice platform_device,
44 uint16 vendor_id,
45 uint16 product_id,
46 uint32 unique_id);
48 virtual ~UsbDeviceImpl();
50 // Called only be UsbService.
51 void OnDisconnect();
53 private:
54 base::ThreadChecker thread_checker_;
55 PlatformUsbDevice platform_device_;
57 // Retain the context so that it will not be released before UsbDevice.
58 scoped_refptr<UsbContext> context_;
60 // Opened handles.
61 typedef std::vector<scoped_refptr<UsbDeviceHandleImpl> > HandlesVector;
62 HandlesVector handles_;
64 DISALLOW_COPY_AND_ASSIGN(UsbDeviceImpl);
67 } // namespace usb_service
69 #endif // COMPONENTS_USB_SERVICE_USB_DEVICE_IMPL_H_