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 "components/usb_service/usb_device_handle_impl.h" | 5 #include "components/usb_service/usb_device_handle_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 scoped_refptr<UsbContext> context, | 189 scoped_refptr<UsbContext> context, |
190 UsbDeviceImpl* device, | 190 UsbDeviceImpl* device, |
191 PlatformUsbDeviceHandle handle, | 191 PlatformUsbDeviceHandle handle, |
192 scoped_refptr<UsbConfigDescriptor> interfaces) | 192 scoped_refptr<UsbConfigDescriptor> interfaces) |
193 : device_(device), | 193 : device_(device), |
194 handle_(handle), | 194 handle_(handle), |
195 interfaces_(interfaces), | 195 interfaces_(interfaces), |
196 context_(context) { | 196 context_(context) { |
197 DCHECK(thread_checker_.CalledOnValidThread()); | 197 DCHECK(thread_checker_.CalledOnValidThread()); |
198 DCHECK(handle) << "Cannot create device with NULL handle."; | 198 DCHECK(handle) << "Cannot create device with NULL handle."; |
199 DCHECK(interfaces_) << "Unable to list interfaces"; | 199 DCHECK(interfaces_.get()) << "Unable to list interfaces"; |
200 } | 200 } |
201 | 201 |
202 UsbDeviceHandleImpl::~UsbDeviceHandleImpl() { | 202 UsbDeviceHandleImpl::~UsbDeviceHandleImpl() { |
203 DCHECK(thread_checker_.CalledOnValidThread()); | 203 DCHECK(thread_checker_.CalledOnValidThread()); |
204 | 204 |
205 libusb_close(handle_); | 205 libusb_close(handle_); |
206 handle_ = NULL; | 206 handle_ = NULL; |
207 } | 207 } |
208 | 208 |
209 scoped_refptr<UsbDevice> UsbDeviceHandleImpl::GetDevice() const { | 209 scoped_refptr<UsbDevice> UsbDeviceHandleImpl::GetDevice() const { |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 const unsigned int timeout, | 525 const unsigned int timeout, |
526 const UsbTransferCallback& callback) { | 526 const UsbTransferCallback& callback) { |
527 if (!device_) { | 527 if (!device_) { |
528 callback.Run(USB_TRANSFER_DISCONNECT, buffer, 0); | 528 callback.Run(USB_TRANSFER_DISCONNECT, buffer, 0); |
529 return; | 529 return; |
530 } | 530 } |
531 | 531 |
532 const size_t resized_length = LIBUSB_CONTROL_SETUP_SIZE + length; | 532 const size_t resized_length = LIBUSB_CONTROL_SETUP_SIZE + length; |
533 scoped_refptr<net::IOBuffer> resized_buffer( | 533 scoped_refptr<net::IOBuffer> resized_buffer( |
534 new net::IOBufferWithSize(static_cast<int>(resized_length))); | 534 new net::IOBufferWithSize(static_cast<int>(resized_length))); |
535 if (!resized_buffer) { | 535 if (!resized_buffer.get()) { |
536 callback.Run(USB_TRANSFER_ERROR, buffer, 0); | 536 callback.Run(USB_TRANSFER_ERROR, buffer, 0); |
537 return; | 537 return; |
538 } | 538 } |
539 memcpy(resized_buffer->data() + LIBUSB_CONTROL_SETUP_SIZE, | 539 memcpy(resized_buffer->data() + LIBUSB_CONTROL_SETUP_SIZE, |
540 buffer->data(), | 540 buffer->data(), |
541 static_cast<int>(length)); | 541 static_cast<int>(length)); |
542 | 542 |
543 PlatformUsbTransferHandle const transfer = libusb_alloc_transfer(0); | 543 PlatformUsbTransferHandle const transfer = libusb_alloc_transfer(0); |
544 const uint8 converted_type = | 544 const uint8 converted_type = |
545 CreateRequestType(direction, request_type, recipient); | 545 CreateRequestType(direction, request_type, recipient); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 // Attempt-release all the interfaces. | 757 // Attempt-release all the interfaces. |
758 // It will be retained until the transfer cancellation is finished. | 758 // It will be retained until the transfer cancellation is finished. |
759 claimed_interfaces_.clear(); | 759 claimed_interfaces_.clear(); |
760 | 760 |
761 // Cannot close device handle here. Need to wait for libusb_cancel_transfer to | 761 // Cannot close device handle here. Need to wait for libusb_cancel_transfer to |
762 // finish. | 762 // finish. |
763 device_ = NULL; | 763 device_ = NULL; |
764 } | 764 } |
765 | 765 |
766 } // namespace usb_service | 766 } // namespace usb_service |
OLD | NEW |