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.h" | 5 #include "components/usb_service/usb_device_handle.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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 scoped_refptr<net::IOBuffer> buffer = transfer.buffer; | 227 scoped_refptr<net::IOBuffer> buffer = transfer.buffer; |
228 switch (transfer.transfer_type) { | 228 switch (transfer.transfer_type) { |
229 case USB_TRANSFER_CONTROL: | 229 case USB_TRANSFER_CONTROL: |
230 // If the transfer is a control transfer we do not expose the control | 230 // If the transfer is a control transfer we do not expose the control |
231 // setup header to the caller. This logic strips off the header if | 231 // setup header to the caller. This logic strips off the header if |
232 // present before invoking the callback provided with the transfer. | 232 // present before invoking the callback provided with the transfer. |
233 if (actual_length > 0) { | 233 if (actual_length > 0) { |
234 CHECK(transfer.length >= LIBUSB_CONTROL_SETUP_SIZE) | 234 CHECK(transfer.length >= LIBUSB_CONTROL_SETUP_SIZE) |
235 << "buffer was not correctly set: too small for the control header"; | 235 << "buffer was not correctly set: too small for the control header"; |
236 | 236 |
237 if (transfer.length >= actual_length && | 237 if (transfer.length >= (LIBUSB_CONTROL_SETUP_SIZE + actual_length)) { |
238 actual_length >= LIBUSB_CONTROL_SETUP_SIZE) { | |
239 // If the payload is zero bytes long, pad out the allocated buffer | 238 // If the payload is zero bytes long, pad out the allocated buffer |
240 // size to one byte so that an IOBuffer of that size can be allocated. | 239 // size to one byte so that an IOBuffer of that size can be allocated. |
241 scoped_refptr<net::IOBuffer> resized_buffer = | 240 scoped_refptr<net::IOBuffer> resized_buffer = |
242 new net::IOBuffer(static_cast<int>( | 241 new net::IOBuffer(static_cast<int>( |
243 std::max(actual_length, static_cast<size_t>(1)))); | 242 std::max(actual_length, static_cast<size_t>(1)))); |
244 memcpy(resized_buffer->data(), | 243 memcpy(resized_buffer->data(), |
245 buffer->data() + LIBUSB_CONTROL_SETUP_SIZE, | 244 buffer->data() + LIBUSB_CONTROL_SETUP_SIZE, |
246 actual_length); | 245 actual_length); |
247 buffer = resized_buffer; | 246 buffer = resized_buffer; |
248 } | 247 } |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 // Attempt-release all the interfaces. | 648 // Attempt-release all the interfaces. |
650 // It will be retained until the transfer cancellation is finished. | 649 // It will be retained until the transfer cancellation is finished. |
651 claimed_interfaces_.clear(); | 650 claimed_interfaces_.clear(); |
652 | 651 |
653 // Cannot close device handle here. Need to wait for libusb_cancel_transfer to | 652 // Cannot close device handle here. Need to wait for libusb_cancel_transfer to |
654 // finish. | 653 // finish. |
655 device_ = NULL; | 654 device_ = NULL; |
656 } | 655 } |
657 | 656 |
658 } // namespace usb_service | 657 } // namespace usb_service |
OLD | NEW |