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

Side by Side Diff: device/usb/usb_device_impl.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_device_handle_unittest.cc ('k') | device/usb/usb_device_impl.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_IMPL_H_ 5 #ifndef DEVICE_USB_USB_DEVICE_IMPL_H_
6 #define DEVICE_USB_USB_DEVICE_IMPL_H_ 6 #define DEVICE_USB_USB_DEVICE_IMPL_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/threading/thread_checker.h" 12 #include "base/threading/thread_checker.h"
13 #include "device/usb/usb_descriptors.h" 13 #include "device/usb/usb_descriptors.h"
14 #include "device/usb/usb_device.h" 14 #include "device/usb/usb_device.h"
15 15
16 struct libusb_device; 16 struct libusb_device;
17 struct libusb_config_descriptor; 17 struct libusb_config_descriptor;
18 struct libusb_device_handle;
18 19
19 namespace base { 20 namespace base {
20 class SingleThreadTaskRunner; 21 class SequencedTaskRunner;
21 } 22 }
22 23
23 namespace device { 24 namespace device {
24 25
25 class UsbDeviceHandleImpl; 26 class UsbDeviceHandleImpl;
26 class UsbContext; 27 class UsbContext;
27 28
28 typedef libusb_device* PlatformUsbDevice; 29 typedef struct libusb_device* PlatformUsbDevice;
29 typedef libusb_config_descriptor* PlatformUsbConfigDescriptor; 30 typedef struct libusb_config_descriptor* PlatformUsbConfigDescriptor;
31 typedef struct libusb_device_handle* PlatformUsbDeviceHandle;
30 32
31 class UsbDeviceImpl : public UsbDevice { 33 class UsbDeviceImpl : public UsbDevice {
32 public: 34 public:
33 // UsbDevice implementation: 35 // UsbDevice implementation:
34 #if defined(OS_CHROMEOS) 36 #if defined(OS_CHROMEOS)
35 // Only overridden on Chrome OS. 37 // Only overridden on Chrome OS.
36 void CheckUsbAccess(const ResultCallback& callback) override; 38 void CheckUsbAccess(const ResultCallback& callback) override;
37 void RequestUsbAccess(int interface_id, 39 void RequestUsbAccess(int interface_id,
38 const ResultCallback& callback) override; 40 const ResultCallback& callback) override;
39 #endif // OS_CHROMEOS 41 #endif // OS_CHROMEOS
40 scoped_refptr<UsbDeviceHandle> Open() override; 42 void Open(const OpenCallback& callback) override;
41 bool Close(scoped_refptr<UsbDeviceHandle> handle) override; 43 bool Close(scoped_refptr<UsbDeviceHandle> handle) override;
42 const UsbConfigDescriptor* GetConfiguration() override; 44 const UsbConfigDescriptor* GetConfiguration() override;
43 bool GetManufacturer(base::string16* manufacturer) override;
44 bool GetProduct(base::string16* product) override;
45 bool GetSerialNumber(base::string16* serial_number) override;
46 45
47 protected: 46 protected:
48 friend class UsbServiceImpl; 47 friend class UsbServiceImpl;
49 friend class UsbDeviceHandleImpl; 48 friend class UsbDeviceHandleImpl;
50 49
51 // Called by UsbServiceImpl only; 50 // Called by UsbServiceImpl only;
52 UsbDeviceImpl(scoped_refptr<UsbContext> context, 51 UsbDeviceImpl(scoped_refptr<UsbContext> context,
53 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
54 PlatformUsbDevice platform_device, 52 PlatformUsbDevice platform_device,
55 uint16 vendor_id, 53 uint16 vendor_id,
56 uint16 product_id, 54 uint16 product_id,
57 uint32 unique_id); 55 uint32 unique_id,
56 const base::string16& manufacturer_string,
57 const base::string16& product_string,
58 const base::string16& serial_number,
59 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
58 60
59 ~UsbDeviceImpl() override; 61 ~UsbDeviceImpl() override;
60 62
61 // Called only by UsbServiceImpl. 63 // Called only by UsbServiceImpl.
64 PlatformUsbDevice platform_device() const { return platform_device_; }
65 void set_visited(bool visited) { visited_ = visited; }
66 bool was_visited() const { return visited_; }
62 void OnDisconnect(); 67 void OnDisconnect();
63 68
64 // Called by UsbDeviceHandleImpl. 69 // Called by UsbDeviceHandleImpl.
65 void RefreshConfiguration(); 70 void RefreshConfiguration();
66 71
67 private: 72 private:
73 void OpenOnBlockingThread(const OpenCallback& callback);
74 void Opened(PlatformUsbDeviceHandle platform_handle,
75 const OpenCallback& callback);
76
68 base::ThreadChecker thread_checker_; 77 base::ThreadChecker thread_checker_;
69 PlatformUsbDevice platform_device_; 78 PlatformUsbDevice platform_device_;
79 bool visited_ = false;
70 80
71 // On Linux these properties are read from sysfs when the device is enumerated
72 // to avoid hitting the permission broker on Chrome OS for a real string
73 // descriptor request.
74 base::string16 manufacturer_;
75 base::string16 product_;
76 base::string16 serial_number_;
77 #if !defined(USE_UDEV)
78 // On other platforms the device must be opened in order to cache them. This
79 // should be delayed until the strings are needed to avoid poor interactions
80 // with other applications.
81 void CacheStrings();
82 bool strings_cached_;
83 #endif
84 #if defined(OS_CHROMEOS) 81 #if defined(OS_CHROMEOS)
85 // On Chrome OS save the devnode string for requesting path access from 82 // On Chrome OS save the devnode string for requesting path access from
86 // permission broker. 83 // permission broker.
87 std::string devnode_; 84 std::string devnode_;
88 #endif 85 #endif
89 86
90 // The current device configuration descriptor. May be null if the device is 87 // The current device configuration descriptor. May be null if the device is
91 // in an unconfigured state. 88 // in an unconfigured state.
92 scoped_ptr<UsbConfigDescriptor> configuration_; 89 scoped_ptr<UsbConfigDescriptor> configuration_;
93 90
94 // Retain the context so that it will not be released before UsbDevice. 91 // Retain the context so that it will not be released before UsbDevice.
95 scoped_refptr<UsbContext> context_; 92 scoped_refptr<UsbContext> context_;
96 93
97 // Opened handles. 94 // Opened handles.
98 typedef std::vector<scoped_refptr<UsbDeviceHandleImpl> > HandlesVector; 95 typedef std::vector<scoped_refptr<UsbDeviceHandleImpl> > HandlesVector;
99 HandlesVector handles_; 96 HandlesVector handles_;
100 97
101 // Reference to the UI thread for permission-broker calls. 98 scoped_refptr<base::SequencedTaskRunner> task_runner_;
102 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; 99 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
103 100
104 DISALLOW_COPY_AND_ASSIGN(UsbDeviceImpl); 101 DISALLOW_COPY_AND_ASSIGN(UsbDeviceImpl);
105 }; 102 };
106 103
107 } // namespace device 104 } // namespace device
108 105
109 #endif // DEVICE_USB_USB_DEVICE_IMPL_H_ 106 #endif // DEVICE_USB_USB_DEVICE_IMPL_H_
OLDNEW
« no previous file with comments | « device/usb/usb_device_handle_unittest.cc ('k') | device/usb/usb_device_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698