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

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

Powered by Google App Engine
This is Rietveld 408576698