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

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

Issue 1544323002: Convert Pass()→std::move() in //device (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 | « device/devices_app/devices_app.cc ('k') | device/devices_app/usb/device_impl_unittest.cc » ('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 "device/devices_app/usb/device_impl.h" 5 #include "device/devices_app/usb/device_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/stl_util.h" 12 #include "base/stl_util.h"
12 #include "device/devices_app/usb/type_converters.h" 13 #include "device/devices_app/usb/type_converters.h"
13 #include "device/usb/usb_descriptors.h" 14 #include "device/usb/usb_descriptors.h"
14 #include "device/usb/usb_device.h" 15 #include "device/usb/usb_device.h"
15 #include "net/base/io_buffer.h" 16 #include "net/base/io_buffer.h"
16 17
17 namespace device { 18 namespace device {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 size_t buffer_size) { 68 size_t buffer_size) {
68 mojo::Array<uint8_t> data; 69 mojo::Array<uint8_t> data;
69 if (buffer) { 70 if (buffer) {
70 // TODO(rockot/reillyg): We should change UsbDeviceHandle to use a 71 // TODO(rockot/reillyg): We should change UsbDeviceHandle to use a
71 // std::vector<uint8_t> instead of net::IOBuffer. Then we could move 72 // std::vector<uint8_t> instead of net::IOBuffer. Then we could move
72 // instead of copy. 73 // instead of copy.
73 std::vector<uint8_t> bytes(buffer_size); 74 std::vector<uint8_t> bytes(buffer_size);
74 std::copy(buffer->data(), buffer->data() + buffer_size, bytes.begin()); 75 std::copy(buffer->data(), buffer->data() + buffer_size, bytes.begin());
75 data.Swap(&bytes); 76 data.Swap(&bytes);
76 } 77 }
77 callback->Run(mojo::ConvertTo<TransferStatus>(status), data.Pass()); 78 callback->Run(mojo::ConvertTo<TransferStatus>(status), std::move(data));
78 } 79 }
79 80
80 void OnControlTransferInPermissionCheckComplete( 81 void OnControlTransferInPermissionCheckComplete(
81 scoped_refptr<UsbDeviceHandle> device_handle, 82 scoped_refptr<UsbDeviceHandle> device_handle,
82 ControlTransferParamsPtr params, 83 ControlTransferParamsPtr params,
83 int length, 84 int length,
84 int timeout, 85 int timeout,
85 scoped_ptr<Device::ControlTransferInCallback> callback, 86 scoped_ptr<Device::ControlTransferInCallback> callback,
86 bool allowed) { 87 bool allowed) {
87 if (allowed) { 88 if (allowed) {
88 scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(length); 89 scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(length);
89 device_handle->ControlTransfer( 90 device_handle->ControlTransfer(
90 USB_DIRECTION_INBOUND, 91 USB_DIRECTION_INBOUND,
91 mojo::ConvertTo<UsbDeviceHandle::TransferRequestType>(params->type), 92 mojo::ConvertTo<UsbDeviceHandle::TransferRequestType>(params->type),
92 mojo::ConvertTo<UsbDeviceHandle::TransferRecipient>(params->recipient), 93 mojo::ConvertTo<UsbDeviceHandle::TransferRecipient>(params->recipient),
93 params->request, params->value, params->index, buffer, length, timeout, 94 params->request, params->value, params->index, buffer, length, timeout,
94 base::Bind(&OnTransferIn, base::Passed(&callback))); 95 base::Bind(&OnTransferIn, base::Passed(&callback)));
95 } else { 96 } else {
96 mojo::Array<uint8_t> data; 97 mojo::Array<uint8_t> data;
97 callback->Run(TRANSFER_STATUS_PERMISSION_DENIED, data.Pass()); 98 callback->Run(TRANSFER_STATUS_PERMISSION_DENIED, std::move(data));
98 } 99 }
99 } 100 }
100 101
101 void OnTransferOut(scoped_ptr<MojoTransferOutCallback> callback, 102 void OnTransferOut(scoped_ptr<MojoTransferOutCallback> callback,
102 UsbTransferStatus status, 103 UsbTransferStatus status,
103 scoped_refptr<net::IOBuffer> buffer, 104 scoped_refptr<net::IOBuffer> buffer,
104 size_t buffer_size) { 105 size_t buffer_size) {
105 callback->Run(mojo::ConvertTo<TransferStatus>(status)); 106 callback->Run(mojo::ConvertTo<TransferStatus>(status));
106 } 107 }
107 108
(...skipping 29 matching lines...) Expand all
137 mojo::Array<mojo::Array<uint8_t>> packets(num_packets); 138 mojo::Array<mojo::Array<uint8_t>> packets(num_packets);
138 if (buffer) { 139 if (buffer) {
139 for (size_t i = 0; i < num_packets; ++i) { 140 for (size_t i = 0; i < num_packets; ++i) {
140 size_t packet_index = i * packet_size; 141 size_t packet_index = i * packet_size;
141 std::vector<uint8_t> bytes(packet_size); 142 std::vector<uint8_t> bytes(packet_size);
142 std::copy(buffer->data() + packet_index, 143 std::copy(buffer->data() + packet_index,
143 buffer->data() + packet_index + packet_size, bytes.begin()); 144 buffer->data() + packet_index + packet_size, bytes.begin());
144 packets[i].Swap(&bytes); 145 packets[i].Swap(&bytes);
145 } 146 }
146 } 147 }
147 callback->Run(mojo::ConvertTo<TransferStatus>(status), packets.Pass()); 148 callback->Run(mojo::ConvertTo<TransferStatus>(status), std::move(packets));
148 } 149 }
149 150
150 void OnIsochronousTransferOut( 151 void OnIsochronousTransferOut(
151 scoped_ptr<Device::IsochronousTransferOutCallback> callback, 152 scoped_ptr<Device::IsochronousTransferOutCallback> callback,
152 UsbTransferStatus status, 153 UsbTransferStatus status,
153 scoped_refptr<net::IOBuffer> buffer, 154 scoped_refptr<net::IOBuffer> buffer,
154 size_t buffer_size) { 155 size_t buffer_size) {
155 callback->Run(mojo::ConvertTo<TransferStatus>(status)); 156 callback->Run(mojo::ConvertTo<TransferStatus>(status));
156 } 157 }
157 158
158 } // namespace 159 } // namespace
159 160
160 DeviceImpl::DeviceImpl(scoped_refptr<UsbDevice> device, 161 DeviceImpl::DeviceImpl(scoped_refptr<UsbDevice> device,
161 PermissionProviderPtr permission_provider, 162 PermissionProviderPtr permission_provider,
162 mojo::InterfaceRequest<Device> request) 163 mojo::InterfaceRequest<Device> request)
163 : binding_(this, request.Pass()), 164 : binding_(this, std::move(request)),
164 device_(device), 165 device_(device),
165 permission_provider_(permission_provider.Pass()), 166 permission_provider_(std::move(permission_provider)),
166 weak_factory_(this) { 167 weak_factory_(this) {
167 // This object owns itself and will be destroyed if either the message pipe 168 // This object owns itself and will be destroyed if either the message pipe
168 // it is bound to is closed or the PermissionProvider it depends on is 169 // it is bound to is closed or the PermissionProvider it depends on is
169 // unavailable. 170 // unavailable.
170 binding_.set_connection_error_handler([this]() { delete this; }); 171 binding_.set_connection_error_handler([this]() { delete this; });
171 permission_provider_.set_connection_error_handler([this]() { delete this; }); 172 permission_provider_.set_connection_error_handler([this]() { delete this; });
172 } 173 }
173 174
174 DeviceImpl::~DeviceImpl() { 175 DeviceImpl::~DeviceImpl() {
175 CloseHandle(); 176 CloseHandle();
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 memcpy(packet, packets[i].storage().data(), packets[i].size()); 447 memcpy(packet, packets[i].storage().data(), packets[i].size());
447 } 448 }
448 device_handle_->IsochronousTransfer( 449 device_handle_->IsochronousTransfer(
449 USB_DIRECTION_OUTBOUND, endpoint_address, buffer, transfer_size, 450 USB_DIRECTION_OUTBOUND, endpoint_address, buffer, transfer_size,
450 static_cast<uint32_t>(packets.size()), packet_size, timeout, 451 static_cast<uint32_t>(packets.size()), packet_size, timeout,
451 base::Bind(&OnIsochronousTransferOut, base::Passed(&callback_ptr))); 452 base::Bind(&OnIsochronousTransferOut, base::Passed(&callback_ptr)));
452 } 453 }
453 454
454 } // namespace usb 455 } // namespace usb
455 } // namespace device 456 } // namespace device
OLDNEW
« no previous file with comments | « device/devices_app/devices_app.cc ('k') | device/devices_app/usb/device_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698