| 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 <memory> | 8 #include <memory> |
| 9 #include <numeric> | 9 #include <numeric> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 | 473 |
| 474 DCHECK(length_ >= actual_length) | 474 DCHECK(length_ >= actual_length) |
| 475 << "data too big for our buffer (libusb failure?)"; | 475 << "data too big for our buffer (libusb failure?)"; |
| 476 | 476 |
| 477 switch (transfer_type_) { | 477 switch (transfer_type_) { |
| 478 case USB_TRANSFER_CONTROL: | 478 case USB_TRANSFER_CONTROL: |
| 479 // If the transfer is a control transfer we do not expose the control | 479 // If the transfer is a control transfer we do not expose the control |
| 480 // setup header to the caller. This logic strips off the header if | 480 // setup header to the caller. This logic strips off the header if |
| 481 // present before invoking the callback provided with the transfer. | 481 // present before invoking the callback provided with the transfer. |
| 482 if (actual_length > 0) { | 482 if (actual_length > 0) { |
| 483 CHECK(length_ >= LIBUSB_CONTROL_SETUP_SIZE) | 483 // buffer was not correctly set: too small for the control header |
| 484 << "buffer was not correctly set: too small for the control header"; | 484 CHECK(length_ >= LIBUSB_CONTROL_SETUP_SIZE); |
| 485 | 485 |
| 486 if (length_ >= (LIBUSB_CONTROL_SETUP_SIZE + actual_length)) { | 486 if (length_ >= (LIBUSB_CONTROL_SETUP_SIZE + actual_length)) { |
| 487 // If the payload is zero bytes long, pad out the allocated buffer | 487 // If the payload is zero bytes long, pad out the allocated buffer |
| 488 // size to one byte so that an IOBuffer of that size can be allocated. | 488 // size to one byte so that an IOBuffer of that size can be allocated. |
| 489 scoped_refptr<net::IOBuffer> resized_buffer = new net::IOBuffer( | 489 scoped_refptr<net::IOBuffer> resized_buffer = new net::IOBuffer( |
| 490 std::max(actual_length, static_cast<size_t>(1))); | 490 std::max(actual_length, static_cast<size_t>(1))); |
| 491 memcpy(resized_buffer->data(), | 491 memcpy(resized_buffer->data(), |
| 492 buffer_->data() + LIBUSB_CONTROL_SETUP_SIZE, actual_length); | 492 buffer_->data() + LIBUSB_CONTROL_SETUP_SIZE, actual_length); |
| 493 buffer_ = resized_buffer; | 493 buffer_ = resized_buffer; |
| 494 } | 494 } |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1122 } else { | 1122 } else { |
| 1123 transfer->callback_task_runner()->PostTask(FROM_HERE, callback); | 1123 transfer->callback_task_runner()->PostTask(FROM_HERE, callback); |
| 1124 } | 1124 } |
| 1125 | 1125 |
| 1126 // libusb_free_transfer races with libusb_submit_transfer and only work- | 1126 // libusb_free_transfer races with libusb_submit_transfer and only work- |
| 1127 // around is to make sure to call them on the same thread. | 1127 // around is to make sure to call them on the same thread. |
| 1128 blocking_task_runner_->DeleteSoon(FROM_HERE, transfer); | 1128 blocking_task_runner_->DeleteSoon(FROM_HERE, transfer); |
| 1129 } | 1129 } |
| 1130 | 1130 |
| 1131 } // namespace device | 1131 } // namespace device |
| OLD | NEW |