OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_usbfs.h" | 5 #include "device/usb/usb_device_handle_usbfs.h" |
6 | 6 |
7 #if defined(OS_ANDROID) && __ANDROID_API__ < 21 | 7 #if defined(OS_ANDROID) && __ANDROID_API__ < 21 |
8 #include <linux/usb_ch9.h> | 8 #include <linux/usb_ch9.h> |
9 #else | 9 #else |
10 #include <linux/usb/ch9.h> | 10 #include <linux/usb/ch9.h> |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "base/threading/thread_restrictions.h" | 25 #include "base/threading/thread_restrictions.h" |
26 #include "base/threading/thread_task_runner_handle.h" | 26 #include "base/threading/thread_task_runner_handle.h" |
27 #include "components/device_event_log/device_event_log.h" | 27 #include "components/device_event_log/device_event_log.h" |
28 #include "device/usb/usb_device_linux.h" | 28 #include "device/usb/usb_device_linux.h" |
29 #include "net/base/io_buffer.h" | 29 #include "net/base/io_buffer.h" |
30 | 30 |
31 namespace device { | 31 namespace device { |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 uint8_t ConvertEndpointDirection(UsbEndpointDirection direction) { | 35 uint8_t ConvertEndpointDirection(UsbTransferDirection direction) { |
36 switch (direction) { | 36 switch (direction) { |
37 case USB_DIRECTION_INBOUND: | 37 case UsbTransferDirection::INBOUND: |
38 return USB_DIR_IN; | 38 return USB_DIR_IN; |
39 case USB_DIRECTION_OUTBOUND: | 39 case UsbTransferDirection::OUTBOUND: |
40 return USB_DIR_OUT; | 40 return USB_DIR_OUT; |
41 } | 41 } |
42 NOTREACHED(); | 42 NOTREACHED(); |
43 return 0; | 43 return 0; |
44 } | 44 } |
45 | 45 |
46 uint8_t ConvertRequestType(UsbDeviceHandle::TransferRequestType request_type) { | 46 uint8_t ConvertRequestType(UsbControlTransferType request_type) { |
47 switch (request_type) { | 47 switch (request_type) { |
48 case UsbDeviceHandle::STANDARD: | 48 case UsbControlTransferType::STANDARD: |
49 return USB_TYPE_STANDARD; | 49 return USB_TYPE_STANDARD; |
50 case UsbDeviceHandle::CLASS: | 50 case UsbControlTransferType::CLASS: |
51 return USB_TYPE_CLASS; | 51 return USB_TYPE_CLASS; |
52 case UsbDeviceHandle::VENDOR: | 52 case UsbControlTransferType::VENDOR: |
53 return USB_TYPE_VENDOR; | 53 return USB_TYPE_VENDOR; |
54 case UsbDeviceHandle::RESERVED: | 54 case UsbControlTransferType::RESERVED: |
55 return USB_TYPE_RESERVED; | 55 return USB_TYPE_RESERVED; |
56 } | 56 } |
57 NOTREACHED(); | 57 NOTREACHED(); |
58 return 0; | 58 return 0; |
59 } | 59 } |
60 | 60 |
61 uint8_t ConvertRecipient(UsbDeviceHandle::TransferRecipient recipient) { | 61 uint8_t ConvertRecipient(UsbControlTransferRecipient recipient) { |
62 switch (recipient) { | 62 switch (recipient) { |
63 case UsbDeviceHandle::DEVICE: | 63 case UsbControlTransferRecipient::DEVICE: |
64 return USB_RECIP_DEVICE; | 64 return USB_RECIP_DEVICE; |
65 case UsbDeviceHandle::INTERFACE: | 65 case UsbControlTransferRecipient::INTERFACE: |
66 return USB_RECIP_INTERFACE; | 66 return USB_RECIP_INTERFACE; |
67 case UsbDeviceHandle::ENDPOINT: | 67 case UsbControlTransferRecipient::ENDPOINT: |
68 return USB_RECIP_ENDPOINT; | 68 return USB_RECIP_ENDPOINT; |
69 case UsbDeviceHandle::OTHER: | 69 case UsbControlTransferRecipient::OTHER: |
70 return USB_RECIP_OTHER; | 70 return USB_RECIP_OTHER; |
71 } | 71 } |
72 NOTREACHED(); | 72 NOTREACHED(); |
73 return 0; | 73 return 0; |
74 } | 74 } |
75 | 75 |
76 scoped_refptr<net::IOBuffer> BuildControlTransferBuffer( | 76 scoped_refptr<net::IOBuffer> BuildControlTransferBuffer( |
77 UsbEndpointDirection direction, | 77 UsbTransferDirection direction, |
78 UsbDeviceHandle::TransferRequestType request_type, | 78 UsbControlTransferType request_type, |
79 UsbDeviceHandle::TransferRecipient recipient, | 79 UsbControlTransferRecipient recipient, |
80 uint8_t request, | 80 uint8_t request, |
81 uint16_t value, | 81 uint16_t value, |
82 uint16_t index, | 82 uint16_t index, |
83 scoped_refptr<net::IOBuffer> original_buffer, | 83 scoped_refptr<net::IOBuffer> original_buffer, |
84 size_t length) { | 84 size_t length) { |
85 scoped_refptr<net::IOBuffer> new_buffer( | 85 scoped_refptr<net::IOBuffer> new_buffer( |
86 new net::IOBuffer(length + sizeof(usb_ctrlrequest))); | 86 new net::IOBuffer(length + sizeof(usb_ctrlrequest))); |
87 usb_ctrlrequest* setup = | 87 usb_ctrlrequest* setup = |
88 reinterpret_cast<usb_ctrlrequest*>(new_buffer->data()); | 88 reinterpret_cast<usb_ctrlrequest*>(new_buffer->data()); |
89 setup->bRequestType = ConvertEndpointDirection(direction) | | 89 setup->bRequestType = ConvertEndpointDirection(direction) | |
90 ConvertRequestType(request_type) | | 90 ConvertRequestType(request_type) | |
91 ConvertRecipient(recipient); | 91 ConvertRecipient(recipient); |
92 setup->bRequest = request; | 92 setup->bRequest = request; |
93 setup->wValue = value; | 93 setup->wValue = value; |
94 setup->wIndex = index; | 94 setup->wIndex = index; |
95 setup->wLength = length; | 95 setup->wLength = length; |
96 memcpy(new_buffer->data() + sizeof(usb_ctrlrequest), original_buffer->data(), | 96 memcpy(new_buffer->data() + sizeof(usb_ctrlrequest), original_buffer->data(), |
97 length); | 97 length); |
98 return new_buffer; | 98 return new_buffer; |
99 } | 99 } |
100 | 100 |
101 uint8_t ConvertTransferType(UsbTransferType type) { | 101 uint8_t ConvertTransferType(UsbTransferType type) { |
102 switch (type) { | 102 switch (type) { |
103 case USB_TRANSFER_CONTROL: | 103 case UsbTransferType::CONTROL: |
104 return USBDEVFS_URB_TYPE_CONTROL; | 104 return USBDEVFS_URB_TYPE_CONTROL; |
105 case USB_TRANSFER_ISOCHRONOUS: | 105 case UsbTransferType::ISOCHRONOUS: |
106 return USBDEVFS_URB_TYPE_ISO; | 106 return USBDEVFS_URB_TYPE_ISO; |
107 case USB_TRANSFER_BULK: | 107 case UsbTransferType::BULK: |
108 return USBDEVFS_URB_TYPE_BULK; | 108 return USBDEVFS_URB_TYPE_BULK; |
109 case USB_TRANSFER_INTERRUPT: | 109 case UsbTransferType::INTERRUPT: |
110 return USBDEVFS_URB_TYPE_INTERRUPT; | 110 return USBDEVFS_URB_TYPE_INTERRUPT; |
111 } | 111 } |
112 NOTREACHED(); | 112 NOTREACHED(); |
113 return 0; | 113 return 0; |
114 } | 114 } |
115 | 115 |
116 UsbTransferStatus ConvertTransferResult(int rc) { | 116 UsbTransferStatus ConvertTransferResult(int rc) { |
117 switch (rc) { | 117 switch (rc) { |
118 case 0: | 118 case 0: |
119 return USB_TRANSFER_COMPLETED; | 119 return UsbTransferStatus::COMPLETED; |
120 case EPIPE: | 120 case EPIPE: |
121 return USB_TRANSFER_STALLED; | 121 return UsbTransferStatus::STALLED; |
122 case ENODEV: | 122 case ENODEV: |
123 case ESHUTDOWN: | 123 case ESHUTDOWN: |
124 case EPROTO: | 124 case EPROTO: |
125 return USB_TRANSFER_DISCONNECT; | 125 return UsbTransferStatus::DISCONNECT; |
126 default: | 126 default: |
127 // TODO(reillyg): Add a specific error message whenever one of the cases | 127 // TODO(reillyg): Add a specific error message whenever one of the cases |
128 // above fails to match. | 128 // above fails to match. |
129 USB_LOG(ERROR) << "Unknown system error: " | 129 USB_LOG(ERROR) << "Unknown system error: " |
130 << logging::SystemErrorCodeToString(rc); | 130 << logging::SystemErrorCodeToString(rc); |
131 return USB_TRANSFER_ERROR; | 131 return UsbTransferStatus::TRANSFER_ERROR; |
132 } | 132 } |
133 } | 133 } |
134 | 134 |
135 } // namespace | 135 } // namespace |
136 | 136 |
137 class UsbDeviceHandleUsbfs::FileThreadHelper { | 137 class UsbDeviceHandleUsbfs::FileThreadHelper { |
138 public: | 138 public: |
139 FileThreadHelper(base::ScopedFD fd, | 139 FileThreadHelper(base::ScopedFD fd, |
140 scoped_refptr<UsbDeviceHandleUsbfs> device_handle, | 140 scoped_refptr<UsbDeviceHandleUsbfs> device_handle, |
141 scoped_refptr<base::SequencedTaskRunner> task_runner); | 141 scoped_refptr<base::SequencedTaskRunner> task_runner); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 if (!device_) | 430 if (!device_) |
431 return; // Already closed. | 431 return; // Already closed. |
432 | 432 |
433 // On the |task_runner_| thread check |device_| to see if the handle is | 433 // On the |task_runner_| thread check |device_| to see if the handle is |
434 // closed. On the |blocking_task_runner_| thread check |fd_.is_valid()| to | 434 // closed. On the |blocking_task_runner_| thread check |fd_.is_valid()| to |
435 // see if the handle is closed. | 435 // see if the handle is closed. |
436 device_->HandleClosed(this); | 436 device_->HandleClosed(this); |
437 device_ = nullptr; | 437 device_ = nullptr; |
438 | 438 |
439 for (const auto& transfer : transfers_) | 439 for (const auto& transfer : transfers_) |
440 CancelTransfer(transfer.get(), USB_TRANSFER_CANCELLED); | 440 CancelTransfer(transfer.get(), UsbTransferStatus::CANCELLED); |
441 | 441 |
442 // Releases |helper_|. | 442 // Releases |helper_|. |
443 blocking_task_runner_->PostTask( | 443 blocking_task_runner_->PostTask( |
444 FROM_HERE, base::Bind(&UsbDeviceHandleUsbfs::CloseBlocking, this)); | 444 FROM_HERE, base::Bind(&UsbDeviceHandleUsbfs::CloseBlocking, this)); |
445 } | 445 } |
446 | 446 |
447 void UsbDeviceHandleUsbfs::SetConfiguration(int configuration_value, | 447 void UsbDeviceHandleUsbfs::SetConfiguration(int configuration_value, |
448 const ResultCallback& callback) { | 448 const ResultCallback& callback) { |
449 if (!device_) { | 449 if (!device_) { |
450 task_runner_->PostTask(FROM_HERE, base::Bind(callback, false)); | 450 task_runner_->PostTask(FROM_HERE, base::Bind(callback, false)); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 | 544 |
545 // USBDEVFS_CLEAR_HALT is synchronous because it issues a CLEAR_FEATURE | 545 // USBDEVFS_CLEAR_HALT is synchronous because it issues a CLEAR_FEATURE |
546 // request to the device so it must be performed on a thread where it is okay | 546 // request to the device so it must be performed on a thread where it is okay |
547 // to block. | 547 // to block. |
548 blocking_task_runner_->PostTask( | 548 blocking_task_runner_->PostTask( |
549 FROM_HERE, | 549 FROM_HERE, |
550 base::Bind(&UsbDeviceHandleUsbfs::FileThreadHelper::ClearHalt, | 550 base::Bind(&UsbDeviceHandleUsbfs::FileThreadHelper::ClearHalt, |
551 base::Unretained(helper_.get()), endpoint_address, callback)); | 551 base::Unretained(helper_.get()), endpoint_address, callback)); |
552 } | 552 } |
553 | 553 |
554 void UsbDeviceHandleUsbfs::ControlTransfer(UsbEndpointDirection direction, | 554 void UsbDeviceHandleUsbfs::ControlTransfer( |
555 TransferRequestType request_type, | 555 UsbTransferDirection direction, |
556 TransferRecipient recipient, | 556 UsbControlTransferType request_type, |
557 uint8_t request, | 557 UsbControlTransferRecipient recipient, |
558 uint16_t value, | 558 uint8_t request, |
559 uint16_t index, | 559 uint16_t value, |
560 scoped_refptr<net::IOBuffer> buffer, | 560 uint16_t index, |
561 size_t length, | 561 scoped_refptr<net::IOBuffer> buffer, |
562 unsigned int timeout, | 562 size_t length, |
563 const TransferCallback& callback) { | 563 unsigned int timeout, |
| 564 const TransferCallback& callback) { |
564 if (!device_) { | 565 if (!device_) { |
565 task_runner_->PostTask( | 566 task_runner_->PostTask( |
566 FROM_HERE, base::Bind(callback, USB_TRANSFER_DISCONNECT, nullptr, 0)); | 567 FROM_HERE, |
| 568 base::Bind(callback, UsbTransferStatus::DISCONNECT, nullptr, 0)); |
567 return; | 569 return; |
568 } | 570 } |
569 | 571 |
570 std::unique_ptr<Transfer> transfer(new (0) | 572 std::unique_ptr<Transfer> transfer(new (0) |
571 Transfer(buffer, callback, nullptr)); | 573 Transfer(buffer, callback, nullptr)); |
572 transfer->control_transfer_buffer = | 574 transfer->control_transfer_buffer = |
573 BuildControlTransferBuffer(direction, request_type, recipient, request, | 575 BuildControlTransferBuffer(direction, request_type, recipient, request, |
574 value, index, buffer, length); | 576 value, index, buffer, length); |
575 transfer->urb.type = USBDEVFS_URB_TYPE_CONTROL; | 577 transfer->urb.type = USBDEVFS_URB_TYPE_CONTROL; |
576 transfer->urb.endpoint = 0; | 578 transfer->urb.endpoint = 0; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 const std::vector<uint32_t>& packet_lengths, | 612 const std::vector<uint32_t>& packet_lengths, |
611 unsigned int timeout, | 613 unsigned int timeout, |
612 const IsochronousTransferCallback& callback) { | 614 const IsochronousTransferCallback& callback) { |
613 uint8_t endpoint_address = USB_DIR_OUT | endpoint_number; | 615 uint8_t endpoint_address = USB_DIR_OUT | endpoint_number; |
614 size_t total_length = | 616 size_t total_length = |
615 std::accumulate(packet_lengths.begin(), packet_lengths.end(), 0u); | 617 std::accumulate(packet_lengths.begin(), packet_lengths.end(), 0u); |
616 IsochronousTransferInternal(endpoint_address, buffer, total_length, | 618 IsochronousTransferInternal(endpoint_address, buffer, total_length, |
617 packet_lengths, timeout, callback); | 619 packet_lengths, timeout, callback); |
618 } | 620 } |
619 | 621 |
620 void UsbDeviceHandleUsbfs::GenericTransfer(UsbEndpointDirection direction, | 622 void UsbDeviceHandleUsbfs::GenericTransfer(UsbTransferDirection direction, |
621 uint8_t endpoint_number, | 623 uint8_t endpoint_number, |
622 scoped_refptr<net::IOBuffer> buffer, | 624 scoped_refptr<net::IOBuffer> buffer, |
623 size_t length, | 625 size_t length, |
624 unsigned int timeout, | 626 unsigned int timeout, |
625 const TransferCallback& callback) { | 627 const TransferCallback& callback) { |
626 if (task_runner_->BelongsToCurrentThread()) { | 628 if (task_runner_->BelongsToCurrentThread()) { |
627 GenericTransferInternal(direction, endpoint_number, buffer, length, timeout, | 629 GenericTransferInternal(direction, endpoint_number, buffer, length, timeout, |
628 callback, task_runner_); | 630 callback, task_runner_); |
629 } else { | 631 } else { |
630 task_runner_->PostTask( | 632 task_runner_->PostTask( |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 } | 684 } |
683 | 685 |
684 void UsbDeviceHandleUsbfs::IsochronousTransferInternal( | 686 void UsbDeviceHandleUsbfs::IsochronousTransferInternal( |
685 uint8_t endpoint_address, | 687 uint8_t endpoint_address, |
686 scoped_refptr<net::IOBuffer> buffer, | 688 scoped_refptr<net::IOBuffer> buffer, |
687 size_t total_length, | 689 size_t total_length, |
688 const std::vector<uint32_t>& packet_lengths, | 690 const std::vector<uint32_t>& packet_lengths, |
689 unsigned int timeout, | 691 unsigned int timeout, |
690 const IsochronousTransferCallback& callback) { | 692 const IsochronousTransferCallback& callback) { |
691 if (!device_) { | 693 if (!device_) { |
692 ReportIsochronousError(packet_lengths, callback, USB_TRANSFER_DISCONNECT); | 694 ReportIsochronousError(packet_lengths, callback, |
| 695 UsbTransferStatus::DISCONNECT); |
693 return; | 696 return; |
694 } | 697 } |
695 | 698 |
696 auto it = endpoints_.find(endpoint_address); | 699 auto it = endpoints_.find(endpoint_address); |
697 if (it == endpoints_.end()) { | 700 if (it == endpoints_.end()) { |
698 USB_LOG(USER) << "Endpoint address " << static_cast<int>(endpoint_address) | 701 USB_LOG(USER) << "Endpoint address " << static_cast<int>(endpoint_address) |
699 << " is not part of a claimed interface."; | 702 << " is not part of a claimed interface."; |
700 ReportIsochronousError(packet_lengths, callback, USB_TRANSFER_ERROR); | 703 ReportIsochronousError(packet_lengths, callback, |
| 704 UsbTransferStatus::TRANSFER_ERROR); |
701 return; | 705 return; |
702 } | 706 } |
703 | 707 |
704 std::unique_ptr<Transfer> transfer(new (packet_lengths.size()) | 708 std::unique_ptr<Transfer> transfer(new (packet_lengths.size()) |
705 Transfer(buffer, callback)); | 709 Transfer(buffer, callback)); |
706 transfer->urb.type = USBDEVFS_URB_TYPE_ISO; | 710 transfer->urb.type = USBDEVFS_URB_TYPE_ISO; |
707 transfer->urb.endpoint = endpoint_address; | 711 transfer->urb.endpoint = endpoint_address; |
708 transfer->urb.buffer_length = total_length; | 712 transfer->urb.buffer_length = total_length; |
709 | 713 |
710 for (size_t i = 0; i < packet_lengths.size(); ++i) | 714 for (size_t i = 0; i < packet_lengths.size(); ++i) |
711 transfer->urb.iso_frame_desc[i].length = packet_lengths[i]; | 715 transfer->urb.iso_frame_desc[i].length = packet_lengths[i]; |
712 | 716 |
713 // USBDEVFS_SUBMITURB appears to be non-blocking as completion is reported | 717 // USBDEVFS_SUBMITURB appears to be non-blocking as completion is reported |
714 // by USBDEVFS_REAPURBNDELAY. This code assumes a recent kernel that can | 718 // by USBDEVFS_REAPURBNDELAY. This code assumes a recent kernel that can |
715 // accept arbitrarily large transfer requests, hopefully also using a scatter- | 719 // accept arbitrarily large transfer requests, hopefully also using a scatter- |
716 // gather list. | 720 // gather list. |
717 int rc = HANDLE_EINTR(ioctl(fd_, USBDEVFS_SUBMITURB, &transfer->urb)); | 721 int rc = HANDLE_EINTR(ioctl(fd_, USBDEVFS_SUBMITURB, &transfer->urb)); |
718 if (rc) { | 722 if (rc) { |
719 rc = logging::GetLastSystemErrorCode(); | 723 rc = logging::GetLastSystemErrorCode(); |
720 USB_PLOG(DEBUG) << "Failed to submit transfer"; | 724 USB_PLOG(DEBUG) << "Failed to submit transfer"; |
721 ReportIsochronousError(packet_lengths, callback, ConvertTransferResult(rc)); | 725 ReportIsochronousError(packet_lengths, callback, ConvertTransferResult(rc)); |
722 } else { | 726 } else { |
723 SetUpTimeoutCallback(transfer.get(), timeout); | 727 SetUpTimeoutCallback(transfer.get(), timeout); |
724 transfers_.push_back(std::move(transfer)); | 728 transfers_.push_back(std::move(transfer)); |
725 } | 729 } |
726 } | 730 } |
727 | 731 |
728 void UsbDeviceHandleUsbfs::GenericTransferInternal( | 732 void UsbDeviceHandleUsbfs::GenericTransferInternal( |
729 UsbEndpointDirection direction, | 733 UsbTransferDirection direction, |
730 uint8_t endpoint_number, | 734 uint8_t endpoint_number, |
731 scoped_refptr<net::IOBuffer> buffer, | 735 scoped_refptr<net::IOBuffer> buffer, |
732 size_t length, | 736 size_t length, |
733 unsigned int timeout, | 737 unsigned int timeout, |
734 const TransferCallback& callback, | 738 const TransferCallback& callback, |
735 scoped_refptr<base::SingleThreadTaskRunner> callback_runner) { | 739 scoped_refptr<base::SingleThreadTaskRunner> callback_runner) { |
736 if (!device_) { | 740 if (!device_) { |
737 callback_runner->PostTask( | 741 callback_runner->PostTask( |
738 FROM_HERE, base::Bind(callback, USB_TRANSFER_DISCONNECT, nullptr, 0)); | 742 FROM_HERE, |
| 743 base::Bind(callback, UsbTransferStatus::DISCONNECT, nullptr, 0)); |
739 return; | 744 return; |
740 } | 745 } |
741 | 746 |
742 uint8_t endpoint_address = | 747 uint8_t endpoint_address = |
743 ConvertEndpointDirection(direction) | endpoint_number; | 748 ConvertEndpointDirection(direction) | endpoint_number; |
744 auto it = endpoints_.find(endpoint_address); | 749 auto it = endpoints_.find(endpoint_address); |
745 if (it == endpoints_.end()) { | 750 if (it == endpoints_.end()) { |
746 USB_LOG(USER) << "Endpoint address " << static_cast<int>(endpoint_address) | 751 USB_LOG(USER) << "Endpoint address " << static_cast<int>(endpoint_address) |
747 << " is not part of a claimed interface."; | 752 << " is not part of a claimed interface."; |
748 callback_runner->PostTask( | 753 callback_runner->PostTask( |
749 FROM_HERE, base::Bind(callback, USB_TRANSFER_ERROR, nullptr, 0)); | 754 FROM_HERE, |
| 755 base::Bind(callback, UsbTransferStatus::TRANSFER_ERROR, nullptr, 0)); |
750 return; | 756 return; |
751 } | 757 } |
752 | 758 |
753 std::unique_ptr<Transfer> transfer( | 759 std::unique_ptr<Transfer> transfer( |
754 new (0) Transfer(buffer, callback, callback_runner)); | 760 new (0) Transfer(buffer, callback, callback_runner)); |
755 transfer->urb.endpoint = endpoint_address; | 761 transfer->urb.endpoint = endpoint_address; |
756 transfer->urb.buffer_length = length; | 762 transfer->urb.buffer_length = length; |
757 transfer->urb.type = ConvertTransferType(it->second.type); | 763 transfer->urb.type = ConvertTransferType(it->second.type); |
758 | 764 |
759 // USBDEVFS_SUBMITURB appears to be non-blocking as completion is reported | 765 // USBDEVFS_SUBMITURB appears to be non-blocking as completion is reported |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 packets[i].status = status; | 866 packets[i].status = status; |
861 } | 867 } |
862 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr, packets)); | 868 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr, packets)); |
863 } | 869 } |
864 | 870 |
865 void UsbDeviceHandleUsbfs::SetUpTimeoutCallback(Transfer* transfer, | 871 void UsbDeviceHandleUsbfs::SetUpTimeoutCallback(Transfer* transfer, |
866 unsigned int timeout) { | 872 unsigned int timeout) { |
867 if (timeout > 0) { | 873 if (timeout > 0) { |
868 transfer->timeout_closure.Reset( | 874 transfer->timeout_closure.Reset( |
869 base::Bind(&UsbDeviceHandleUsbfs::CancelTransfer, this, transfer, | 875 base::Bind(&UsbDeviceHandleUsbfs::CancelTransfer, this, transfer, |
870 USB_TRANSFER_TIMEOUT)); | 876 UsbTransferStatus::TIMEOUT)); |
871 task_runner_->PostDelayedTask(FROM_HERE, | 877 task_runner_->PostDelayedTask(FROM_HERE, |
872 transfer->timeout_closure.callback(), | 878 transfer->timeout_closure.callback(), |
873 base::TimeDelta::FromMilliseconds(timeout)); | 879 base::TimeDelta::FromMilliseconds(timeout)); |
874 } | 880 } |
875 } | 881 } |
876 | 882 |
877 std::unique_ptr<UsbDeviceHandleUsbfs::Transfer> | 883 std::unique_ptr<UsbDeviceHandleUsbfs::Transfer> |
878 UsbDeviceHandleUsbfs::RemoveFromTransferList(Transfer* transfer_ptr) { | 884 UsbDeviceHandleUsbfs::RemoveFromTransferList(Transfer* transfer_ptr) { |
879 auto it = std::find_if( | 885 auto it = std::find_if( |
880 transfers_.begin(), transfers_.end(), | 886 transfers_.begin(), transfers_.end(), |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 } | 921 } |
916 | 922 |
917 | 923 |
918 void UsbDeviceHandleUsbfs::UrbDiscarded(Transfer* transfer) { | 924 void UsbDeviceHandleUsbfs::UrbDiscarded(Transfer* transfer) { |
919 transfer->discarded = true; | 925 transfer->discarded = true; |
920 if (transfer->reaped) | 926 if (transfer->reaped) |
921 RemoveFromTransferList(transfer); | 927 RemoveFromTransferList(transfer); |
922 } | 928 } |
923 | 929 |
924 } // namespace device | 930 } // namespace device |
OLD | NEW |