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

Unified Diff: components/usb_service/usb_service_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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/usb_service/usb_error.cc ('k') | third_party/libusb/libusb.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/usb_service/usb_service_impl.cc
diff --git a/components/usb_service/usb_service_impl.cc b/components/usb_service/usb_service_impl.cc
index bafb51b680538571c4301525f16ee73763a8f6f6..4a3e88a2b956a7fccc60d31d8af376298e3a9d76 100644
--- a/components/usb_service/usb_service_impl.cc
+++ b/components/usb_service/usb_service_impl.cc
@@ -12,6 +12,7 @@
#include "base/stl_util.h"
#include "components/usb_service/usb_context.h"
#include "components/usb_service/usb_device_impl.h"
+#include "components/usb_service/usb_error.h"
#include "content/public/browser/browser_thread.h"
#include "third_party/libusb/src/libusb/libusb.h"
@@ -102,6 +103,10 @@ void UsbServiceImpl::RefreshDevices() {
libusb_device** platform_devices = NULL;
const ssize_t device_count =
libusb_get_device_list(context_->context(), &platform_devices);
+ if (device_count < 0) {
+ LOG(ERROR) << "Failed to get device list: " <<
+ ConvertErrorToString(device_count);
+ }
std::set<UsbDevice*> connected_devices;
std::vector<PlatformUsbDevice> disconnected_devices;
@@ -110,9 +115,14 @@ void UsbServiceImpl::RefreshDevices() {
for (ssize_t i = 0; i < device_count; ++i) {
if (!ContainsKey(devices_, platform_devices[i])) {
libusb_device_descriptor descriptor;
+ const int rv =
+ libusb_get_device_descriptor(platform_devices[i], &descriptor);
// This test is needed. A valid vendor/produce pair is required.
- if (0 != libusb_get_device_descriptor(platform_devices[i], &descriptor))
+ if (rv != LIBUSB_SUCCESS) {
+ LOG(WARNING) << "Failed to get device descriptor: "
+ << ConvertErrorToString(rv);
continue;
+ }
UsbDeviceImpl* new_device = new UsbDeviceImpl(context_,
platform_devices[i],
descriptor.idVendor,
@@ -148,8 +158,12 @@ UsbService* UsbService::GetInstance() {
UsbService* instance = g_usb_service_instance.Get().get();
if (!instance) {
PlatformUsbContext context = NULL;
- if (libusb_init(&context) != LIBUSB_SUCCESS)
+
+ const int rv = libusb_init(&context);
+ if (rv != LIBUSB_SUCCESS) {
+ LOG(ERROR) << "Failed to initialize libusb: " << ConvertErrorToString(rv);
return NULL;
+ }
if (!context)
return NULL;
« no previous file with comments | « components/usb_service/usb_error.cc ('k') | third_party/libusb/libusb.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698