| 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 "content/renderer/usb/web_usb_device_impl.h" | 5 #include "content/renderer/usb/web_usb_device_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 web_status = blink::WebUSBTransferInfo::Status::Babble; | 121 web_status = blink::WebUSBTransferInfo::Status::Babble; |
| 122 break; | 122 break; |
| 123 default: | 123 default: |
| 124 RejectWithTransferError(std::move(scoped_callbacks)); | 124 RejectWithTransferError(std::move(scoped_callbacks)); |
| 125 return; | 125 return; |
| 126 } | 126 } |
| 127 scoped_ptr<blink::WebUSBTransferInfo> info(new blink::WebUSBTransferInfo()); | 127 scoped_ptr<blink::WebUSBTransferInfo> info(new blink::WebUSBTransferInfo()); |
| 128 info->status.assign( | 128 info->status.assign( |
| 129 std::vector<blink::WebUSBTransferInfo::Status>(1, web_status)); | 129 std::vector<blink::WebUSBTransferInfo::Status>(1, web_status)); |
| 130 info->data.assign(data); | 130 info->data.assign(data); |
| 131 scoped_callbacks->onSuccess(adoptWebPtr(info.release())); | 131 scoped_callbacks->onSuccess(std::move(info)); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void OnTransferOut( | 134 void OnTransferOut( |
| 135 ScopedWebCallbacks<blink::WebUSBDeviceTransferCallbacks> callbacks, | 135 ScopedWebCallbacks<blink::WebUSBDeviceTransferCallbacks> callbacks, |
| 136 size_t bytes_written, | 136 size_t bytes_written, |
| 137 device::usb::TransferStatus status) { | 137 device::usb::TransferStatus status) { |
| 138 auto scoped_callbacks = callbacks.PassCallbacks(); | 138 auto scoped_callbacks = callbacks.PassCallbacks(); |
| 139 blink::WebUSBTransferInfo::Status web_status; | 139 blink::WebUSBTransferInfo::Status web_status; |
| 140 switch (status) { | 140 switch (status) { |
| 141 case device::usb::TransferStatus::COMPLETED: | 141 case device::usb::TransferStatus::COMPLETED: |
| 142 web_status = blink::WebUSBTransferInfo::Status::Ok; | 142 web_status = blink::WebUSBTransferInfo::Status::Ok; |
| 143 break; | 143 break; |
| 144 case device::usb::TransferStatus::STALLED: | 144 case device::usb::TransferStatus::STALLED: |
| 145 web_status = blink::WebUSBTransferInfo::Status::Stall; | 145 web_status = blink::WebUSBTransferInfo::Status::Stall; |
| 146 break; | 146 break; |
| 147 default: | 147 default: |
| 148 RejectWithTransferError(std::move(scoped_callbacks)); | 148 RejectWithTransferError(std::move(scoped_callbacks)); |
| 149 return; | 149 return; |
| 150 } | 150 } |
| 151 // TODO(rockot): Device::ControlTransferOut should expose the number of bytes | 151 // TODO(rockot): Device::ControlTransferOut should expose the number of bytes |
| 152 // actually transferred so we can send it from here. | 152 // actually transferred so we can send it from here. |
| 153 scoped_ptr<blink::WebUSBTransferInfo> info(new blink::WebUSBTransferInfo()); | 153 scoped_ptr<blink::WebUSBTransferInfo> info(new blink::WebUSBTransferInfo()); |
| 154 info->status.assign( | 154 info->status.assign( |
| 155 std::vector<blink::WebUSBTransferInfo::Status>(1, web_status)); | 155 std::vector<blink::WebUSBTransferInfo::Status>(1, web_status)); |
| 156 info->bytesTransferred.assign(std::vector<uint32_t>(1, bytes_written)); | 156 info->bytesTransferred.assign(std::vector<uint32_t>(1, bytes_written)); |
| 157 scoped_callbacks->onSuccess(adoptWebPtr(info.release())); | 157 scoped_callbacks->onSuccess(std::move(info)); |
| 158 } | 158 } |
| 159 | 159 |
| 160 void OnIsochronousTransferIn( | 160 void OnIsochronousTransferIn( |
| 161 ScopedWebCallbacks<blink::WebUSBDeviceTransferCallbacks> callbacks, | 161 ScopedWebCallbacks<blink::WebUSBDeviceTransferCallbacks> callbacks, |
| 162 mojo::Array<uint8_t> data, | 162 mojo::Array<uint8_t> data, |
| 163 mojo::Array<device::usb::IsochronousPacketPtr> packets) { | 163 mojo::Array<device::usb::IsochronousPacketPtr> packets) { |
| 164 auto scoped_callbacks = callbacks.PassCallbacks(); | 164 auto scoped_callbacks = callbacks.PassCallbacks(); |
| 165 scoped_ptr<blink::WebUSBTransferInfo> info(new blink::WebUSBTransferInfo()); | 165 scoped_ptr<blink::WebUSBTransferInfo> info(new blink::WebUSBTransferInfo()); |
| 166 info->data.assign(data); | 166 info->data.assign(data); |
| 167 info->status = | 167 info->status = |
| (...skipping 11 matching lines...) Expand all Loading... |
| 179 case device::usb::TransferStatus::BABBLE: | 179 case device::usb::TransferStatus::BABBLE: |
| 180 info->status[i] = blink::WebUSBTransferInfo::Status::Babble; | 180 info->status[i] = blink::WebUSBTransferInfo::Status::Babble; |
| 181 break; | 181 break; |
| 182 default: | 182 default: |
| 183 RejectWithTransferError(std::move(scoped_callbacks)); | 183 RejectWithTransferError(std::move(scoped_callbacks)); |
| 184 return; | 184 return; |
| 185 } | 185 } |
| 186 info->packetLength[i] = packets[i]->length; | 186 info->packetLength[i] = packets[i]->length; |
| 187 info->bytesTransferred[i] = packets[i]->transferred_length; | 187 info->bytesTransferred[i] = packets[i]->transferred_length; |
| 188 } | 188 } |
| 189 scoped_callbacks->onSuccess(adoptWebPtr(info.release())); | 189 scoped_callbacks->onSuccess(std::move(info)); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void OnIsochronousTransferOut( | 192 void OnIsochronousTransferOut( |
| 193 ScopedWebCallbacks<blink::WebUSBDeviceTransferCallbacks> callbacks, | 193 ScopedWebCallbacks<blink::WebUSBDeviceTransferCallbacks> callbacks, |
| 194 mojo::Array<device::usb::IsochronousPacketPtr> packets) { | 194 mojo::Array<device::usb::IsochronousPacketPtr> packets) { |
| 195 auto scoped_callbacks = callbacks.PassCallbacks(); | 195 auto scoped_callbacks = callbacks.PassCallbacks(); |
| 196 scoped_ptr<blink::WebUSBTransferInfo> info(new blink::WebUSBTransferInfo()); | 196 scoped_ptr<blink::WebUSBTransferInfo> info(new blink::WebUSBTransferInfo()); |
| 197 info->status = | 197 info->status = |
| 198 blink::WebVector<blink::WebUSBTransferInfo::Status>(packets.size()); | 198 blink::WebVector<blink::WebUSBTransferInfo::Status>(packets.size()); |
| 199 info->bytesTransferred = blink::WebVector<uint32_t>(packets.size()); | 199 info->bytesTransferred = blink::WebVector<uint32_t>(packets.size()); |
| 200 for (size_t i = 0; i < packets.size(); ++i) { | 200 for (size_t i = 0; i < packets.size(); ++i) { |
| 201 switch (packets[i]->status) { | 201 switch (packets[i]->status) { |
| 202 case device::usb::TransferStatus::COMPLETED: | 202 case device::usb::TransferStatus::COMPLETED: |
| 203 info->status[i] = blink::WebUSBTransferInfo::Status::Ok; | 203 info->status[i] = blink::WebUSBTransferInfo::Status::Ok; |
| 204 break; | 204 break; |
| 205 case device::usb::TransferStatus::STALLED: | 205 case device::usb::TransferStatus::STALLED: |
| 206 info->status[i] = blink::WebUSBTransferInfo::Status::Stall; | 206 info->status[i] = blink::WebUSBTransferInfo::Status::Stall; |
| 207 break; | 207 break; |
| 208 default: | 208 default: |
| 209 RejectWithTransferError(std::move(scoped_callbacks)); | 209 RejectWithTransferError(std::move(scoped_callbacks)); |
| 210 return; | 210 return; |
| 211 } | 211 } |
| 212 info->bytesTransferred[i] = packets[i]->transferred_length; | 212 info->bytesTransferred[i] = packets[i]->transferred_length; |
| 213 } | 213 } |
| 214 scoped_callbacks->onSuccess(adoptWebPtr(info.release())); | 214 scoped_callbacks->onSuccess(std::move(info)); |
| 215 } | 215 } |
| 216 | 216 |
| 217 } // namespace | 217 } // namespace |
| 218 | 218 |
| 219 WebUSBDeviceImpl::WebUSBDeviceImpl(device::usb::DevicePtr device, | 219 WebUSBDeviceImpl::WebUSBDeviceImpl(device::usb::DevicePtr device, |
| 220 const blink::WebUSBDeviceInfo& device_info) | 220 const blink::WebUSBDeviceInfo& device_info) |
| 221 : device_(std::move(device)), | 221 : device_(std::move(device)), |
| 222 device_info_(device_info), | 222 device_info_(device_info), |
| 223 weak_factory_(this) { | 223 weak_factory_(this) { |
| 224 if (device_) | 224 if (device_) |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 | 408 |
| 409 void WebUSBDeviceImpl::reset(blink::WebUSBDeviceResetCallbacks* callbacks) { | 409 void WebUSBDeviceImpl::reset(blink::WebUSBDeviceResetCallbacks* callbacks) { |
| 410 auto scoped_callbacks = MakeScopedUSBCallbacks(callbacks); | 410 auto scoped_callbacks = MakeScopedUSBCallbacks(callbacks); |
| 411 if (device_) | 411 if (device_) |
| 412 device_->Reset(base::Bind(&HandlePassFailDeviceOperation, | 412 device_->Reset(base::Bind(&HandlePassFailDeviceOperation, |
| 413 base::Passed(&scoped_callbacks), | 413 base::Passed(&scoped_callbacks), |
| 414 kDeviceResetFailed)); | 414 kDeviceResetFailed)); |
| 415 } | 415 } |
| 416 | 416 |
| 417 } // namespace content | 417 } // namespace content |
| OLD | NEW |