| OLD | NEW |
| 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/usb/mojo/device_impl.h" | 5 #include "device/usb/mojo/device_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 uint32_t timeout, | 327 uint32_t timeout, |
| 328 const ControlTransferInCallback& callback) { | 328 const ControlTransferInCallback& callback) { |
| 329 if (!device_handle_) { | 329 if (!device_handle_) { |
| 330 callback.Run(mojom::UsbTransferStatus::TRANSFER_ERROR, base::nullopt); | 330 callback.Run(mojom::UsbTransferStatus::TRANSFER_ERROR, base::nullopt); |
| 331 return; | 331 return; |
| 332 } | 332 } |
| 333 | 333 |
| 334 if (HasControlTransferPermission(params->recipient, params->index)) { | 334 if (HasControlTransferPermission(params->recipient, params->index)) { |
| 335 scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(length); | 335 scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(length); |
| 336 device_handle_->ControlTransfer( | 336 device_handle_->ControlTransfer( |
| 337 USB_DIRECTION_INBOUND, | 337 UsbTransferDirection::INBOUND, params->type, params->recipient, |
| 338 mojo::ConvertTo<UsbDeviceHandle::TransferRequestType>(params->type), | |
| 339 mojo::ConvertTo<UsbDeviceHandle::TransferRecipient>(params->recipient), | |
| 340 params->request, params->value, params->index, buffer, length, timeout, | 338 params->request, params->value, params->index, buffer, length, timeout, |
| 341 base::Bind(&OnTransferIn, callback)); | 339 base::Bind(&OnTransferIn, callback)); |
| 342 } else { | 340 } else { |
| 343 callback.Run(mojom::UsbTransferStatus::PERMISSION_DENIED, base::nullopt); | 341 callback.Run(mojom::UsbTransferStatus::PERMISSION_DENIED, base::nullopt); |
| 344 } | 342 } |
| 345 } | 343 } |
| 346 | 344 |
| 347 void DeviceImpl::ControlTransferOut( | 345 void DeviceImpl::ControlTransferOut( |
| 348 UsbControlTransferParamsPtr params, | 346 UsbControlTransferParamsPtr params, |
| 349 const std::vector<uint8_t>& data, | 347 const std::vector<uint8_t>& data, |
| 350 uint32_t timeout, | 348 uint32_t timeout, |
| 351 const ControlTransferOutCallback& callback) { | 349 const ControlTransferOutCallback& callback) { |
| 352 if (!device_handle_) { | 350 if (!device_handle_) { |
| 353 callback.Run(mojom::UsbTransferStatus::TRANSFER_ERROR); | 351 callback.Run(mojom::UsbTransferStatus::TRANSFER_ERROR); |
| 354 return; | 352 return; |
| 355 } | 353 } |
| 356 | 354 |
| 357 if (HasControlTransferPermission(params->recipient, params->index)) { | 355 if (HasControlTransferPermission(params->recipient, params->index)) { |
| 358 scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(data.size()); | 356 scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(data.size()); |
| 359 std::copy(data.begin(), data.end(), buffer->data()); | 357 std::copy(data.begin(), data.end(), buffer->data()); |
| 360 device_handle_->ControlTransfer( | 358 device_handle_->ControlTransfer( |
| 361 USB_DIRECTION_OUTBOUND, | 359 UsbTransferDirection::OUTBOUND, params->type, params->recipient, |
| 362 mojo::ConvertTo<UsbDeviceHandle::TransferRequestType>(params->type), | |
| 363 mojo::ConvertTo<UsbDeviceHandle::TransferRecipient>(params->recipient), | |
| 364 params->request, params->value, params->index, buffer, data.size(), | 360 params->request, params->value, params->index, buffer, data.size(), |
| 365 timeout, base::Bind(&OnTransferOut, callback)); | 361 timeout, base::Bind(&OnTransferOut, callback)); |
| 366 } else { | 362 } else { |
| 367 callback.Run(mojom::UsbTransferStatus::PERMISSION_DENIED); | 363 callback.Run(mojom::UsbTransferStatus::PERMISSION_DENIED); |
| 368 } | 364 } |
| 369 } | 365 } |
| 370 | 366 |
| 371 void DeviceImpl::GenericTransferIn(uint8_t endpoint_number, | 367 void DeviceImpl::GenericTransferIn(uint8_t endpoint_number, |
| 372 uint32_t length, | 368 uint32_t length, |
| 373 uint32_t timeout, | 369 uint32_t timeout, |
| 374 const GenericTransferInCallback& callback) { | 370 const GenericTransferInCallback& callback) { |
| 375 if (!device_handle_) { | 371 if (!device_handle_) { |
| 376 callback.Run(mojom::UsbTransferStatus::TRANSFER_ERROR, base::nullopt); | 372 callback.Run(mojom::UsbTransferStatus::TRANSFER_ERROR, base::nullopt); |
| 377 return; | 373 return; |
| 378 } | 374 } |
| 379 | 375 |
| 380 uint8_t endpoint_address = endpoint_number | 0x80; | 376 uint8_t endpoint_address = endpoint_number | 0x80; |
| 381 scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(length); | 377 scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(length); |
| 382 device_handle_->GenericTransfer(USB_DIRECTION_INBOUND, endpoint_address, | 378 device_handle_->GenericTransfer(UsbTransferDirection::INBOUND, |
| 383 buffer, length, timeout, | 379 endpoint_address, buffer, length, timeout, |
| 384 base::Bind(&OnTransferIn, callback)); | 380 base::Bind(&OnTransferIn, callback)); |
| 385 } | 381 } |
| 386 | 382 |
| 387 void DeviceImpl::GenericTransferOut( | 383 void DeviceImpl::GenericTransferOut( |
| 388 uint8_t endpoint_number, | 384 uint8_t endpoint_number, |
| 389 const std::vector<uint8_t>& data, | 385 const std::vector<uint8_t>& data, |
| 390 uint32_t timeout, | 386 uint32_t timeout, |
| 391 const GenericTransferOutCallback& callback) { | 387 const GenericTransferOutCallback& callback) { |
| 392 if (!device_handle_) { | 388 if (!device_handle_) { |
| 393 callback.Run(mojom::UsbTransferStatus::TRANSFER_ERROR); | 389 callback.Run(mojom::UsbTransferStatus::TRANSFER_ERROR); |
| 394 return; | 390 return; |
| 395 } | 391 } |
| 396 | 392 |
| 397 uint8_t endpoint_address = endpoint_number; | 393 uint8_t endpoint_address = endpoint_number; |
| 398 scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(data.size()); | 394 scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(data.size()); |
| 399 std::copy(data.begin(), data.end(), buffer->data()); | 395 std::copy(data.begin(), data.end(), buffer->data()); |
| 400 device_handle_->GenericTransfer(USB_DIRECTION_OUTBOUND, endpoint_address, | 396 device_handle_->GenericTransfer( |
| 401 buffer, data.size(), timeout, | 397 UsbTransferDirection::OUTBOUND, endpoint_address, buffer, data.size(), |
| 402 base::Bind(&OnTransferOut, callback)); | 398 timeout, base::Bind(&OnTransferOut, callback)); |
| 403 } | 399 } |
| 404 | 400 |
| 405 void DeviceImpl::IsochronousTransferIn( | 401 void DeviceImpl::IsochronousTransferIn( |
| 406 uint8_t endpoint_number, | 402 uint8_t endpoint_number, |
| 407 const std::vector<uint32_t>& packet_lengths, | 403 const std::vector<uint32_t>& packet_lengths, |
| 408 uint32_t timeout, | 404 uint32_t timeout, |
| 409 const IsochronousTransferInCallback& callback) { | 405 const IsochronousTransferInCallback& callback) { |
| 410 if (!device_handle_) { | 406 if (!device_handle_) { |
| 411 callback.Run(base::nullopt, | 407 callback.Run(base::nullopt, |
| 412 BuildIsochronousPacketArray( | 408 BuildIsochronousPacketArray( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 440 base::Bind(&OnIsochronousTransferOut, callback)); | 436 base::Bind(&OnIsochronousTransferOut, callback)); |
| 441 } | 437 } |
| 442 | 438 |
| 443 void DeviceImpl::OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) { | 439 void DeviceImpl::OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) { |
| 444 DCHECK_EQ(device_, device); | 440 DCHECK_EQ(device_, device); |
| 445 binding_->Close(); | 441 binding_->Close(); |
| 446 } | 442 } |
| 447 | 443 |
| 448 } // namespace usb | 444 } // namespace usb |
| 449 } // namespace device | 445 } // namespace device |
| OLD | NEW |