Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(479)

Side by Side Diff: chrome/browser/usb/usb_device.cc

Issue 10823081: Resize control transfer buffers so users don't have to. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing order bug. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/libusb.h" 10 #include "third_party/libusb/libusb.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 libusb_free_transfer(handle); 121 libusb_free_transfer(handle);
122 } 122 }
123 123
124 void UsbDevice::ControlTransfer(const TransferDirection direction, 124 void UsbDevice::ControlTransfer(const TransferDirection direction,
125 const TransferRequestType request_type, const TransferRecipient recipient, 125 const TransferRequestType request_type, const TransferRecipient recipient,
126 const uint8 request, const uint16 value, const uint16 index, 126 const uint8 request, const uint16 value, const uint16 index,
127 net::IOBuffer* buffer, const size_t length, const unsigned int timeout, 127 net::IOBuffer* buffer, const size_t length, const unsigned int timeout,
128 const UsbTransferCallback& callback) { 128 const UsbTransferCallback& callback) {
129 CheckDevice(); 129 CheckDevice();
130 130
131 scoped_refptr<net::IOBuffer> resized_buffer(new net::IOBufferWithSize(
132 LIBUSB_CONTROL_SETUP_SIZE + length));
133 memcpy(resized_buffer->data() + LIBUSB_CONTROL_SETUP_SIZE, buffer->data(),
134 length);
135
131 struct libusb_transfer* const transfer = libusb_alloc_transfer(0); 136 struct libusb_transfer* const transfer = libusb_alloc_transfer(0);
132 const uint8 converted_type = CreateRequestType(direction, request_type, 137 const uint8 converted_type = CreateRequestType(direction, request_type,
133 recipient); 138 recipient);
134 libusb_fill_control_setup(reinterpret_cast<uint8*>(buffer->data()), 139 libusb_fill_control_setup(reinterpret_cast<uint8*>(resized_buffer->data()),
135 converted_type, request, value, index, length); 140 converted_type, request, value, index, length);
136 libusb_fill_control_transfer(transfer, handle_, reinterpret_cast<uint8*>( 141 libusb_fill_control_transfer(transfer, handle_, reinterpret_cast<uint8*>(
137 buffer->data()), reinterpret_cast<libusb_transfer_cb_fn>( 142 resized_buffer->data()), reinterpret_cast<libusb_transfer_cb_fn>(
138 &HandleTransferCompletion), this, timeout); 143 &HandleTransferCompletion), this, timeout);
139 SubmitTransfer(transfer, buffer, callback); 144 SubmitTransfer(transfer, resized_buffer, callback);
140 } 145 }
141 146
142 void UsbDevice::BulkTransfer(const TransferDirection direction, 147 void UsbDevice::BulkTransfer(const TransferDirection direction,
143 const uint8 endpoint, net::IOBuffer* buffer, const size_t length, 148 const uint8 endpoint, net::IOBuffer* buffer, const size_t length,
144 const unsigned int timeout, const UsbTransferCallback& callback) { 149 const unsigned int timeout, const UsbTransferCallback& callback) {
145 CheckDevice(); 150 CheckDevice();
146 151
147 struct libusb_transfer* const transfer = libusb_alloc_transfer(0); 152 struct libusb_transfer* const transfer = libusb_alloc_transfer(0);
148 const uint8 new_endpoint = ConvertTransferDirection(direction) | endpoint; 153 const uint8 new_endpoint = ConvertTransferDirection(direction) | endpoint;
149 libusb_fill_bulk_transfer(transfer, handle_, new_endpoint, 154 libusb_fill_bulk_transfer(transfer, handle_, new_endpoint,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 200
196 Transfer transfer; 201 Transfer transfer;
197 transfer.buffer = buffer; 202 transfer.buffer = buffer;
198 transfer.callback = callback; 203 transfer.callback = callback;
199 204
200 { 205 {
201 base::AutoLock lock(lock_); 206 base::AutoLock lock(lock_);
202 transfers_[handle] = transfer; 207 transfers_[handle] = transfer;
203 } 208 }
204 } 209 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698