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

Side by Side Diff: device/devices_app/usb/device_impl.cc

Issue 1369643002: Add configuration and interface permission checks to DeviceImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add new method ot Android USB mocks. Created 5 years, 2 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/devices_app/usb/device_impl.h" 5 #include "device/devices_app/usb/device_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "device/devices_app/usb/type_converters.h" 10 #include "device/devices_app/usb/type_converters.h"
(...skipping 13 matching lines...) Expand all
24 } 24 }
25 25
26 // Generic wrapper to convert a Mojo callback to something we can rebind and 26 // Generic wrapper to convert a Mojo callback to something we can rebind and
27 // pass around. This is only usable for callbacks with no move-only arguments. 27 // pass around. This is only usable for callbacks with no move-only arguments.
28 template <typename... Args> 28 template <typename... Args>
29 base::Callback<void(Args...)> WrapMojoCallback( 29 base::Callback<void(Args...)> WrapMojoCallback(
30 const mojo::Callback<void(Args...)>& callback) { 30 const mojo::Callback<void(Args...)>& callback) {
31 return base::Bind(&CallMojoCallback<Args...>, callback); 31 return base::Bind(&CallMojoCallback<Args...>, callback);
32 } 32 }
33 33
34 void OnPermissionCheckComplete(
35 const base::Callback<void(bool)>& callback,
36 const base::Callback<void(const base::Callback<void(bool)>&)>& action,
37 bool allowed) {
38 if (allowed)
39 action.Run(callback);
40 else
41 callback.Run(false);
42 }
43
34 scoped_refptr<net::IOBuffer> CreateTransferBuffer(size_t size) { 44 scoped_refptr<net::IOBuffer> CreateTransferBuffer(size_t size) {
35 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer( 45 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(
36 std::max(static_cast<size_t>(1u), static_cast<size_t>(size))); 46 std::max(static_cast<size_t>(1u), static_cast<size_t>(size)));
37 return buffer; 47 return buffer;
38 } 48 }
39 49
40 } // namespace 50 void OnTransferIn(const DeviceImpl::MojoTransferInCallback& callback,
41 51 UsbTransferStatus status,
42 DeviceImpl::DeviceImpl(scoped_refptr<UsbDevice> device, 52 scoped_refptr<net::IOBuffer> buffer,
43 mojo::InterfaceRequest<Device> request) 53 size_t buffer_size) {
44 : binding_(this, request.Pass()), device_(device), weak_factory_(this) {}
45
46 DeviceImpl::~DeviceImpl() {
47 CloseHandle();
48 }
49
50 void DeviceImpl::CloseHandle() {
51 if (device_handle_)
52 device_handle_->Close();
53 device_handle_ = nullptr;
54 }
55
56 void DeviceImpl::OnOpen(const OpenCallback& callback,
57 scoped_refptr<UsbDeviceHandle> handle) {
58 device_handle_ = handle;
59 callback.Run(handle ? OPEN_DEVICE_ERROR_OK : OPEN_DEVICE_ERROR_ACCESS_DENIED);
60 }
61
62 void DeviceImpl::OnTransferIn(const MojoTransferInCallback& callback,
63 UsbTransferStatus status,
64 scoped_refptr<net::IOBuffer> buffer,
65 size_t buffer_size) {
66 mojo::Array<uint8_t> data; 54 mojo::Array<uint8_t> data;
67 if (buffer) { 55 if (buffer) {
68 // TODO(rockot/reillyg): We should change UsbDeviceHandle to use a 56 // TODO(rockot/reillyg): We should change UsbDeviceHandle to use a
69 // std::vector<uint8_t> instead of net::IOBuffer. Then we could move 57 // std::vector<uint8_t> instead of net::IOBuffer. Then we could move
70 // instead of copy. 58 // instead of copy.
71 std::vector<uint8_t> bytes(buffer_size); 59 std::vector<uint8_t> bytes(buffer_size);
72 std::copy(buffer->data(), buffer->data() + buffer_size, bytes.begin()); 60 std::copy(buffer->data(), buffer->data() + buffer_size, bytes.begin());
73 data.Swap(&bytes); 61 data.Swap(&bytes);
74 } 62 }
75 callback.Run(mojo::ConvertTo<TransferStatus>(status), data.Pass()); 63 callback.Run(mojo::ConvertTo<TransferStatus>(status), data.Pass());
76 } 64 }
77 65
78 void DeviceImpl::OnTransferOut(const MojoTransferOutCallback& callback, 66 void OnControlTransferInPermissionCheckComplete(
79 UsbTransferStatus status, 67 scoped_refptr<UsbDeviceHandle> device_handle,
80 scoped_refptr<net::IOBuffer> buffer, 68 ControlTransferParamsPtr params,
81 size_t buffer_size) { 69 int length,
70 int timeout,
71 const Device::ControlTransferInCallback& callback,
72 bool allowed) {
73 if (allowed) {
74 scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(length);
75 device_handle->ControlTransfer(
76 USB_DIRECTION_INBOUND,
77 mojo::ConvertTo<UsbDeviceHandle::TransferRequestType>(params->type),
78 mojo::ConvertTo<UsbDeviceHandle::TransferRecipient>(params->recipient),
79 params->request, params->value, params->index, buffer, length, timeout,
80 base::Bind(&OnTransferIn, callback));
81 } else {
82 mojo::Array<uint8_t> data;
83 callback.Run(TRANSFER_STATUS_PERMISSION_DENIED, data.Pass());
84 }
85 }
86
87 void OnTransferOut(const DeviceImpl::MojoTransferOutCallback& callback,
88 UsbTransferStatus status,
89 scoped_refptr<net::IOBuffer> buffer,
90 size_t buffer_size) {
82 callback.Run(mojo::ConvertTo<TransferStatus>(status)); 91 callback.Run(mojo::ConvertTo<TransferStatus>(status));
83 } 92 }
84 93
85 void DeviceImpl::OnIsochronousTransferIn( 94 void OnControlTransferOutPermissionCheckComplete(
86 const IsochronousTransferInCallback& callback, 95 scoped_refptr<UsbDeviceHandle> device_handle,
96 ControlTransferParamsPtr params,
97 mojo::Array<uint8_t> data,
98 int timeout,
99 const Device::ControlTransferOutCallback& callback,
100 bool allowed) {
101 if (allowed) {
102 scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(data.size());
103 const std::vector<uint8_t>& storage = data.storage();
104 std::copy(storage.begin(), storage.end(), buffer->data());
105 device_handle->ControlTransfer(
106 USB_DIRECTION_OUTBOUND,
107 mojo::ConvertTo<UsbDeviceHandle::TransferRequestType>(params->type),
108 mojo::ConvertTo<UsbDeviceHandle::TransferRecipient>(params->recipient),
109 params->request, params->value, params->index, buffer, data.size(),
110 timeout, base::Bind(&OnTransferOut, callback));
111 } else {
112 callback.Run(TRANSFER_STATUS_PERMISSION_DENIED);
113 }
114 }
115
116 void OnIsochronousTransferIn(
117 const Device::IsochronousTransferInCallback& callback,
87 uint32_t packet_size, 118 uint32_t packet_size,
88 UsbTransferStatus status, 119 UsbTransferStatus status,
89 scoped_refptr<net::IOBuffer> buffer, 120 scoped_refptr<net::IOBuffer> buffer,
90 size_t buffer_size) { 121 size_t buffer_size) {
91 size_t num_packets = buffer_size / packet_size; 122 size_t num_packets = buffer_size / packet_size;
92 mojo::Array<mojo::Array<uint8_t>> packets(num_packets); 123 mojo::Array<mojo::Array<uint8_t>> packets(num_packets);
93 if (buffer) { 124 if (buffer) {
94 for (size_t i = 0; i < num_packets; ++i) { 125 for (size_t i = 0; i < num_packets; ++i) {
95 size_t packet_index = i * packet_size; 126 size_t packet_index = i * packet_size;
96 std::vector<uint8_t> bytes(packet_size); 127 std::vector<uint8_t> bytes(packet_size);
97 std::copy(buffer->data() + packet_index, 128 std::copy(buffer->data() + packet_index,
98 buffer->data() + packet_index + packet_size, bytes.begin()); 129 buffer->data() + packet_index + packet_size, bytes.begin());
99 packets[i].Swap(&bytes); 130 packets[i].Swap(&bytes);
100 } 131 }
101 } 132 }
102 callback.Run(mojo::ConvertTo<TransferStatus>(status), packets.Pass()); 133 callback.Run(mojo::ConvertTo<TransferStatus>(status), packets.Pass());
103 } 134 }
104 135
105 void DeviceImpl::OnIsochronousTransferOut( 136 void OnIsochronousTransferOut(
106 const MojoTransferOutCallback& callback, 137 const Device::IsochronousTransferOutCallback& callback,
107 UsbTransferStatus status, 138 UsbTransferStatus status,
108 scoped_refptr<net::IOBuffer> buffer, 139 scoped_refptr<net::IOBuffer> buffer,
109 size_t buffer_size) { 140 size_t buffer_size) {
110 callback.Run(mojo::ConvertTo<TransferStatus>(status)); 141 callback.Run(mojo::ConvertTo<TransferStatus>(status));
111 } 142 }
112 143
144 } // namespace
145
146 DeviceImpl::DeviceImpl(scoped_refptr<UsbDevice> device,
147 PermissionProviderPtr permission_provider,
148 mojo::InterfaceRequest<Device> request)
149 : binding_(this, request.Pass()),
150 device_(device),
151 permission_provider_(permission_provider.Pass()),
152 weak_factory_(this) {
153 // This object owns itself and will be destroyed if either the message pipe
154 // it is bound to is closed or the PermissionProvider it depends on is
155 // unavailable.
156 binding_.set_connection_error_handler([this]() { delete this; });
157 permission_provider_.set_connection_error_handler([this]() { delete this; });
158 }
159
160 DeviceImpl::~DeviceImpl() {
161 CloseHandle();
162 }
163
164 void DeviceImpl::CloseHandle() {
165 if (device_handle_)
166 device_handle_->Close();
167 device_handle_ = nullptr;
168 }
169
170 void DeviceImpl::HasControlTransferPermission(
171 ControlTransferRecipient recipient,
172 uint16_t index,
173 const base::Callback<void(bool)>& callback) {
174 DCHECK(device_handle_);
175 const UsbConfigDescriptor* config = device_->GetActiveConfiguration();
176
177 if (recipient == CONTROL_TRANSFER_RECIPIENT_INTERFACE ||
178 recipient == CONTROL_TRANSFER_RECIPIENT_ENDPOINT) {
179 if (!config) {
180 callback.Run(false);
181 return;
182 }
183
184 uint8_t interface_number = index & 0xff;
185 if (recipient == CONTROL_TRANSFER_RECIPIENT_ENDPOINT) {
186 if (!device_handle_->FindInterfaceByEndpoint(index & 0xff,
187 &interface_number)) {
188 callback.Run(false);
189 return;
190 }
191 }
192
193 permission_provider_->HasInterfacePermission(
194 interface_number, config->configuration_value,
195 DeviceInfo::From(*device_), callback);
196 } else if (config) {
197 permission_provider_->HasConfigurationPermission(
198 config->configuration_value, DeviceInfo::From(*device_), callback);
199 } else {
200 // Client must already have device permission to have gotten this far.
201 callback.Run(true);
202 }
203 }
204
205 void DeviceImpl::OnOpen(const OpenCallback& callback,
206 scoped_refptr<UsbDeviceHandle> handle) {
207 device_handle_ = handle;
208 callback.Run(handle ? OPEN_DEVICE_ERROR_OK : OPEN_DEVICE_ERROR_ACCESS_DENIED);
209 }
210
113 void DeviceImpl::GetDeviceInfo(const GetDeviceInfoCallback& callback) { 211 void DeviceImpl::GetDeviceInfo(const GetDeviceInfoCallback& callback) {
114 callback.Run(DeviceInfo::From(*device_)); 212 callback.Run(DeviceInfo::From(*device_));
115 } 213 }
116 214
117 void DeviceImpl::GetConfiguration(const GetConfigurationCallback& callback) { 215 void DeviceImpl::GetConfiguration(const GetConfigurationCallback& callback) {
118 const UsbConfigDescriptor* config = device_->GetActiveConfiguration(); 216 const UsbConfigDescriptor* config = device_->GetActiveConfiguration();
119 callback.Run(config ? config->configuration_value : 0); 217 callback.Run(config ? config->configuration_value : 0);
120 } 218 }
121 219
122 void DeviceImpl::Open(const OpenCallback& callback) { 220 void DeviceImpl::Open(const OpenCallback& callback) {
123 device_->Open( 221 device_->Open(
124 base::Bind(&DeviceImpl::OnOpen, weak_factory_.GetWeakPtr(), callback)); 222 base::Bind(&DeviceImpl::OnOpen, weak_factory_.GetWeakPtr(), callback));
125 } 223 }
126 224
127 void DeviceImpl::Close(const CloseCallback& callback) { 225 void DeviceImpl::Close(const CloseCallback& callback) {
128 CloseHandle(); 226 CloseHandle();
129 callback.Run(); 227 callback.Run();
130 } 228 }
131 229
132 void DeviceImpl::SetConfiguration(uint8_t value, 230 void DeviceImpl::SetConfiguration(uint8_t value,
133 const SetConfigurationCallback& callback) { 231 const SetConfigurationCallback& callback) {
134 if (!device_handle_) { 232 if (!device_handle_) {
135 callback.Run(false); 233 callback.Run(false);
136 return; 234 return;
137 } 235 }
138 236
139 device_handle_->SetConfiguration(value, WrapMojoCallback(callback)); 237 auto set_configuration =
238 base::Bind(&UsbDeviceHandle::SetConfiguration, device_handle_, value);
239 permission_provider_->HasConfigurationPermission(
240 value, DeviceInfo::From(*device_),
241 base::Bind(&OnPermissionCheckComplete, WrapMojoCallback(callback),
242 set_configuration));
140 } 243 }
141 244
142 void DeviceImpl::ClaimInterface(uint8_t interface_number, 245 void DeviceImpl::ClaimInterface(uint8_t interface_number,
143 const ClaimInterfaceCallback& callback) { 246 const ClaimInterfaceCallback& callback) {
144 if (!device_handle_) { 247 if (!device_handle_) {
145 callback.Run(false); 248 callback.Run(false);
146 return; 249 return;
147 } 250 }
148 251
149 device_handle_->ClaimInterface(interface_number, WrapMojoCallback(callback)); 252 const UsbConfigDescriptor* config = device_->GetActiveConfiguration();
253 if (!config) {
254 callback.Run(false);
255 return;
256 }
257
258 auto claim_interface = base::Bind(&UsbDeviceHandle::ClaimInterface,
259 device_handle_, interface_number);
260 permission_provider_->HasInterfacePermission(
261 interface_number, config->configuration_value, DeviceInfo::From(*device_),
262 base::Bind(&OnPermissionCheckComplete, WrapMojoCallback(callback),
263 claim_interface));
150 } 264 }
151 265
152 void DeviceImpl::ReleaseInterface(uint8_t interface_number, 266 void DeviceImpl::ReleaseInterface(uint8_t interface_number,
153 const ReleaseInterfaceCallback& callback) { 267 const ReleaseInterfaceCallback& callback) {
154 if (!device_handle_) { 268 if (!device_handle_) {
155 callback.Run(false); 269 callback.Run(false);
156 return; 270 return;
157 } 271 }
158 272
159 callback.Run(device_handle_->ReleaseInterface(interface_number)); 273 callback.Run(device_handle_->ReleaseInterface(interface_number));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 307
194 void DeviceImpl::ControlTransferIn(ControlTransferParamsPtr params, 308 void DeviceImpl::ControlTransferIn(ControlTransferParamsPtr params,
195 uint32_t length, 309 uint32_t length,
196 uint32_t timeout, 310 uint32_t timeout,
197 const ControlTransferInCallback& callback) { 311 const ControlTransferInCallback& callback) {
198 if (!device_handle_) { 312 if (!device_handle_) {
199 callback.Run(TRANSFER_STATUS_ERROR, mojo::Array<uint8_t>()); 313 callback.Run(TRANSFER_STATUS_ERROR, mojo::Array<uint8_t>());
200 return; 314 return;
201 } 315 }
202 316
203 scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(length); 317 ControlTransferRecipient recipient = params->recipient;
204 device_handle_->ControlTransfer( 318 uint16_t index = params->index;
205 USB_DIRECTION_INBOUND, 319 HasControlTransferPermission(
206 mojo::ConvertTo<UsbDeviceHandle::TransferRequestType>(params->type), 320 recipient, index,
207 mojo::ConvertTo<UsbDeviceHandle::TransferRecipient>(params->recipient), 321 base::Bind(&OnControlTransferInPermissionCheckComplete, device_handle_,
208 params->request, params->value, params->index, buffer, length, timeout, 322 base::Passed(&params), length, timeout, callback));
209 base::Bind(&DeviceImpl::OnTransferIn, weak_factory_.GetWeakPtr(),
210 callback));
211 } 323 }
212 324
213 void DeviceImpl::ControlTransferOut( 325 void DeviceImpl::ControlTransferOut(
214 ControlTransferParamsPtr params, 326 ControlTransferParamsPtr params,
215 mojo::Array<uint8_t> data, 327 mojo::Array<uint8_t> data,
216 uint32_t timeout, 328 uint32_t timeout,
217 const ControlTransferOutCallback& callback) { 329 const ControlTransferOutCallback& callback) {
218 if (!device_handle_) { 330 if (!device_handle_) {
219 callback.Run(TRANSFER_STATUS_ERROR); 331 callback.Run(TRANSFER_STATUS_ERROR);
220 return; 332 return;
221 } 333 }
222 334
223 scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(data.size()); 335 ControlTransferRecipient recipient = params->recipient;
224 const std::vector<uint8_t>& storage = data.storage(); 336 uint16_t index = params->index;
225 std::copy(storage.begin(), storage.end(), buffer->data()); 337 HasControlTransferPermission(
226 device_handle_->ControlTransfer( 338 recipient, index, base::Bind(&OnControlTransferOutPermissionCheckComplete,
227 USB_DIRECTION_OUTBOUND, 339 device_handle_, base::Passed(&params),
228 mojo::ConvertTo<UsbDeviceHandle::TransferRequestType>(params->type), 340 base::Passed(&data), timeout, callback));
229 mojo::ConvertTo<UsbDeviceHandle::TransferRecipient>(params->recipient),
230 params->request, params->value, params->index, buffer, data.size(),
231 timeout, base::Bind(&DeviceImpl::OnTransferOut,
232 weak_factory_.GetWeakPtr(), callback));
233 } 341 }
234 342
235 void DeviceImpl::GenericTransferIn(uint8_t endpoint_number, 343 void DeviceImpl::GenericTransferIn(uint8_t endpoint_number,
236 uint32_t length, 344 uint32_t length,
237 uint32_t timeout, 345 uint32_t timeout,
238 const GenericTransferInCallback& callback) { 346 const GenericTransferInCallback& callback) {
239 if (!device_handle_) { 347 if (!device_handle_) {
240 callback.Run(TRANSFER_STATUS_ERROR, mojo::Array<uint8_t>()); 348 callback.Run(TRANSFER_STATUS_ERROR, mojo::Array<uint8_t>());
241 return; 349 return;
242 } 350 }
243 351
244 uint8_t endpoint_address = endpoint_number | 0x80; 352 uint8_t endpoint_address = endpoint_number | 0x80;
245 scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(length); 353 scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(length);
246 device_handle_->GenericTransfer( 354 device_handle_->GenericTransfer(USB_DIRECTION_INBOUND, endpoint_address,
247 USB_DIRECTION_INBOUND, endpoint_address, buffer, length, timeout, 355 buffer, length, timeout,
248 base::Bind(&DeviceImpl::OnTransferIn, weak_factory_.GetWeakPtr(), 356 base::Bind(&OnTransferIn, callback));
249 callback));
250 } 357 }
251 358
252 void DeviceImpl::GenericTransferOut( 359 void DeviceImpl::GenericTransferOut(
253 uint8_t endpoint_number, 360 uint8_t endpoint_number,
254 mojo::Array<uint8_t> data, 361 mojo::Array<uint8_t> data,
255 uint32_t timeout, 362 uint32_t timeout,
256 const GenericTransferOutCallback& callback) { 363 const GenericTransferOutCallback& callback) {
257 if (!device_handle_) { 364 if (!device_handle_) {
258 callback.Run(TRANSFER_STATUS_ERROR); 365 callback.Run(TRANSFER_STATUS_ERROR);
259 return; 366 return;
260 } 367 }
261 368
262 uint8_t endpoint_address = endpoint_number; 369 uint8_t endpoint_address = endpoint_number;
263 scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(data.size()); 370 scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(data.size());
264 const std::vector<uint8_t>& storage = data.storage(); 371 const std::vector<uint8_t>& storage = data.storage();
265 std::copy(storage.begin(), storage.end(), buffer->data()); 372 std::copy(storage.begin(), storage.end(), buffer->data());
266 device_handle_->GenericTransfer( 373 device_handle_->GenericTransfer(USB_DIRECTION_OUTBOUND, endpoint_address,
267 USB_DIRECTION_OUTBOUND, endpoint_address, buffer, data.size(), timeout, 374 buffer, data.size(), timeout,
268 base::Bind(&DeviceImpl::OnTransferOut, weak_factory_.GetWeakPtr(), 375 base::Bind(&OnTransferOut, callback));
269 callback));
270 } 376 }
271 377
272 void DeviceImpl::IsochronousTransferIn( 378 void DeviceImpl::IsochronousTransferIn(
273 uint8_t endpoint_number, 379 uint8_t endpoint_number,
274 uint32_t num_packets, 380 uint32_t num_packets,
275 uint32_t packet_length, 381 uint32_t packet_length,
276 uint32_t timeout, 382 uint32_t timeout,
277 const IsochronousTransferInCallback& callback) { 383 const IsochronousTransferInCallback& callback) {
278 if (!device_handle_) { 384 if (!device_handle_) {
279 callback.Run(TRANSFER_STATUS_ERROR, mojo::Array<mojo::Array<uint8_t>>()); 385 callback.Run(TRANSFER_STATUS_ERROR, mojo::Array<mojo::Array<uint8_t>>());
280 return; 386 return;
281 } 387 }
282 388
283 uint8_t endpoint_address = endpoint_number | 0x80; 389 uint8_t endpoint_address = endpoint_number | 0x80;
284 size_t transfer_size = static_cast<size_t>(num_packets) * packet_length; 390 size_t transfer_size = static_cast<size_t>(num_packets) * packet_length;
285 scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(transfer_size); 391 scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(transfer_size);
286 device_handle_->IsochronousTransfer( 392 device_handle_->IsochronousTransfer(
287 USB_DIRECTION_INBOUND, endpoint_address, buffer, transfer_size, 393 USB_DIRECTION_INBOUND, endpoint_address, buffer, transfer_size,
288 num_packets, packet_length, timeout, 394 num_packets, packet_length, timeout,
289 base::Bind(&DeviceImpl::OnIsochronousTransferIn, 395 base::Bind(&OnIsochronousTransferIn, callback, packet_length));
290 weak_factory_.GetWeakPtr(), callback, packet_length));
291 } 396 }
292 397
293 void DeviceImpl::IsochronousTransferOut( 398 void DeviceImpl::IsochronousTransferOut(
294 uint8_t endpoint_number, 399 uint8_t endpoint_number,
295 mojo::Array<mojo::Array<uint8_t>> packets, 400 mojo::Array<mojo::Array<uint8_t>> packets,
296 uint32_t timeout, 401 uint32_t timeout,
297 const IsochronousTransferOutCallback& callback) { 402 const IsochronousTransferOutCallback& callback) {
298 if (!device_handle_) { 403 if (!device_handle_) {
299 callback.Run(TRANSFER_STATUS_ERROR); 404 callback.Run(TRANSFER_STATUS_ERROR);
300 return; 405 return;
(...skipping 10 matching lines...) Expand all
311 memset(buffer->data(), 0, transfer_size); 416 memset(buffer->data(), 0, transfer_size);
312 for (size_t i = 0; i < packets.size(); ++i) { 417 for (size_t i = 0; i < packets.size(); ++i) {
313 uint8_t* packet = 418 uint8_t* packet =
314 reinterpret_cast<uint8_t*>(&buffer->data()[i * packet_size]); 419 reinterpret_cast<uint8_t*>(&buffer->data()[i * packet_size]);
315 DCHECK_LE(packets[i].size(), static_cast<size_t>(packet_size)); 420 DCHECK_LE(packets[i].size(), static_cast<size_t>(packet_size));
316 memcpy(packet, packets[i].storage().data(), packets[i].size()); 421 memcpy(packet, packets[i].storage().data(), packets[i].size());
317 } 422 }
318 device_handle_->IsochronousTransfer( 423 device_handle_->IsochronousTransfer(
319 USB_DIRECTION_OUTBOUND, endpoint_address, buffer, transfer_size, 424 USB_DIRECTION_OUTBOUND, endpoint_address, buffer, transfer_size,
320 static_cast<uint32_t>(packets.size()), packet_size, timeout, 425 static_cast<uint32_t>(packets.size()), packet_size, timeout,
321 base::Bind(&DeviceImpl::OnIsochronousTransferOut, 426 base::Bind(&OnIsochronousTransferOut, callback));
322 weak_factory_.GetWeakPtr(), callback));
323 } 427 }
324 428
325 } // namespace usb 429 } // namespace usb
326 } // namespace device 430 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698