Fix invalid cast in AppCacheGroup::AddUpdateObserver.
[chromium-blink-merge.git] / device / usb / usb_device.h
blob21676b64b2ff015c6a48c7a14be6128ec86e2929
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 <vector>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/strings/string16.h"
14 #include "device/usb/usb_descriptors.h"
16 namespace device {
18 class UsbDeviceHandle;
20 // A UsbDevice object represents a detected USB device, providing basic
21 // information about it. Methods other than simple property accessors must be
22 // called from the thread on which this object was created. For further
23 // manipulation of the device, a UsbDeviceHandle must be created from Open()
24 // method.
25 class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> {
26 public:
27 using OpenCallback = base::Callback<void(scoped_refptr<UsbDeviceHandle>)>;
28 using ResultCallback = base::Callback<void(bool success)>;
30 // A unique identifier which remains stable for the lifetime of this device
31 // object (i.e., until the device is unplugged or the USB service dies.)
32 const std::string& guid() const { return guid_; }
34 // Accessors to basic information.
35 uint16 vendor_id() const { return vendor_id_; }
36 uint16 product_id() const { return product_id_; }
37 const base::string16& manufacturer_string() const {
38 return manufacturer_string_;
40 const base::string16& product_string() const { return product_string_; }
41 const base::string16& serial_number() const { return serial_number_; }
43 // On ChromeOS the permission_broker service is used to change the ownership
44 // of USB device nodes so that Chrome can open them. On other platforms these
45 // functions are no-ops and always return true.
46 virtual void CheckUsbAccess(const ResultCallback& callback);
48 // Creates a UsbDeviceHandle for further manipulation.
49 virtual void Open(const OpenCallback& callback) = 0;
51 // Explicitly closes a device handle. This method will be automatically called
52 // by the destructor of a UsbDeviceHandle as well.
53 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) = 0;
55 // Gets the UsbConfigDescriptor for the active device configuration or nullptr
56 // if the device is unconfigured.
57 virtual const UsbConfigDescriptor* GetActiveConfiguration() = 0;
59 // Gets all of the device's UsbConfigDescriptors.
60 const std::vector<UsbConfigDescriptor>& configurations() {
61 return configurations_;
64 protected:
65 UsbDevice(uint16 vendor_id,
66 uint16 product_id,
67 const base::string16& manufacturer_string,
68 const base::string16& product_string,
69 const base::string16& serial_number);
70 virtual ~UsbDevice();
72 // These members must be mutable by subclasses as necessary during device
73 // enumeration. To preserve the thread safety of this object they must remain
74 // constant afterwards.
75 base::string16 manufacturer_string_;
76 base::string16 product_string_;
77 base::string16 serial_number_;
79 // All of the device's configuration descriptors.
80 std::vector<UsbConfigDescriptor> configurations_;
82 private:
83 friend class base::RefCountedThreadSafe<UsbDevice>;
85 const std::string guid_;
86 const uint16 vendor_id_;
87 const uint16 product_id_;
89 DISALLOW_COPY_AND_ASSIGN(UsbDevice);
92 } // namespace device
94 #endif // DEVICE_USB_USB_DEVICE_H_