| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/usb/usb_device.h" | 5 #include "chrome/browser/usb/usb_device.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "base/synchronization/lock.h" | 8 #include "base/synchronization/lock.h" |
| 9 #include "chrome/browser/usb/usb_service.h" | 9 #include "chrome/browser/usb/usb_service.h" |
| 10 #include "third_party/libusb/src/libusb/libusb.h" | 10 #include "third_party/libusb/src/libusb/libusb.h" |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 SubmitTransfer(transfer, USB_TRANSFER_INTERRUPT, buffer, length, callback); | 272 SubmitTransfer(transfer, USB_TRANSFER_INTERRUPT, buffer, length, callback); |
| 273 } | 273 } |
| 274 | 274 |
| 275 void UsbDevice::IsochronousTransfer(const TransferDirection direction, | 275 void UsbDevice::IsochronousTransfer(const TransferDirection direction, |
| 276 const uint8 endpoint, net::IOBuffer* buffer, const size_t length, | 276 const uint8 endpoint, net::IOBuffer* buffer, const size_t length, |
| 277 const unsigned int packets, const unsigned int packet_length, | 277 const unsigned int packets, const unsigned int packet_length, |
| 278 const unsigned int timeout, const UsbTransferCallback& callback) { | 278 const unsigned int timeout, const UsbTransferCallback& callback) { |
| 279 CheckDevice(); | 279 CheckDevice(); |
| 280 | 280 |
| 281 const uint64 total_length = packets * packet_length; | 281 const uint64 total_length = packets * packet_length; |
| 282 if (total_length > length) { | 282 CHECK(packets > length || total_length > length) << |
| 283 callback.Run(USB_TRANSFER_LENGTH_SHORT, NULL, 0); | 283 "transfer length is too small"; |
| 284 return; | |
| 285 } | |
| 286 | 284 |
| 287 struct libusb_transfer* const transfer = libusb_alloc_transfer(packets); | 285 struct libusb_transfer* const transfer = libusb_alloc_transfer(packets); |
| 288 const uint8 new_endpoint = ConvertTransferDirection(direction) | endpoint; | 286 const uint8 new_endpoint = ConvertTransferDirection(direction) | endpoint; |
| 289 libusb_fill_iso_transfer(transfer, handle_, new_endpoint, | 287 libusb_fill_iso_transfer(transfer, handle_, new_endpoint, |
| 290 reinterpret_cast<uint8*>(buffer->data()), length, packets, | 288 reinterpret_cast<uint8*>(buffer->data()), length, packets, |
| 291 reinterpret_cast<libusb_transfer_cb_fn>(&HandleTransferCompletion), this, | 289 reinterpret_cast<libusb_transfer_cb_fn>(&HandleTransferCompletion), this, |
| 292 timeout); | 290 timeout); |
| 293 libusb_set_iso_packet_lengths(transfer, packet_length); | 291 libusb_set_iso_packet_lengths(transfer, packet_length); |
| 294 | 292 |
| 295 SubmitTransfer(transfer, USB_TRANSFER_ISOCHRONOUS, buffer, length, callback); | 293 SubmitTransfer(transfer, USB_TRANSFER_ISOCHRONOUS, buffer, length, callback); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 309 transfer.buffer = buffer; | 307 transfer.buffer = buffer; |
| 310 transfer.length = length; | 308 transfer.length = length; |
| 311 transfer.callback = callback; | 309 transfer.callback = callback; |
| 312 | 310 |
| 313 { | 311 { |
| 314 base::AutoLock lock(lock_); | 312 base::AutoLock lock(lock_); |
| 315 transfers_[handle] = transfer; | 313 transfers_[handle] = transfer; |
| 316 libusb_submit_transfer(handle); | 314 libusb_submit_transfer(handle); |
| 317 } | 315 } |
| 318 } | 316 } |
| OLD | NEW |