Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: device/usb/usb_device.h

Issue 980023002: Move device/usb classes from the FILE thread to UI thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef DEVICE_USB_USB_DEVICE_H_ 5 #ifndef DEVICE_USB_USB_DEVICE_H_
6 #define DEVICE_USB_USB_DEVICE_H_ 6 #define DEVICE_USB_USB_DEVICE_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 12
13 namespace device { 13 namespace device {
14 14
15 class UsbDeviceHandle; 15 class UsbDeviceHandle;
16 struct UsbConfigDescriptor; 16 struct UsbConfigDescriptor;
17 17
18 // A UsbDevice object represents a detected USB device, providing basic 18 // A UsbDevice object represents a detected USB device, providing basic
19 // information about it. For further manipulation of the device, a 19 // information about it. Methods other than simple property accessors must be
20 // UsbDeviceHandle must be created from Open() method. 20 // called from the thread on which this object was created. For further
21 // manipulation of the device, a UsbDeviceHandle must be created from Open()
22 // method.
21 class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> { 23 class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> {
22 public: 24 public:
25 typedef base::Callback<void(scoped_refptr<UsbDeviceHandle>)> OpenCallback;
Ken Rockot(use gerrit already) 2015/04/07 22:09:43 nit: Please use aliases instead of typedefs
Reilly Grant (use Gerrit) 2015/04/08 21:39:03 Done.
26
23 // Accessors to basic information. 27 // Accessors to basic information.
24 uint16 vendor_id() const { return vendor_id_; } 28 uint16 vendor_id() const { return vendor_id_; }
25 uint16 product_id() const { return product_id_; } 29 uint16 product_id() const { return product_id_; }
26 uint32 unique_id() const { return unique_id_; } 30 uint32 unique_id() const { return unique_id_; }
31 const base::string16& manufacturer_string() const {
32 return manufacturer_string_;
33 }
34 const base::string16& product_string() const { return product_string_; }
35 const base::string16& serial_number() const { return serial_number_; }
27 36
28 #if defined(OS_CHROMEOS) 37 #if defined(OS_CHROMEOS)
29 // On ChromeOS, if an interface of a claimed device is not claimed, the 38 // On ChromeOS, if an interface of a claimed device is not claimed, the
30 // permission broker can change the owner of the device so that the unclaimed 39 // permission broker can change the owner of the device so that the unclaimed
31 // interfaces can be used. If this argument is missing, permission broker will 40 // interfaces can be used. If this argument is missing, permission broker will
32 // not be used and this method fails if the device is claimed. 41 // not be used and this method fails if the device is claimed.
33 virtual void RequestUsbAccess( 42 virtual void RequestUsbAccess(
34 int interface_id, 43 int interface_id,
35 const base::Callback<void(bool success)>& callback) = 0; 44 const base::Callback<void(bool success)>& callback) = 0;
36 #endif // OS_CHROMEOS 45 #endif // OS_CHROMEOS
37 46
38 // Creates a UsbDeviceHandle for further manipulation. 47 // Creates a UsbDeviceHandle for further manipulation.
39 // Blocking method. Must be called on FILE thread. 48 virtual void Open(const OpenCallback& callback) = 0;
40 virtual scoped_refptr<UsbDeviceHandle> Open() = 0;
41 49
42 // Explicitly closes a device handle. This method will be automatically called 50 // Explicitly closes a device handle. This method will be automatically called
43 // by the destructor of a UsbDeviceHandle as well. 51 // by the destructor of a UsbDeviceHandle as well.
44 // Closing a closed handle is a safe
45 // Blocking method. Must be called on FILE thread.
46 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) = 0; 52 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) = 0;
47 53
48 // Gets the UsbConfigDescriptor for the active device configuration or nullptr 54 // Gets the UsbConfigDescriptor for the active device configuration or nullptr
49 // if the device is unconfigured. 55 // if the device is unconfigured.
50 // Blocking method. Must be called on FILE thread.
51 virtual const UsbConfigDescriptor* GetConfiguration() = 0; 56 virtual const UsbConfigDescriptor* GetConfiguration() = 0;
52 57
53 // Gets the manufacturer string of the device, or false and an empty
54 // string. This is a blocking method and must be called on FILE thread.
55 // TODO(reillyg): Make this available from the UI thread. crbug.com/427985
56 virtual bool GetManufacturer(base::string16* manufacturer) = 0;
57
58 // Gets the product string of the device, or returns false and an empty
59 // string. This is a blocking method and must be called on FILE thread.
60 // TODO(reillyg): Make this available from the UI thread. crbug.com/427985
61 virtual bool GetProduct(base::string16* product) = 0;
62
63 // Gets the serial number string of the device, or returns false and an empty
64 // string. This is a blocking method and must be called on FILE thread.
65 // TODO(reillyg): Make this available from the UI thread. crbug.com/427985
66 virtual bool GetSerialNumber(base::string16* serial) = 0;
67
68 protected: 58 protected:
69 UsbDevice(uint16 vendor_id, uint16 product_id, uint32 unique_id) 59 UsbDevice(uint16 vendor_id,
70 : vendor_id_(vendor_id), product_id_(product_id), unique_id_(unique_id) {} 60 uint16 product_id,
71 virtual ~UsbDevice() {} 61 uint32 unique_id,
62 const base::string16& manufacturer_string,
63 const base::string16& product_string,
64 const base::string16& serial_number);
65 virtual ~UsbDevice();
72 66
73 private: 67 private:
74 friend class base::RefCountedThreadSafe<UsbDevice>; 68 friend class base::RefCountedThreadSafe<UsbDevice>;
75 69
76 const uint16 vendor_id_; 70 const uint16 vendor_id_;
77 const uint16 product_id_; 71 const uint16 product_id_;
78 const uint32 unique_id_; 72 const uint32 unique_id_;
73 const base::string16 manufacturer_string_;
74 const base::string16 product_string_;
75 const base::string16 serial_number_;
79 76
80 DISALLOW_COPY_AND_ASSIGN(UsbDevice); 77 DISALLOW_COPY_AND_ASSIGN(UsbDevice);
81 }; 78 };
82 79
83 } // namespace device 80 } // namespace device
84 81
85 #endif // DEVICE_USB_USB_DEVICE_H_ 82 #endif // DEVICE_USB_USB_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698