Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / device / usb / usb_device_handle.h
blob7098d6809ee8a1eb47845b23432c7e901c9e413b
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 DEVICE_USB_USB_DEVICE_HANDLE_H_
6 #define DEVICE_USB_USB_DEVICE_HANDLE_H_
8 #include <map>
9 #include <vector>
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/strings/string16.h"
14 #include "base/threading/thread_checker.h"
15 #include "device/usb/usb_descriptors.h"
16 #include "net/base/io_buffer.h"
18 namespace device {
20 class UsbDevice;
22 enum UsbTransferStatus {
23 USB_TRANSFER_COMPLETED = 0,
24 USB_TRANSFER_ERROR,
25 USB_TRANSFER_TIMEOUT,
26 USB_TRANSFER_CANCELLED,
27 USB_TRANSFER_STALLED,
28 USB_TRANSFER_DISCONNECT,
29 USB_TRANSFER_OVERFLOW,
30 USB_TRANSFER_LENGTH_SHORT,
33 typedef base::Callback<
34 void(UsbTransferStatus, scoped_refptr<net::IOBuffer>, size_t)>
35 UsbTransferCallback;
37 // UsbDeviceHandle class provides basic I/O related functionalities.
38 class UsbDeviceHandle : public base::RefCountedThreadSafe<UsbDeviceHandle> {
39 public:
40 enum TransferRequestType { STANDARD, CLASS, VENDOR, RESERVED };
41 enum TransferRecipient { DEVICE, INTERFACE, ENDPOINT, OTHER };
43 virtual scoped_refptr<UsbDevice> GetDevice() const = 0;
45 // Notifies UsbDevice to drop the reference of this object; cancels all the
46 // flying transfers.
47 // It is possible that the object has no other reference after this call. So
48 // if it is called using a raw pointer, it could be invalidated.
49 // The platform device handle will be closed when UsbDeviceHandle destructs.
50 virtual void Close() = 0;
52 // Device manipulation operations. These methods are blocking and must be
53 // called on FILE thread.
54 virtual bool SetConfiguration(int configuration_value) = 0;
55 virtual bool ClaimInterface(int interface_number) = 0;
56 virtual bool ReleaseInterface(int interface_number) = 0;
57 virtual bool SetInterfaceAlternateSetting(int interface_number,
58 int alternate_setting) = 0;
59 virtual bool ResetDevice() = 0;
61 // Gets the string descriptor with the given index from the device, or returns
62 // false. This method is blocking and must be called on the FILE thread.
63 virtual bool GetStringDescriptor(uint8 string_id, base::string16* string) = 0;
65 // Async IO. Can be called on any thread.
66 virtual void ControlTransfer(UsbEndpointDirection direction,
67 TransferRequestType request_type,
68 TransferRecipient recipient,
69 uint8 request,
70 uint16 value,
71 uint16 index,
72 net::IOBuffer* buffer,
73 size_t length,
74 unsigned int timeout,
75 const UsbTransferCallback& callback) = 0;
77 virtual void BulkTransfer(UsbEndpointDirection direction,
78 uint8 endpoint,
79 net::IOBuffer* buffer,
80 size_t length,
81 unsigned int timeout,
82 const UsbTransferCallback& callback) = 0;
84 virtual void InterruptTransfer(UsbEndpointDirection direction,
85 uint8 endpoint,
86 net::IOBuffer* buffer,
87 size_t length,
88 unsigned int timeout,
89 const UsbTransferCallback& callback) = 0;
91 virtual void IsochronousTransfer(UsbEndpointDirection direction,
92 uint8 endpoint,
93 net::IOBuffer* buffer,
94 size_t length,
95 unsigned int packets,
96 unsigned int packet_length,
97 unsigned int timeout,
98 const UsbTransferCallback& callback) = 0;
100 protected:
101 friend class base::RefCountedThreadSafe<UsbDeviceHandle>;
103 UsbDeviceHandle() {};
105 virtual ~UsbDeviceHandle() {};
107 DISALLOW_COPY_AND_ASSIGN(UsbDeviceHandle);
110 } // namespace device
112 #endif // DEVICE_USB_USB_DEVICE_HANDLE_H_