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

Side by Side Diff: device/usb/usb_device_handle_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_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"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
16 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
17 #include "device/usb/usb_context.h" 17 #include "device/usb/usb_context.h"
18 #include "device/usb/usb_descriptors.h" 18 #include "device/usb/usb_descriptors.h"
19 #include "device/usb/usb_device_impl.h" 19 #include "device/usb/usb_device_impl.h"
20 #include "device/usb/usb_error.h" 20 #include "device/usb/usb_error.h"
21 #include "device/usb/usb_log.h"
21 #include "device/usb/usb_service.h" 22 #include "device/usb/usb_service.h"
22 #include "third_party/libusb/src/libusb/libusb.h" 23 #include "third_party/libusb/src/libusb/libusb.h"
23 24
24 namespace device { 25 namespace device {
25 26
26 typedef libusb_device* PlatformUsbDevice; 27 typedef libusb_device* PlatformUsbDevice;
27 28
28 void HandleTransferCompletion(PlatformUsbTransferHandle transfer); 29 void HandleTransferCompletion(PlatformUsbTransferHandle transfer);
29 30
30 namespace { 31 namespace {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 alternate_setting_(0) { 139 alternate_setting_(0) {
139 } 140 }
140 141
141 UsbDeviceHandleImpl::InterfaceClaimer::~InterfaceClaimer() { 142 UsbDeviceHandleImpl::InterfaceClaimer::~InterfaceClaimer() {
142 libusb_release_interface(handle_->handle(), interface_number_); 143 libusb_release_interface(handle_->handle(), interface_number_);
143 } 144 }
144 145
145 bool UsbDeviceHandleImpl::InterfaceClaimer::Claim() const { 146 bool UsbDeviceHandleImpl::InterfaceClaimer::Claim() const {
146 const int rv = libusb_claim_interface(handle_->handle(), interface_number_); 147 const int rv = libusb_claim_interface(handle_->handle(), interface_number_);
147 if (rv != LIBUSB_SUCCESS) { 148 if (rv != LIBUSB_SUCCESS) {
148 VLOG(1) << "Failed to claim interface: " 149 USB_LOG(DEBUG) << "Failed to claim interface " << interface_number_ << ": "
149 << ConvertPlatformUsbErrorToString(rv); 150 << ConvertPlatformUsbErrorToString(rv);
stevenjb 2015/02/20 00:01:27 You might want to use type EVENT here. DEBUG doesn
Reilly Grant (use Gerrit) 2015/02/20 00:10:22 Spamminess is somewhat controlled by the Chrome ap
150 } 151 }
151 return rv == LIBUSB_SUCCESS; 152 return rv == LIBUSB_SUCCESS;
152 } 153 }
153 154
154 // This inner class owns the underlying libusb_transfer and may outlast 155 // This inner class owns the underlying libusb_transfer and may outlast
155 // the UsbDeviceHandle that created it. 156 // the UsbDeviceHandle that created it.
156 class UsbDeviceHandleImpl::Transfer { 157 class UsbDeviceHandleImpl::Transfer {
157 public: 158 public:
158 static scoped_ptr<Transfer> CreateControlTransfer( 159 static scoped_ptr<Transfer> CreateControlTransfer(
159 uint8 type, 160 uint8 type,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 uint16 length, 227 uint16 length,
227 scoped_refptr<net::IOBuffer> buffer, 228 scoped_refptr<net::IOBuffer> buffer,
228 unsigned int timeout, 229 unsigned int timeout,
229 const UsbTransferCallback& callback) { 230 const UsbTransferCallback& callback) {
230 scoped_ptr<Transfer> transfer(new Transfer(USB_TRANSFER_CONTROL, buffer, 231 scoped_ptr<Transfer> transfer(new Transfer(USB_TRANSFER_CONTROL, buffer,
231 length + LIBUSB_CONTROL_SETUP_SIZE, 232 length + LIBUSB_CONTROL_SETUP_SIZE,
232 callback)); 233 callback));
233 234
234 transfer->platform_transfer_ = libusb_alloc_transfer(0); 235 transfer->platform_transfer_ = libusb_alloc_transfer(0);
235 if (!transfer->platform_transfer_) { 236 if (!transfer->platform_transfer_) {
236 LOG(ERROR) << "Failed to allocate control transfer."; 237 USB_LOG(DEBUG) << "Failed to allocate control transfer.";
stevenjb 2015/02/20 00:01:27 If LOG(ERROR) was correct before, this should also
237 return nullptr; 238 return nullptr;
238 } 239 }
239 240
240 libusb_fill_control_setup(reinterpret_cast<uint8*>(buffer->data()), type, 241 libusb_fill_control_setup(reinterpret_cast<uint8*>(buffer->data()), type,
241 request, value, index, length); 242 request, value, index, length);
242 libusb_fill_control_transfer(transfer->platform_transfer_, 243 libusb_fill_control_transfer(transfer->platform_transfer_,
243 nullptr, /* filled in by Submit() */ 244 nullptr, /* filled in by Submit() */
244 reinterpret_cast<uint8*>(buffer->data()), 245 reinterpret_cast<uint8*>(buffer->data()),
245 &UsbDeviceHandleImpl::Transfer::PlatformCallback, 246 &UsbDeviceHandleImpl::Transfer::PlatformCallback,
246 transfer.get(), timeout); 247 transfer.get(), timeout);
247 248
248 return transfer.Pass(); 249 return transfer.Pass();
249 } 250 }
250 251
251 // static 252 // static
252 scoped_ptr<UsbDeviceHandleImpl::Transfer> 253 scoped_ptr<UsbDeviceHandleImpl::Transfer>
253 UsbDeviceHandleImpl::Transfer::CreateBulkTransfer( 254 UsbDeviceHandleImpl::Transfer::CreateBulkTransfer(
254 uint8 endpoint, 255 uint8 endpoint,
255 scoped_refptr<net::IOBuffer> buffer, 256 scoped_refptr<net::IOBuffer> buffer,
256 int length, 257 int length,
257 unsigned int timeout, 258 unsigned int timeout,
258 const UsbTransferCallback& callback) { 259 const UsbTransferCallback& callback) {
259 scoped_ptr<Transfer> transfer( 260 scoped_ptr<Transfer> transfer(
260 new Transfer(USB_TRANSFER_BULK, buffer, length, callback)); 261 new Transfer(USB_TRANSFER_BULK, buffer, length, callback));
261 262
262 transfer->platform_transfer_ = libusb_alloc_transfer(0); 263 transfer->platform_transfer_ = libusb_alloc_transfer(0);
263 if (!transfer->platform_transfer_) { 264 if (!transfer->platform_transfer_) {
264 LOG(ERROR) << "Failed to allocate bulk transfer."; 265 USB_LOG(DEBUG) << "Failed to allocate bulk transfer.";
stevenjb 2015/02/20 00:01:27 Double check all of these for ERROR / USER / EVENT
265 return nullptr; 266 return nullptr;
266 } 267 }
267 268
268 libusb_fill_bulk_transfer(transfer->platform_transfer_, 269 libusb_fill_bulk_transfer(transfer->platform_transfer_,
269 nullptr, /* filled in by Submit() */ 270 nullptr, /* filled in by Submit() */
270 endpoint, reinterpret_cast<uint8*>(buffer->data()), 271 endpoint, reinterpret_cast<uint8*>(buffer->data()),
271 static_cast<int>(length), 272 static_cast<int>(length),
272 &UsbDeviceHandleImpl::Transfer::PlatformCallback, 273 &UsbDeviceHandleImpl::Transfer::PlatformCallback,
273 transfer.get(), timeout); 274 transfer.get(), timeout);
274 275
275 return transfer.Pass(); 276 return transfer.Pass();
276 } 277 }
277 278
278 // static 279 // static
279 scoped_ptr<UsbDeviceHandleImpl::Transfer> 280 scoped_ptr<UsbDeviceHandleImpl::Transfer>
280 UsbDeviceHandleImpl::Transfer::CreateInterruptTransfer( 281 UsbDeviceHandleImpl::Transfer::CreateInterruptTransfer(
281 uint8 endpoint, 282 uint8 endpoint,
282 scoped_refptr<net::IOBuffer> buffer, 283 scoped_refptr<net::IOBuffer> buffer,
283 int length, 284 int length,
284 unsigned int timeout, 285 unsigned int timeout,
285 const UsbTransferCallback& callback) { 286 const UsbTransferCallback& callback) {
286 scoped_ptr<Transfer> transfer( 287 scoped_ptr<Transfer> transfer(
287 new Transfer(USB_TRANSFER_INTERRUPT, buffer, length, callback)); 288 new Transfer(USB_TRANSFER_INTERRUPT, buffer, length, callback));
288 289
289 transfer->platform_transfer_ = libusb_alloc_transfer(0); 290 transfer->platform_transfer_ = libusb_alloc_transfer(0);
290 if (!transfer->platform_transfer_) { 291 if (!transfer->platform_transfer_) {
291 LOG(ERROR) << "Failed to allocate interrupt transfer."; 292 USB_LOG(DEBUG) << "Failed to allocate interrupt transfer.";
292 return nullptr; 293 return nullptr;
293 } 294 }
294 295
295 libusb_fill_interrupt_transfer( 296 libusb_fill_interrupt_transfer(
296 transfer->platform_transfer_, nullptr, /* filled in by Submit() */ 297 transfer->platform_transfer_, nullptr, /* filled in by Submit() */
297 endpoint, reinterpret_cast<uint8*>(buffer->data()), 298 endpoint, reinterpret_cast<uint8*>(buffer->data()),
298 static_cast<int>(length), 299 static_cast<int>(length),
299 &UsbDeviceHandleImpl::Transfer::PlatformCallback, transfer.get(), 300 &UsbDeviceHandleImpl::Transfer::PlatformCallback, transfer.get(),
300 timeout); 301 timeout);
301 302
(...skipping 11 matching lines...) Expand all
313 unsigned int timeout, 314 unsigned int timeout,
314 const UsbTransferCallback& callback) { 315 const UsbTransferCallback& callback) {
315 DCHECK(packets <= length && (packets * packet_length) <= length) 316 DCHECK(packets <= length && (packets * packet_length) <= length)
316 << "transfer length is too small"; 317 << "transfer length is too small";
317 318
318 scoped_ptr<Transfer> transfer( 319 scoped_ptr<Transfer> transfer(
319 new Transfer(USB_TRANSFER_ISOCHRONOUS, buffer, length, callback)); 320 new Transfer(USB_TRANSFER_ISOCHRONOUS, buffer, length, callback));
320 321
321 transfer->platform_transfer_ = libusb_alloc_transfer(packets); 322 transfer->platform_transfer_ = libusb_alloc_transfer(packets);
322 if (!transfer->platform_transfer_) { 323 if (!transfer->platform_transfer_) {
323 LOG(ERROR) << "Failed to allocate isochronous transfer."; 324 USB_LOG(DEBUG) << "Failed to allocate isochronous transfer.";
324 return nullptr; 325 return nullptr;
325 } 326 }
326 327
327 libusb_fill_iso_transfer( 328 libusb_fill_iso_transfer(
328 transfer->platform_transfer_, nullptr, /* filled in by Submit() */ 329 transfer->platform_transfer_, nullptr, /* filled in by Submit() */
329 endpoint, reinterpret_cast<uint8*>(buffer->data()), 330 endpoint, reinterpret_cast<uint8*>(buffer->data()),
330 static_cast<int>(length), packets, &Transfer::PlatformCallback, 331 static_cast<int>(length), packets, &Transfer::PlatformCallback,
331 transfer.get(), timeout); 332 transfer.get(), timeout);
332 libusb_set_iso_packet_lengths(transfer->platform_transfer_, packet_length); 333 libusb_set_iso_packet_lengths(transfer->platform_transfer_, packet_length);
333 334
(...skipping 29 matching lines...) Expand all
363 // GetClaimedInterfaceForEndpoint may return nullptr. libusb_submit_transfer 364 // GetClaimedInterfaceForEndpoint may return nullptr. libusb_submit_transfer
364 // will fail if it requires an interface we didn't claim. 365 // will fail if it requires an interface we didn't claim.
365 claimed_interface_ = device_handle->GetClaimedInterfaceForEndpoint( 366 claimed_interface_ = device_handle->GetClaimedInterfaceForEndpoint(
366 platform_transfer_->endpoint); 367 platform_transfer_->endpoint);
367 platform_transfer_->dev_handle = device_handle_->handle_; 368 platform_transfer_->dev_handle = device_handle_->handle_;
368 369
369 const int rv = libusb_submit_transfer(platform_transfer_); 370 const int rv = libusb_submit_transfer(platform_transfer_);
370 if (rv == LIBUSB_SUCCESS) { 371 if (rv == LIBUSB_SUCCESS) {
371 return true; 372 return true;
372 } else { 373 } else {
373 VLOG(1) << "Failed to submit transfer: " 374 USB_LOG(DEBUG) << "Failed to submit transfer: "
374 << ConvertPlatformUsbErrorToString(rv); 375 << ConvertPlatformUsbErrorToString(rv);
375 Complete(USB_TRANSFER_ERROR, 0); 376 Complete(USB_TRANSFER_ERROR, 0);
376 return false; 377 return false;
377 } 378 }
378 } 379 }
379 380
380 void UsbDeviceHandleImpl::Transfer::Cancel() { 381 void UsbDeviceHandleImpl::Transfer::Cancel() {
381 if (!cancelled_) { 382 if (!cancelled_) {
382 libusb_cancel_transfer(platform_transfer_); 383 libusb_cancel_transfer(platform_transfer_);
383 claimed_interface_ = nullptr; 384 claimed_interface_ = nullptr;
384 } 385 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 for (Transfer* transfer : transfers_) { 519 for (Transfer* transfer : transfers_) {
519 transfer->Cancel(); 520 transfer->Cancel();
520 } 521 }
521 claimed_interfaces_.clear(); 522 claimed_interfaces_.clear();
522 523
523 int rv = libusb_set_configuration(handle_, configuration_value); 524 int rv = libusb_set_configuration(handle_, configuration_value);
524 if (rv == LIBUSB_SUCCESS) { 525 if (rv == LIBUSB_SUCCESS) {
525 device_->RefreshConfiguration(); 526 device_->RefreshConfiguration();
526 RefreshEndpointMap(); 527 RefreshEndpointMap();
527 } else { 528 } else {
528 VLOG(1) << "Failed to set configuration " << configuration_value << ": " 529 USB_LOG(DEBUG) << "Failed to set configuration " << configuration_value
529 << ConvertPlatformUsbErrorToString(rv); 530 << ": " << ConvertPlatformUsbErrorToString(rv);
530 } 531 }
531 return rv == LIBUSB_SUCCESS; 532 return rv == LIBUSB_SUCCESS;
532 } 533 }
533 534
534 bool UsbDeviceHandleImpl::ClaimInterface(const int interface_number) { 535 bool UsbDeviceHandleImpl::ClaimInterface(const int interface_number) {
535 DCHECK(thread_checker_.CalledOnValidThread()); 536 DCHECK(thread_checker_.CalledOnValidThread());
536 if (!device_) 537 if (!device_)
537 return false; 538 return false;
538 if (ContainsKey(claimed_interfaces_, interface_number)) 539 if (ContainsKey(claimed_interfaces_, interface_number))
539 return true; 540 return true;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 return false; 579 return false;
579 if (!ContainsKey(claimed_interfaces_, interface_number)) 580 if (!ContainsKey(claimed_interfaces_, interface_number))
580 return false; 581 return false;
581 const int rv = libusb_set_interface_alt_setting( 582 const int rv = libusb_set_interface_alt_setting(
582 handle_, interface_number, alternate_setting); 583 handle_, interface_number, alternate_setting);
583 if (rv == LIBUSB_SUCCESS) { 584 if (rv == LIBUSB_SUCCESS) {
584 claimed_interfaces_[interface_number]->set_alternate_setting( 585 claimed_interfaces_[interface_number]->set_alternate_setting(
585 alternate_setting); 586 alternate_setting);
586 RefreshEndpointMap(); 587 RefreshEndpointMap();
587 } else { 588 } else {
588 VLOG(1) << "Failed to set interface (" << interface_number << ", " 589 USB_LOG(DEBUG) << "Failed to set interface " << interface_number
589 << alternate_setting 590 << " to alternate setting " << alternate_setting << ": "
590 << "): " << ConvertPlatformUsbErrorToString(rv); 591 << ConvertPlatformUsbErrorToString(rv);
591 } 592 }
592 return rv == LIBUSB_SUCCESS; 593 return rv == LIBUSB_SUCCESS;
593 } 594 }
594 595
595 bool UsbDeviceHandleImpl::ResetDevice() { 596 bool UsbDeviceHandleImpl::ResetDevice() {
596 DCHECK(thread_checker_.CalledOnValidThread()); 597 DCHECK(thread_checker_.CalledOnValidThread());
597 if (!device_) 598 if (!device_)
598 return false; 599 return false;
599 600
600 const int rv = libusb_reset_device(handle_); 601 const int rv = libusb_reset_device(handle_);
601 if (rv != LIBUSB_SUCCESS) { 602 if (rv != LIBUSB_SUCCESS) {
602 VLOG(1) << "Failed to reset device: " 603 USB_LOG(DEBUG) << "Failed to reset device: "
603 << ConvertPlatformUsbErrorToString(rv); 604 << ConvertPlatformUsbErrorToString(rv);
604 } 605 }
605 return rv == LIBUSB_SUCCESS; 606 return rv == LIBUSB_SUCCESS;
606 } 607 }
607 608
608 bool UsbDeviceHandleImpl::GetStringDescriptor(uint8 string_id, 609 bool UsbDeviceHandleImpl::GetStringDescriptor(uint8 string_id,
609 base::string16* string) { 610 base::string16* string) {
610 if (!GetSupportedLanguages()) { 611 if (!GetSupportedLanguages()) {
611 return false; 612 return false;
612 } 613 }
613 614
614 std::map<uint8, base::string16>::const_iterator it = strings_.find(string_id); 615 std::map<uint8, base::string16>::const_iterator it = strings_.find(string_id);
615 if (it != strings_.end()) { 616 if (it != strings_.end()) {
616 *string = it->second; 617 *string = it->second;
617 return true; 618 return true;
618 } 619 }
619 620
620 for (size_t i = 0; i < languages_.size(); ++i) { 621 for (size_t i = 0; i < languages_.size(); ++i) {
621 // Get the string using language ID. 622 // Get the string using language ID.
622 uint16 language_id = languages_[i]; 623 uint16 language_id = languages_[i];
623 // The 1-byte length field limits the descriptor to 256-bytes (128 char16s). 624 // The 1-byte length field limits the descriptor to 256-bytes (128 char16s).
624 base::char16 text[128]; 625 base::char16 text[128];
625 int size = 626 int size =
626 libusb_get_string_descriptor(handle_, 627 libusb_get_string_descriptor(handle_,
627 string_id, 628 string_id,
628 language_id, 629 language_id,
629 reinterpret_cast<unsigned char*>(&text[0]), 630 reinterpret_cast<unsigned char*>(&text[0]),
630 sizeof(text)); 631 sizeof(text));
631 if (size < 0) { 632 if (size < 0) {
632 VLOG(1) << "Failed to get string descriptor " << string_id << " (langid " 633 USB_LOG(DEBUG) << "Failed to get string descriptor " << string_id
633 << language_id << "): " << ConvertPlatformUsbErrorToString(size); 634 << " (langid " << language_id
635 << "): " << ConvertPlatformUsbErrorToString(size);
634 continue; 636 continue;
635 } else if (size < 2) { 637 } else if (size < 2) {
636 VLOG(1) << "String descriptor " << string_id << " (langid " << language_id 638 USB_LOG(DEBUG) << "String descriptor " << string_id << " (langid "
637 << ") has no header."; 639 << language_id << ") has no header.";
638 continue; 640 continue;
639 // The first 2 bytes of the descriptor are the total length and type tag. 641 // The first 2 bytes of the descriptor are the total length and type tag.
640 } else if ((text[0] & 0xff) != size) { 642 } else if ((text[0] & 0xff) != size) {
641 VLOG(1) << "String descriptor " << string_id << " (langid " << language_id 643 USB_LOG(DEBUG) << "String descriptor " << string_id << " (langid "
642 << ") size mismatch: " << (text[0] & 0xff) << " != " << size; 644 << language_id << ") size mismatch: " << (text[0] & 0xff)
645 << " != " << size;
643 continue; 646 continue;
644 } else if ((text[0] >> 8) != LIBUSB_DT_STRING) { 647 } else if ((text[0] >> 8) != LIBUSB_DT_STRING) {
645 VLOG(1) << "String descriptor " << string_id << " (langid " << language_id 648 USB_LOG(DEBUG) << "String descriptor " << string_id << " (langid "
646 << ") is not a string descriptor."; 649 << language_id << ") is not a string descriptor.";
647 continue; 650 continue;
648 } 651 }
649 652
650 *string = base::string16(text + 1, (size - 2) / 2); 653 *string = base::string16(text + 1, (size - 2) / 2);
651 strings_[string_id] = *string; 654 strings_[string_id] = *string;
652 return true; 655 return true;
653 } 656 }
654 657
655 return false; 658 return false;
656 } 659 }
657 660
658 void UsbDeviceHandleImpl::ControlTransfer(UsbEndpointDirection direction, 661 void UsbDeviceHandleImpl::ControlTransfer(UsbEndpointDirection direction,
659 TransferRequestType request_type, 662 TransferRequestType request_type,
660 TransferRecipient recipient, 663 TransferRecipient recipient,
661 uint8 request, 664 uint8 request,
662 uint16 value, 665 uint16 value,
663 uint16 index, 666 uint16 index,
664 net::IOBuffer* buffer, 667 net::IOBuffer* buffer,
665 size_t length, 668 size_t length,
666 unsigned int timeout, 669 unsigned int timeout,
667 const UsbTransferCallback& callback) { 670 const UsbTransferCallback& callback) {
668 if (length > UINT16_MAX) { 671 if (length > UINT16_MAX) {
669 LOG(ERROR) << "Transfer too long."; 672 USB_LOG(DEBUG) << "Transfer too long.";
670 callback.Run(USB_TRANSFER_ERROR, buffer, 0); 673 callback.Run(USB_TRANSFER_ERROR, buffer, 0);
671 return; 674 return;
672 } 675 }
673 676
674 const size_t resized_length = LIBUSB_CONTROL_SETUP_SIZE + length; 677 const size_t resized_length = LIBUSB_CONTROL_SETUP_SIZE + length;
675 scoped_refptr<net::IOBuffer> resized_buffer( 678 scoped_refptr<net::IOBuffer> resized_buffer(
676 new net::IOBufferWithSize(static_cast<int>(resized_length))); 679 new net::IOBufferWithSize(static_cast<int>(resized_length)));
677 if (!resized_buffer.get()) { 680 if (!resized_buffer.get()) {
678 callback.Run(USB_TRANSFER_ERROR, buffer, 0); 681 callback.Run(USB_TRANSFER_ERROR, buffer, 0);
679 return; 682 return;
(...skipping 12 matching lines...) Expand all
692 PostOrSubmitTransfer(transfer.Pass()); 695 PostOrSubmitTransfer(transfer.Pass());
693 } 696 }
694 697
695 void UsbDeviceHandleImpl::BulkTransfer(const UsbEndpointDirection direction, 698 void UsbDeviceHandleImpl::BulkTransfer(const UsbEndpointDirection direction,
696 const uint8 endpoint, 699 const uint8 endpoint,
697 net::IOBuffer* buffer, 700 net::IOBuffer* buffer,
698 const size_t length, 701 const size_t length,
699 const unsigned int timeout, 702 const unsigned int timeout,
700 const UsbTransferCallback& callback) { 703 const UsbTransferCallback& callback) {
701 if (length > INT_MAX) { 704 if (length > INT_MAX) {
702 LOG(ERROR) << "Transfer too long."; 705 USB_LOG(DEBUG) << "Transfer too long.";
703 callback.Run(USB_TRANSFER_ERROR, buffer, 0); 706 callback.Run(USB_TRANSFER_ERROR, buffer, 0);
704 return; 707 return;
705 } 708 }
706 709
707 scoped_ptr<Transfer> transfer = Transfer::CreateBulkTransfer( 710 scoped_ptr<Transfer> transfer = Transfer::CreateBulkTransfer(
708 ConvertTransferDirection(direction) | endpoint, buffer, 711 ConvertTransferDirection(direction) | endpoint, buffer,
709 static_cast<int>(length), timeout, callback); 712 static_cast<int>(length), timeout, callback);
710 713
711 PostOrSubmitTransfer(transfer.Pass()); 714 PostOrSubmitTransfer(transfer.Pass());
712 } 715 }
713 716
714 void UsbDeviceHandleImpl::InterruptTransfer( 717 void UsbDeviceHandleImpl::InterruptTransfer(
715 UsbEndpointDirection direction, 718 UsbEndpointDirection direction,
716 uint8 endpoint, 719 uint8 endpoint,
717 net::IOBuffer* buffer, 720 net::IOBuffer* buffer,
718 size_t length, 721 size_t length,
719 unsigned int timeout, 722 unsigned int timeout,
720 const UsbTransferCallback& callback) { 723 const UsbTransferCallback& callback) {
721 if (length > INT_MAX) { 724 if (length > INT_MAX) {
722 LOG(ERROR) << "Transfer too long."; 725 USB_LOG(DEBUG) << "Transfer too long.";
723 callback.Run(USB_TRANSFER_ERROR, buffer, 0); 726 callback.Run(USB_TRANSFER_ERROR, buffer, 0);
724 return; 727 return;
725 } 728 }
726 729
727 scoped_ptr<Transfer> transfer = Transfer::CreateInterruptTransfer( 730 scoped_ptr<Transfer> transfer = Transfer::CreateInterruptTransfer(
728 ConvertTransferDirection(direction) | endpoint, buffer, 731 ConvertTransferDirection(direction) | endpoint, buffer,
729 static_cast<int>(length), timeout, callback); 732 static_cast<int>(length), timeout, callback);
730 733
731 PostOrSubmitTransfer(transfer.Pass()); 734 PostOrSubmitTransfer(transfer.Pass());
732 } 735 }
733 736
734 void UsbDeviceHandleImpl::IsochronousTransfer( 737 void UsbDeviceHandleImpl::IsochronousTransfer(
735 const UsbEndpointDirection direction, 738 const UsbEndpointDirection direction,
736 const uint8 endpoint, 739 const uint8 endpoint,
737 net::IOBuffer* buffer, 740 net::IOBuffer* buffer,
738 const size_t length, 741 const size_t length,
739 const unsigned int packets, 742 const unsigned int packets,
740 const unsigned int packet_length, 743 const unsigned int packet_length,
741 const unsigned int timeout, 744 const unsigned int timeout,
742 const UsbTransferCallback& callback) { 745 const UsbTransferCallback& callback) {
743 if (length > INT_MAX) { 746 if (length > INT_MAX) {
744 LOG(ERROR) << "Transfer too long."; 747 USB_LOG(DEBUG) << "Transfer too long.";
745 callback.Run(USB_TRANSFER_ERROR, buffer, 0); 748 callback.Run(USB_TRANSFER_ERROR, buffer, 0);
746 return; 749 return;
747 } 750 }
748 751
749 scoped_ptr<Transfer> transfer = Transfer::CreateIsochronousTransfer( 752 scoped_ptr<Transfer> transfer = Transfer::CreateIsochronousTransfer(
750 ConvertTransferDirection(direction) | endpoint, buffer, 753 ConvertTransferDirection(direction) | endpoint, buffer,
751 static_cast<int>(length), packets, packet_length, timeout, callback); 754 static_cast<int>(length), packets, packet_length, timeout, callback);
752 755
753 PostOrSubmitTransfer(transfer.Pass()); 756 PostOrSubmitTransfer(transfer.Pass());
754 } 757 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 823
821 // The 1-byte length field limits the descriptor to 256-bytes (128 uint16s). 824 // The 1-byte length field limits the descriptor to 256-bytes (128 uint16s).
822 uint16 languages[128]; 825 uint16 languages[128];
823 int size = libusb_get_string_descriptor( 826 int size = libusb_get_string_descriptor(
824 handle_, 827 handle_,
825 0, 828 0,
826 0, 829 0,
827 reinterpret_cast<unsigned char*>(&languages[0]), 830 reinterpret_cast<unsigned char*>(&languages[0]),
828 sizeof(languages)); 831 sizeof(languages));
829 if (size < 0) { 832 if (size < 0) {
830 VLOG(1) << "Failed to get list of supported languages: " 833 USB_LOG(DEBUG) << "Failed to get list of supported languages: "
831 << ConvertPlatformUsbErrorToString(size); 834 << ConvertPlatformUsbErrorToString(size);
832 return false; 835 return false;
833 } else if (size < 2) { 836 } else if (size < 2) {
834 VLOG(1) << "String descriptor zero has no header."; 837 USB_LOG(DEBUG) << "String descriptor zero has no header.";
835 return false; 838 return false;
836 // The first 2 bytes of the descriptor are the total length and type tag. 839 // The first 2 bytes of the descriptor are the total length and type tag.
837 } else if ((languages[0] & 0xff) != size) { 840 } else if ((languages[0] & 0xff) != size) {
838 VLOG(1) << "String descriptor zero size mismatch: " << (languages[0] & 0xff) 841 USB_LOG(DEBUG) << "String descriptor zero size mismatch: "
839 << " != " << size; 842 << (languages[0] & 0xff) << " != " << size;
840 return false; 843 return false;
841 } else if ((languages[0] >> 8) != LIBUSB_DT_STRING) { 844 } else if ((languages[0] >> 8) != LIBUSB_DT_STRING) {
842 VLOG(1) << "String descriptor zero is not a string descriptor."; 845 USB_LOG(DEBUG) << "String descriptor zero is not a string descriptor.";
843 return false; 846 return false;
844 } 847 }
845 848
846 languages_.assign(languages[1], languages[(size - 2) / 2]); 849 languages_.assign(languages[1], languages[(size - 2) / 2]);
847 return true; 850 return true;
848 } 851 }
849 852
850 void UsbDeviceHandleImpl::InternalClose() { 853 void UsbDeviceHandleImpl::InternalClose() {
851 DCHECK(thread_checker_.CalledOnValidThread()); 854 DCHECK(thread_checker_.CalledOnValidThread());
852 if (!device_) 855 if (!device_)
853 return; 856 return;
854 857
855 // Cancel all the transfers. 858 // Cancel all the transfers.
856 for (Transfer* transfer : transfers_) { 859 for (Transfer* transfer : transfers_) {
857 // The callback will be called some time later. 860 // The callback will be called some time later.
858 transfer->Cancel(); 861 transfer->Cancel();
859 } 862 }
860 863
861 // Attempt-release all the interfaces. 864 // Attempt-release all the interfaces.
862 // It will be retained until the transfer cancellation is finished. 865 // It will be retained until the transfer cancellation is finished.
863 claimed_interfaces_.clear(); 866 claimed_interfaces_.clear();
864 867
865 // Cannot close device handle here. Need to wait for libusb_cancel_transfer to 868 // Cannot close device handle here. Need to wait for libusb_cancel_transfer to
866 // finish. 869 // finish.
867 device_ = NULL; 870 device_ = NULL;
868 } 871 }
869 872
870 } // namespace device 873 } // namespace device
OLDNEW
« no previous file with comments | « device/usb/usb.gyp ('k') | device/usb/usb_device_impl.cc » ('j') | device/usb/usb_device_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698