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

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

Issue 941063003: Log device/usb messages to chrome://device-log. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 #include "device/usb/usb_device_impl.h" 5 #include "device/usb/usb_device_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
16 #include "device/usb/usb_context.h" 16 #include "device/usb/usb_context.h"
17 #include "device/usb/usb_descriptors.h" 17 #include "device/usb/usb_descriptors.h"
18 #include "device/usb/usb_device_handle_impl.h" 18 #include "device/usb/usb_device_handle_impl.h"
19 #include "device/usb/usb_error.h" 19 #include "device/usb/usb_error.h"
20 #include "device/usb/usb_log.h"
20 #include "third_party/libusb/src/libusb/libusb.h" 21 #include "third_party/libusb/src/libusb/libusb.h"
21 22
22 #if defined(OS_CHROMEOS) 23 #if defined(OS_CHROMEOS)
23 #include "base/sys_info.h" 24 #include "base/sys_info.h"
24 #include "chromeos/dbus/dbus_thread_manager.h" 25 #include "chromeos/dbus/dbus_thread_manager.h"
25 #include "chromeos/dbus/permission_broker_client.h" 26 #include "chromeos/dbus/permission_broker_client.h"
26 #endif // defined(OS_CHROMEOS) 27 #endif // defined(OS_CHROMEOS)
27 28
28 #if defined(USE_UDEV) 29 #if defined(USE_UDEV)
29 #include "device/udev_linux/scoped_udev.h" 30 #include "device/udev_linux/scoped_udev.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 scoped_refptr<UsbDeviceHandle> UsbDeviceImpl::Open() { 215 scoped_refptr<UsbDeviceHandle> UsbDeviceImpl::Open() {
215 DCHECK(thread_checker_.CalledOnValidThread()); 216 DCHECK(thread_checker_.CalledOnValidThread());
216 PlatformUsbDeviceHandle handle; 217 PlatformUsbDeviceHandle handle;
217 const int rv = libusb_open(platform_device_, &handle); 218 const int rv = libusb_open(platform_device_, &handle);
218 if (LIBUSB_SUCCESS == rv) { 219 if (LIBUSB_SUCCESS == rv) {
219 scoped_refptr<UsbDeviceHandleImpl> device_handle = 220 scoped_refptr<UsbDeviceHandleImpl> device_handle =
220 new UsbDeviceHandleImpl(context_, this, handle); 221 new UsbDeviceHandleImpl(context_, this, handle);
221 handles_.push_back(device_handle); 222 handles_.push_back(device_handle);
222 return device_handle; 223 return device_handle;
223 } else { 224 } else {
224 VLOG(1) << "Failed to open device: " << ConvertPlatformUsbErrorToString(rv); 225 USB_LOG(DEBUG) << "Failed to open device: "
226 << ConvertPlatformUsbErrorToString(rv);
stevenjb 2015/02/20 00:01:27 These seem like they should be actual ERROR events
225 return NULL; 227 return NULL;
226 } 228 }
227 } 229 }
228 230
229 bool UsbDeviceImpl::Close(scoped_refptr<UsbDeviceHandle> handle) { 231 bool UsbDeviceImpl::Close(scoped_refptr<UsbDeviceHandle> handle) {
230 DCHECK(thread_checker_.CalledOnValidThread()); 232 DCHECK(thread_checker_.CalledOnValidThread());
231 233
232 for (HandlesVector::iterator it = handles_.begin(); it != handles_.end(); 234 for (HandlesVector::iterator it = handles_.begin(); it != handles_.end();
233 ++it) { 235 ++it) {
234 if (it->get() == handle.get()) { 236 if (it->get() == handle.get()) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 for (const scoped_refptr<UsbDeviceHandleImpl>& handle : handles_) { 297 for (const scoped_refptr<UsbDeviceHandleImpl>& handle : handles_) {
296 handle->InternalClose(); 298 handle->InternalClose();
297 } 299 }
298 } 300 }
299 301
300 void UsbDeviceImpl::RefreshConfiguration() { 302 void UsbDeviceImpl::RefreshConfiguration() {
301 libusb_config_descriptor* platform_config; 303 libusb_config_descriptor* platform_config;
302 int rv = 304 int rv =
303 libusb_get_active_config_descriptor(platform_device_, &platform_config); 305 libusb_get_active_config_descriptor(platform_device_, &platform_config);
304 if (rv != LIBUSB_SUCCESS) { 306 if (rv != LIBUSB_SUCCESS) {
305 VLOG(1) << "Failed to get config descriptor: " 307 USB_LOG(DEBUG) << "Failed to get config descriptor: "
306 << ConvertPlatformUsbErrorToString(rv); 308 << ConvertPlatformUsbErrorToString(rv);
307 return; 309 return;
308 } 310 }
309 311
310 configuration_.reset(new UsbConfigDescriptor()); 312 configuration_.reset(new UsbConfigDescriptor());
311 configuration_->configuration_value = platform_config->bConfigurationValue; 313 configuration_->configuration_value = platform_config->bConfigurationValue;
312 configuration_->self_powered = (platform_config->bmAttributes & 0x40) != 0; 314 configuration_->self_powered = (platform_config->bmAttributes & 0x40) != 0;
313 configuration_->remote_wakeup = (platform_config->bmAttributes & 0x20) != 0; 315 configuration_->remote_wakeup = (platform_config->bmAttributes & 0x20) != 0;
314 configuration_->maximum_power = platform_config->MaxPower * 2; 316 configuration_->maximum_power = platform_config->MaxPower * 2;
315 317
316 for (size_t i = 0; i < platform_config->bNumInterfaces; ++i) { 318 for (size_t i = 0; i < platform_config->bNumInterfaces; ++i) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 device_handle->GetStringDescriptor(desc.iManufacturer, &manufacturer_); 377 device_handle->GetStringDescriptor(desc.iManufacturer, &manufacturer_);
376 } 378 }
377 if (desc.iProduct != 0) { 379 if (desc.iProduct != 0) {
378 device_handle->GetStringDescriptor(desc.iProduct, &product_); 380 device_handle->GetStringDescriptor(desc.iProduct, &product_);
379 } 381 }
380 if (desc.iSerialNumber != 0) { 382 if (desc.iSerialNumber != 0) {
381 device_handle->GetStringDescriptor(desc.iSerialNumber, &serial_number_); 383 device_handle->GetStringDescriptor(desc.iSerialNumber, &serial_number_);
382 } 384 }
383 device_handle->Close(); 385 device_handle->Close();
384 } else { 386 } else {
385 VLOG(1) << "Failed to open device to cache string descriptors."; 387 USB_LOG(DEBUG) << "Failed to open device to cache string descriptors.";
386 } 388 }
387 } else { 389 } else {
388 VLOG(1) << "Failed to read device descriptor to cache string descriptors: " 390 USB_LOG(DEBUG)
389 << ConvertPlatformUsbErrorToString(rv); 391 << "Failed to read device descriptor to cache string descriptors: "
392 << ConvertPlatformUsbErrorToString(rv);
390 } 393 }
391 strings_cached_ = true; 394 strings_cached_ = true;
392 } 395 }
393 #endif // !defined(USE_UDEV) 396 #endif // !defined(USE_UDEV)
394 397
395 } // namespace device 398 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698