+ Fix cloud sprite clipping on 2x
[chromium-blink-merge.git] / device / usb / usb_device.h
blob7ea964cce57ad0dab217f23e6cfe31459c503dff
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_H_
6 #define DEVICE_USB_USB_DEVICE_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/observer_list.h"
12 #include "base/strings/string16.h"
14 namespace device {
16 class UsbDeviceHandle;
17 struct UsbConfigDescriptor;
19 // A UsbDevice object represents a detected USB device, providing basic
20 // information about it. For further manipulation of the device, a
21 // UsbDeviceHandle must be created from Open() method.
22 class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> {
23 public:
24 class Observer {
25 public:
26 virtual void OnDisconnect(scoped_refptr<UsbDevice> device) = 0;
29 // Accessors to basic information.
30 uint16 vendor_id() const { return vendor_id_; }
31 uint16 product_id() const { return product_id_; }
32 uint32 unique_id() const { return unique_id_; }
34 #if defined(OS_CHROMEOS)
35 // On ChromeOS, if an interface of a claimed device is not claimed, the
36 // permission broker can change the owner of the device so that the unclaimed
37 // interfaces can be used. If this argument is missing, permission broker will
38 // not be used and this method fails if the device is claimed.
39 virtual void RequestUsbAccess(
40 int interface_id,
41 const base::Callback<void(bool success)>& callback) = 0;
42 #endif // OS_CHROMEOS
44 // Creates a UsbDeviceHandle for further manipulation.
45 // Blocking method. Must be called on FILE thread.
46 virtual scoped_refptr<UsbDeviceHandle> Open() = 0;
48 // Explicitly closes a device handle. This method will be automatically called
49 // by the destructor of a UsbDeviceHandle as well.
50 // Closing a closed handle is a safe
51 // Blocking method. Must be called on FILE thread.
52 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) = 0;
54 // Gets the UsbConfigDescriptor for the active device configuration.
55 // Blocking method. Must be called on FILE thread.
56 virtual const UsbConfigDescriptor& GetConfiguration() = 0;
58 // Gets the manufacturer string of the device, or returns false.
59 // Blocking method. Must be called on FILE thread.
60 virtual bool GetManufacturer(base::string16* manufacturer) = 0;
62 // Gets the product string of the device, or returns false.
63 // Blocking method. Must be called on FILE thread.
64 virtual bool GetProduct(base::string16* product) = 0;
66 // Gets the serial number string of the device, or returns false.
67 // Blocking method. Must be called on FILE thread.
68 virtual bool GetSerialNumber(base::string16* serial) = 0;
70 void AddObserver(Observer* obs) { observer_list_.AddObserver(obs); }
71 void RemoveObserver(Observer* obs) { observer_list_.RemoveObserver(obs); }
73 protected:
74 UsbDevice(uint16 vendor_id, uint16 product_id, uint32 unique_id);
75 virtual ~UsbDevice();
77 void NotifyDisconnect();
79 private:
80 friend class base::RefCountedThreadSafe<UsbDevice>;
82 const uint16 vendor_id_;
83 const uint16 product_id_;
84 const uint32 unique_id_;
86 ObserverList<Observer> observer_list_;
88 DISALLOW_COPY_AND_ASSIGN(UsbDevice);
91 } // namespace device
93 #endif // DEVICE_USB_USB_DEVICE_H_