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

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: Add more thread assertions. 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
« no previous file with comments | « device/usb/usb_context.cc ('k') | device/usb/usb_device.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:
23 typedef base::Callback<void(bool success)> ResultCallback; 25 using OpenCallback = base::Callback<void(scoped_refptr<UsbDeviceHandle>)>;
26 using ResultCallback = base::Callback<void(bool success)>;
24 27
25 // Accessors to basic information. 28 // Accessors to basic information.
26 uint16 vendor_id() const { return vendor_id_; } 29 uint16 vendor_id() const { return vendor_id_; }
27 uint16 product_id() const { return product_id_; } 30 uint16 product_id() const { return product_id_; }
28 uint32 unique_id() const { return unique_id_; } 31 uint32 unique_id() const { return unique_id_; }
32 const base::string16& manufacturer_string() const {
33 return manufacturer_string_;
34 }
35 const base::string16& product_string() const { return product_string_; }
36 const base::string16& serial_number() const { return serial_number_; }
29 37
30 // On ChromeOS the permission_broker service is used to change the ownership 38 // On ChromeOS the permission_broker service is used to change the ownership
31 // of USB device nodes so that Chrome can open them. On other platforms these 39 // of USB device nodes so that Chrome can open them. On other platforms these
32 // functions are no-ops and always return true. 40 // functions are no-ops and always return true.
33 virtual void CheckUsbAccess(const ResultCallback& callback); 41 virtual void CheckUsbAccess(const ResultCallback& callback);
34 42
35 // Like CheckUsbAccess but actually changes the ownership of the device node. 43 // Like CheckUsbAccess but actually changes the ownership of the device node.
36 virtual void RequestUsbAccess(int interface_id, 44 virtual void RequestUsbAccess(int interface_id,
37 const ResultCallback& callback); 45 const ResultCallback& callback);
38 46
39 // Creates a UsbDeviceHandle for further manipulation. 47 // Creates a UsbDeviceHandle for further manipulation.
40 // Blocking method. Must be called on FILE thread. 48 virtual void Open(const OpenCallback& callback) = 0;
41 virtual scoped_refptr<UsbDeviceHandle> Open() = 0;
42 49
43 // Explicitly closes a device handle. This method will be automatically called 50 // Explicitly closes a device handle. This method will be automatically called
44 // by the destructor of a UsbDeviceHandle as well. 51 // by the destructor of a UsbDeviceHandle as well.
45 // Closing a closed handle is a safe
46 // Blocking method. Must be called on FILE thread.
47 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) = 0; 52 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) = 0;
48 53
49 // Gets the UsbConfigDescriptor for the active device configuration or nullptr 54 // Gets the UsbConfigDescriptor for the active device configuration or nullptr
50 // if the device is unconfigured. 55 // if the device is unconfigured.
51 // Blocking method. Must be called on FILE thread.
52 virtual const UsbConfigDescriptor* GetConfiguration() = 0; 56 virtual const UsbConfigDescriptor* GetConfiguration() = 0;
53 57
54 // Gets the manufacturer string of the device, or false and an empty
55 // string. This is a blocking method and must be called on FILE thread.
56 // TODO(reillyg): Make this available from the UI thread. crbug.com/427985
57 virtual bool GetManufacturer(base::string16* manufacturer) = 0;
58
59 // Gets the product string of the device, or returns false and an empty
60 // string. This is a blocking method and must be called on FILE thread.
61 // TODO(reillyg): Make this available from the UI thread. crbug.com/427985
62 virtual bool GetProduct(base::string16* product) = 0;
63
64 // Gets the serial number string of the device, or returns false and an empty
65 // string. This is a blocking method and must be called on FILE thread.
66 // TODO(reillyg): Make this available from the UI thread. crbug.com/427985
67 virtual bool GetSerialNumber(base::string16* serial) = 0;
68
69 protected: 58 protected:
70 UsbDevice(uint16 vendor_id, uint16 product_id, uint32 unique_id); 59 UsbDevice(uint16 vendor_id,
60 uint16 product_id,
61 uint32 unique_id,
62 const base::string16& manufacturer_string,
63 const base::string16& product_string,
64 const base::string16& serial_number);
71 virtual ~UsbDevice(); 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
« no previous file with comments | « device/usb/usb_context.cc ('k') | device/usb/usb_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698