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

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

Issue 1877503003: Replace libusb in the Linux/Chrome OS USB I/O path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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_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 <stdint.h> 8 #include <stdint.h>
9 9
10 #include <list> 10 #include <list>
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/files/scoped_file.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/threading/thread_checker.h" 17 #include "base/threading/thread_checker.h"
17 #include "build/build_config.h" 18 #include "build/build_config.h"
18 #include "device/usb/usb_descriptors.h" 19 #include "device/usb/usb_descriptors.h"
19 #include "device/usb/usb_device.h" 20 #include "device/usb/usb_device.h"
20 #include "device/usb/webusb_descriptors.h" 21 #include "device/usb/webusb_descriptors.h"
21 22
22 struct libusb_device; 23 struct libusb_device;
23 struct libusb_device_descriptor; 24 struct libusb_device_descriptor;
24 struct libusb_device_handle; 25 struct libusb_device_handle;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 scoped_ptr<WebUsbAllowedOrigins> allowed_origins) { 67 scoped_ptr<WebUsbAllowedOrigins> allowed_origins) {
67 webusb_allowed_origins_ = std::move(allowed_origins); 68 webusb_allowed_origins_ = std::move(allowed_origins);
68 } 69 }
69 void set_webusb_landing_page(const GURL& url) { webusb_landing_page_ = url; } 70 void set_webusb_landing_page(const GURL& url) { webusb_landing_page_ = url; }
70 71
71 PlatformUsbDevice platform_device() const { return platform_device_; } 72 PlatformUsbDevice platform_device() const { return platform_device_; }
72 73
73 protected: 74 protected:
74 friend class UsbServiceImpl; 75 friend class UsbServiceImpl;
75 friend class UsbDeviceHandleImpl; 76 friend class UsbDeviceHandleImpl;
77 friend class UsbDeviceHandleUsbfs;
76 78
77 // Called by UsbServiceImpl only; 79 // Called by UsbServiceImpl only;
78 UsbDeviceImpl(scoped_refptr<UsbContext> context, 80 UsbDeviceImpl(scoped_refptr<UsbContext> context,
79 PlatformUsbDevice platform_device, 81 PlatformUsbDevice platform_device,
80 const libusb_device_descriptor& descriptor, 82 const libusb_device_descriptor& descriptor,
81 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); 83 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
82 84
83 ~UsbDeviceImpl() override; 85 ~UsbDeviceImpl() override;
84 86
85 // Called only by UsbServiceImpl. 87 // Called only by UsbServiceImpl.
86 void set_visited(bool visited) { visited_ = visited; } 88 void set_visited(bool visited) { visited_ = visited; }
87 bool was_visited() const { return visited_; } 89 bool was_visited() const { return visited_; }
88 void OnDisconnect(); 90 void OnDisconnect();
89 void ReadAllConfigurations(); 91 void ReadAllConfigurations();
90 92
91 // Called by UsbDeviceHandleImpl. 93 // Called by UsbDeviceHandleImpl.
92 void HandleClosed(scoped_refptr<UsbDeviceHandle> handle); 94 void HandleClosed(UsbDeviceHandle* handle);
95 void ActiveConfigurationChanged(int configuration_value);
93 void RefreshActiveConfiguration(); 96 void RefreshActiveConfiguration();
94 97
95 private: 98 private:
96 void GetAllConfigurations(); 99 void GetAllConfigurations();
97 #if defined(OS_CHROMEOS) 100 #if defined(OS_CHROMEOS)
98 void OnOpenRequestComplete(const OpenCallback& callback, 101 void OnOpenRequestComplete(const OpenCallback& callback,
99 dbus::FileDescriptor fd); 102 dbus::FileDescriptor fd);
100 void OnOpenRequestError(const OpenCallback& callback, 103 void OnOpenRequestError(const OpenCallback& callback,
101 const std::string& error_name, 104 const std::string& error_name,
102 const std::string& error_message); 105 const std::string& error_message);
103 void OpenOnBlockingThreadWithFd(dbus::FileDescriptor fd, 106 void OpenOnBlockingThreadWithFd(dbus::FileDescriptor fd,
104 const OpenCallback& callback); 107 const OpenCallback& callback);
105 #endif 108 #else
106 void OpenOnBlockingThread(const OpenCallback& callback); 109 void OpenOnBlockingThread(const OpenCallback& callback);
110 #endif // defined(OS_CHROMEOS)
111 #if defined(OS_LINUX)
112 void Opened(base::ScopedFD fd, const OpenCallback& callback);
113 #else
107 void Opened(PlatformUsbDeviceHandle platform_handle, 114 void Opened(PlatformUsbDeviceHandle platform_handle,
108 const OpenCallback& callback); 115 const OpenCallback& callback);
116 #endif // defined(OS_LINUX)
109 117
110 base::ThreadChecker thread_checker_; 118 base::ThreadChecker thread_checker_;
111 PlatformUsbDevice platform_device_; 119 PlatformUsbDevice platform_device_;
112 bool visited_ = false; 120 bool visited_ = false;
113 121
114 // On Chrome OS device path is necessary to request access from the permission 122 // On Chrome OS device path is necessary to request access from the permission
115 // broker. 123 // broker.
116 std::string device_path_; 124 std::string device_path_;
117 125
118 // The current device configuration descriptor. May be null if the device is 126 // The current device configuration descriptor. May be null if the device is
119 // in an unconfigured state; if not null, it is a pointer to one of the 127 // in an unconfigured state; if not null, it is a pointer to one of the
120 // items at UsbDevice::configurations_. 128 // items at UsbDevice::configurations_.
121 const UsbConfigDescriptor* active_configuration_ = nullptr; 129 const UsbConfigDescriptor* active_configuration_ = nullptr;
122 130
123 // Retain the context so that it will not be released before UsbDevice. 131 // Retain the context so that it will not be released before UsbDevice.
124 scoped_refptr<UsbContext> context_; 132 scoped_refptr<UsbContext> context_;
125 133
126 // Opened handles. 134 // Opened handles.
127 std::list<UsbDeviceHandle*> handles_; 135 std::list<UsbDeviceHandle*> handles_;
128 136
129 scoped_refptr<base::SequencedTaskRunner> task_runner_; 137 scoped_refptr<base::SequencedTaskRunner> task_runner_;
130 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 138 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
131 139
132 DISALLOW_COPY_AND_ASSIGN(UsbDeviceImpl); 140 DISALLOW_COPY_AND_ASSIGN(UsbDeviceImpl);
133 }; 141 };
134 142
135 } // namespace device 143 } // namespace device
136 144
137 #endif // DEVICE_USB_USB_DEVICE_IMPL_H_ 145 #endif // DEVICE_USB_USB_DEVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698