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

Side by Side Diff: content/renderer/usb/web_usb_device_impl.cc

Issue 1730403006: Basic layout tests for WebUSB. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Mojo tests that depend on extra module loading. Created 4 years, 9 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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/resources/mojo-helpers.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 scoped_callbacks->onSuccess(adoptWebPtr(info.release())); 171 scoped_callbacks->onSuccess(adoptWebPtr(info.release()));
172 } 172 }
173 173
174 void OnIsochronousTransferIn( 174 void OnIsochronousTransferIn(
175 ScopedWebCallbacks<blink::WebUSBDeviceTransferCallbacks> callbacks, 175 ScopedWebCallbacks<blink::WebUSBDeviceTransferCallbacks> callbacks,
176 mojo::Array<uint8_t> data, 176 mojo::Array<uint8_t> data,
177 mojo::Array<device::usb::IsochronousPacketPtr> packets) { 177 mojo::Array<device::usb::IsochronousPacketPtr> packets) {
178 auto scoped_callbacks = callbacks.PassCallbacks(); 178 auto scoped_callbacks = callbacks.PassCallbacks();
179 scoped_ptr<blink::WebUSBTransferInfo> info(new blink::WebUSBTransferInfo()); 179 scoped_ptr<blink::WebUSBTransferInfo> info(new blink::WebUSBTransferInfo());
180 info->data.assign(data); 180 info->data.assign(data);
181 info->status =
182 blink::WebVector<blink::WebUSBTransferInfo::Status>(packets.size());
183 info->packetLength = blink::WebVector<uint32_t>(packets.size());
184 info->bytesTransferred = blink::WebVector<uint32_t>(packets.size());
181 for (size_t i = 0; i < packets.size(); ++i) { 185 for (size_t i = 0; i < packets.size(); ++i) {
182 switch (packets[i]->status) { 186 switch (packets[i]->status) {
183 case device::usb::TransferStatus::COMPLETED: 187 case device::usb::TransferStatus::COMPLETED:
184 info->status[i] = blink::WebUSBTransferInfo::Status::Ok; 188 info->status[i] = blink::WebUSBTransferInfo::Status::Ok;
185 break; 189 break;
186 case device::usb::TransferStatus::STALLED: 190 case device::usb::TransferStatus::STALLED:
187 info->status[i] = blink::WebUSBTransferInfo::Status::Stall; 191 info->status[i] = blink::WebUSBTransferInfo::Status::Stall;
188 break; 192 break;
189 case device::usb::TransferStatus::BABBLE: 193 case device::usb::TransferStatus::BABBLE:
190 info->status[i] = blink::WebUSBTransferInfo::Status::Babble; 194 info->status[i] = blink::WebUSBTransferInfo::Status::Babble;
191 break; 195 break;
192 default: 196 default:
193 RejectWithTransferError(std::move(scoped_callbacks)); 197 RejectWithTransferError(std::move(scoped_callbacks));
194 return; 198 return;
195 } 199 }
196 info->packetLength[i] = packets[i]->length; 200 info->packetLength[i] = packets[i]->length;
197 info->bytesTransferred[i] = packets[i]->transferred_length; 201 info->bytesTransferred[i] = packets[i]->transferred_length;
198 } 202 }
199 scoped_callbacks->onSuccess(adoptWebPtr(info.release())); 203 scoped_callbacks->onSuccess(adoptWebPtr(info.release()));
200 } 204 }
201 205
202 void OnIsochronousTransferOut( 206 void OnIsochronousTransferOut(
203 ScopedWebCallbacks<blink::WebUSBDeviceTransferCallbacks> callbacks, 207 ScopedWebCallbacks<blink::WebUSBDeviceTransferCallbacks> callbacks,
204 mojo::Array<device::usb::IsochronousPacketPtr> packets) { 208 mojo::Array<device::usb::IsochronousPacketPtr> packets) {
205 auto scoped_callbacks = callbacks.PassCallbacks(); 209 auto scoped_callbacks = callbacks.PassCallbacks();
206 scoped_ptr<blink::WebUSBTransferInfo> info(new blink::WebUSBTransferInfo()); 210 scoped_ptr<blink::WebUSBTransferInfo> info(new blink::WebUSBTransferInfo());
211 info->status =
212 blink::WebVector<blink::WebUSBTransferInfo::Status>(packets.size());
213 info->bytesTransferred = blink::WebVector<uint32_t>(packets.size());
207 for (size_t i = 0; i < packets.size(); ++i) { 214 for (size_t i = 0; i < packets.size(); ++i) {
208 switch (packets[i]->status) { 215 switch (packets[i]->status) {
209 case device::usb::TransferStatus::COMPLETED: 216 case device::usb::TransferStatus::COMPLETED:
210 info->status[i] = blink::WebUSBTransferInfo::Status::Ok; 217 info->status[i] = blink::WebUSBTransferInfo::Status::Ok;
211 break; 218 break;
212 case device::usb::TransferStatus::STALLED: 219 case device::usb::TransferStatus::STALLED:
213 info->status[i] = blink::WebUSBTransferInfo::Status::Stall; 220 info->status[i] = blink::WebUSBTransferInfo::Status::Stall;
214 break; 221 break;
215 default: 222 default:
216 RejectWithTransferError(std::move(scoped_callbacks)); 223 RejectWithTransferError(std::move(scoped_callbacks));
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 } 408 }
402 409
403 void WebUSBDeviceImpl::reset(blink::WebUSBDeviceResetCallbacks* callbacks) { 410 void WebUSBDeviceImpl::reset(blink::WebUSBDeviceResetCallbacks* callbacks) {
404 auto scoped_callbacks = MakeScopedUSBCallbacks(callbacks); 411 auto scoped_callbacks = MakeScopedUSBCallbacks(callbacks);
405 device_->Reset(base::Bind(&HandlePassFailDeviceOperation, 412 device_->Reset(base::Bind(&HandlePassFailDeviceOperation,
406 base::Passed(&scoped_callbacks), 413 base::Passed(&scoped_callbacks),
407 kDeviceResetFailed)); 414 kDeviceResetFailed));
408 } 415 }
409 416
410 } // namespace content 417 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/resources/mojo-helpers.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698