OLD | NEW |
---|---|
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_handle_impl.h" | 5 #include "device/usb/usb_device_handle_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
402 return false; | 402 return false; |
403 } else if ((languages[0] >> 8) != LIBUSB_DT_STRING) { | 403 } else if ((languages[0] >> 8) != LIBUSB_DT_STRING) { |
404 VLOG(1) << "String descriptor zero is not a string descriptor."; | 404 VLOG(1) << "String descriptor zero is not a string descriptor."; |
405 return false; | 405 return false; |
406 } | 406 } |
407 | 407 |
408 languages_.assign(languages[1], languages[(size - 2) / 2]); | 408 languages_.assign(languages[1], languages[(size - 2) / 2]); |
409 return true; | 409 return true; |
410 } | 410 } |
411 | 411 |
412 bool UsbDeviceHandleImpl::GetStringDescriptor(uint8 string_id, | 412 bool UsbDeviceHandleImpl::GetStringDescriptor(uint8 string_id, |
scheib
2014/09/25 17:36:04
Move to match declaration order.
Reilly Grant (use Gerrit)
2014/09/25 17:58:44
This file is all out of order. It's actually the f
scheib
2014/09/25 19:47:05
Fix at least the methods that you move the declara
Reilly Grant (use Gerrit)
2014/09/25 19:55:15
Done. I should stop being lazy.
| |
413 base::string16* string) { | 413 base::string16* string) { |
414 if (!GetSupportedLanguages()) { | 414 if (!GetSupportedLanguages()) { |
415 return false; | 415 return false; |
416 } | 416 } |
417 | 417 |
418 std::map<uint8, base::string16>::const_iterator it = strings_.find(string_id); | 418 std::map<uint8, base::string16>::const_iterator it = strings_.find(string_id); |
419 if (it != strings_.end()) { | 419 if (it != strings_.end()) { |
420 *string = it->second; | 420 *string = it->second; |
421 return true; | 421 return true; |
422 } | 422 } |
(...skipping 29 matching lines...) Expand all Loading... | |
452 } | 452 } |
453 | 453 |
454 *string = base::string16(text + 1, (size - 2) / 2); | 454 *string = base::string16(text + 1, (size - 2) / 2); |
455 strings_[string_id] = *string; | 455 strings_[string_id] = *string; |
456 return true; | 456 return true; |
457 } | 457 } |
458 | 458 |
459 return false; | 459 return false; |
460 } | 460 } |
461 | 461 |
462 bool UsbDeviceHandleImpl::GetManufacturer(base::string16* manufacturer) { | |
463 DCHECK(thread_checker_.CalledOnValidThread()); | |
464 PlatformUsbDevice device = libusb_get_device(handle_); | |
465 libusb_device_descriptor desc; | |
466 | |
467 // This is a non-blocking call as libusb has the descriptor in memory. | |
468 const int rv = libusb_get_device_descriptor(device, &desc); | |
469 if (rv != LIBUSB_SUCCESS) { | |
470 VLOG(1) << "Failed to read device descriptor: " | |
471 << ConvertPlatformUsbErrorToString(rv); | |
472 return false; | |
473 } | |
474 | |
475 if (desc.iManufacturer == 0) { | |
476 return false; | |
477 } | |
478 | |
479 return GetStringDescriptor(desc.iManufacturer, manufacturer); | |
480 } | |
481 | |
482 bool UsbDeviceHandleImpl::GetProduct(base::string16* product) { | |
483 DCHECK(thread_checker_.CalledOnValidThread()); | |
484 PlatformUsbDevice device = libusb_get_device(handle_); | |
485 libusb_device_descriptor desc; | |
486 | |
487 // This is a non-blocking call as libusb has the descriptor in memory. | |
488 const int rv = libusb_get_device_descriptor(device, &desc); | |
489 if (rv != LIBUSB_SUCCESS) { | |
490 VLOG(1) << "Failed to read device descriptor: " | |
491 << ConvertPlatformUsbErrorToString(rv); | |
492 return false; | |
493 } | |
494 | |
495 if (desc.iProduct == 0) { | |
496 return false; | |
497 } | |
498 | |
499 return GetStringDescriptor(desc.iProduct, product); | |
500 } | |
501 | |
502 bool UsbDeviceHandleImpl::GetSerial(base::string16* serial) { | |
503 DCHECK(thread_checker_.CalledOnValidThread()); | |
504 PlatformUsbDevice device = libusb_get_device(handle_); | |
505 libusb_device_descriptor desc; | |
506 | |
507 // This is a non-blocking call as libusb has the descriptor in memory. | |
508 const int rv = libusb_get_device_descriptor(device, &desc); | |
509 if (rv != LIBUSB_SUCCESS) { | |
510 VLOG(1) << "Failed to read device descriptor: " | |
511 << ConvertPlatformUsbErrorToString(rv); | |
512 return false; | |
513 } | |
514 | |
515 if (desc.iSerialNumber == 0) { | |
516 return false; | |
517 } | |
518 | |
519 return GetStringDescriptor(desc.iSerialNumber, serial); | |
520 } | |
521 | |
522 void UsbDeviceHandleImpl::ControlTransfer( | 462 void UsbDeviceHandleImpl::ControlTransfer( |
523 const UsbEndpointDirection direction, | 463 const UsbEndpointDirection direction, |
524 const TransferRequestType request_type, | 464 const TransferRequestType request_type, |
525 const TransferRecipient recipient, | 465 const TransferRecipient recipient, |
526 const uint8 request, | 466 const uint8 request, |
527 const uint16 value, | 467 const uint16 value, |
528 const uint16 index, | 468 const uint16 index, |
529 net::IOBuffer* buffer, | 469 net::IOBuffer* buffer, |
530 const size_t length, | 470 const size_t length, |
531 const unsigned int timeout, | 471 const unsigned int timeout, |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
764 // Attempt-release all the interfaces. | 704 // Attempt-release all the interfaces. |
765 // It will be retained until the transfer cancellation is finished. | 705 // It will be retained until the transfer cancellation is finished. |
766 claimed_interfaces_.clear(); | 706 claimed_interfaces_.clear(); |
767 | 707 |
768 // Cannot close device handle here. Need to wait for libusb_cancel_transfer to | 708 // Cannot close device handle here. Need to wait for libusb_cancel_transfer to |
769 // finish. | 709 // finish. |
770 device_ = NULL; | 710 device_ = NULL; |
771 } | 711 } |
772 | 712 |
773 } // namespace device | 713 } // namespace device |
OLD | NEW |