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

Side by Side Diff: components/usb_service/usb_device_impl.cc

Issue 344793009: Log errors from libusb. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 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 | « components/usb_service/usb_device_handle_impl.cc ('k') | components/usb_service/usb_error.h » ('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 #include "components/usb_service/usb_device_impl.h" 5 #include "components/usb_service/usb_device_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "components/usb_service/usb_context.h" 10 #include "components/usb_service/usb_context.h"
11 #include "components/usb_service/usb_device_handle_impl.h" 11 #include "components/usb_service/usb_device_handle_impl.h"
12 #include "components/usb_service/usb_error.h"
12 #include "components/usb_service/usb_interface_impl.h" 13 #include "components/usb_service/usb_interface_impl.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 #include "third_party/libusb/src/libusb/libusb.h" 15 #include "third_party/libusb/src/libusb/libusb.h"
15 16
16 #if defined(OS_CHROMEOS) 17 #if defined(OS_CHROMEOS)
17 #include "base/sys_info.h" 18 #include "base/sys_info.h"
18 #include "chromeos/dbus/dbus_thread_manager.h" 19 #include "chromeos/dbus/dbus_thread_manager.h"
19 #include "chromeos/dbus/permission_broker_client.h" 20 #include "chromeos/dbus/permission_broker_client.h"
20 #endif // defined(OS_CHROMEOS) 21 #endif // defined(OS_CHROMEOS)
21 22
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 interface_id, 87 interface_id,
87 base::Bind(&OnRequestUsbAccessReplied, callback))); 88 base::Bind(&OnRequestUsbAccessReplied, callback)));
88 } 89 }
89 } 90 }
90 91
91 #endif 92 #endif
92 93
93 scoped_refptr<UsbDeviceHandle> UsbDeviceImpl::Open() { 94 scoped_refptr<UsbDeviceHandle> UsbDeviceImpl::Open() {
94 DCHECK(thread_checker_.CalledOnValidThread()); 95 DCHECK(thread_checker_.CalledOnValidThread());
95 PlatformUsbDeviceHandle handle; 96 PlatformUsbDeviceHandle handle;
96 int rv = libusb_open(platform_device_, &handle); 97 const int rv = libusb_open(platform_device_, &handle);
97 if (LIBUSB_SUCCESS == rv) { 98 if (LIBUSB_SUCCESS == rv) {
98 scoped_refptr<UsbConfigDescriptor> interfaces = ListInterfaces(); 99 scoped_refptr<UsbConfigDescriptor> interfaces = ListInterfaces();
99 if (!interfaces) 100 if (!interfaces)
100 return NULL; 101 return NULL;
101 scoped_refptr<UsbDeviceHandleImpl> device_handle = 102 scoped_refptr<UsbDeviceHandleImpl> device_handle =
102 new UsbDeviceHandleImpl(context_, this, handle, interfaces); 103 new UsbDeviceHandleImpl(context_, this, handle, interfaces);
103 handles_.push_back(device_handle); 104 handles_.push_back(device_handle);
104 return device_handle; 105 return device_handle;
106 } else {
107 LOG(ERROR) << "Failed to open device: " << ConvertErrorToString(rv);
108 return NULL;
105 } 109 }
106 return NULL;
107 } 110 }
108 111
109 bool UsbDeviceImpl::Close(scoped_refptr<UsbDeviceHandle> handle) { 112 bool UsbDeviceImpl::Close(scoped_refptr<UsbDeviceHandle> handle) {
110 DCHECK(thread_checker_.CalledOnValidThread()); 113 DCHECK(thread_checker_.CalledOnValidThread());
111 114
112 for (HandlesVector::iterator it = handles_.begin(); it != handles_.end(); 115 for (HandlesVector::iterator it = handles_.begin(); it != handles_.end();
113 ++it) { 116 ++it) {
114 if (*it == handle) { 117 if (*it == handle) {
115 (*it)->InternalClose(); 118 (*it)->InternalClose();
116 handles_.erase(it); 119 handles_.erase(it);
117 return true; 120 return true;
118 } 121 }
119 } 122 }
120 return false; 123 return false;
121 } 124 }
122 125
123 scoped_refptr<UsbConfigDescriptor> UsbDeviceImpl::ListInterfaces() { 126 scoped_refptr<UsbConfigDescriptor> UsbDeviceImpl::ListInterfaces() {
124 DCHECK(thread_checker_.CalledOnValidThread()); 127 DCHECK(thread_checker_.CalledOnValidThread());
125 128
126 PlatformUsbConfigDescriptor platform_config; 129 PlatformUsbConfigDescriptor platform_config;
127 const int list_result = 130 const int rv =
128 libusb_get_active_config_descriptor(platform_device_, &platform_config); 131 libusb_get_active_config_descriptor(platform_device_, &platform_config);
129 if (list_result == 0) 132 if (rv == LIBUSB_SUCCESS) {
130 return new UsbConfigDescriptorImpl(platform_config); 133 return new UsbConfigDescriptorImpl(platform_config);
131 134 } else {
132 return NULL; 135 LOG(ERROR) << "Failed to get config descriptor: "
136 << ConvertErrorToString(rv);
137 return NULL;
138 }
133 } 139 }
134 140
135 void UsbDeviceImpl::OnDisconnect() { 141 void UsbDeviceImpl::OnDisconnect() {
136 DCHECK(thread_checker_.CalledOnValidThread()); 142 DCHECK(thread_checker_.CalledOnValidThread());
137 HandlesVector handles; 143 HandlesVector handles;
138 swap(handles, handles_); 144 swap(handles, handles_);
139 for (HandlesVector::iterator it = handles.begin(); it != handles.end(); ++it) 145 for (HandlesVector::iterator it = handles.begin(); it != handles.end(); ++it)
140 (*it)->InternalClose(); 146 (*it)->InternalClose();
141 } 147 }
142 148
143 } // namespace usb_service 149 } // namespace usb_service
OLDNEW
« no previous file with comments | « components/usb_service/usb_device_handle_impl.cc ('k') | components/usb_service/usb_error.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698