OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <unordered_map> | 9 #include <unordered_map> |
10 #include <utility> | 10 #include <utility> |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "net/base/io_buffer.h" | 30 #include "net/base/io_buffer.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
32 | 32 |
33 using content::BrowserThread; | 33 using content::BrowserThread; |
34 using device::DeviceClient; | 34 using device::DeviceClient; |
35 using device::MockUsbService; | 35 using device::MockUsbService; |
36 using device::UsbConfigDescriptor; | 36 using device::UsbConfigDescriptor; |
37 using device::UsbDevice; | 37 using device::UsbDevice; |
38 using device::UsbDeviceHandle; | 38 using device::UsbDeviceHandle; |
39 using device::UsbEndpointDescriptor; | 39 using device::UsbEndpointDescriptor; |
40 using device::UsbEndpointDirection; | |
41 using device::UsbInterfaceDescriptor; | 40 using device::UsbInterfaceDescriptor; |
42 using device::UsbService; | 41 using device::UsbService; |
43 using device::UsbSynchronizationType; | 42 using device::UsbSynchronizationType; |
| 43 using device::UsbTransferDirection; |
| 44 using device::UsbTransferStatus; |
44 using device::UsbTransferType; | 45 using device::UsbTransferType; |
45 using device::UsbUsageType; | 46 using device::UsbUsageType; |
46 | 47 |
47 namespace { | 48 namespace { |
48 | 49 |
49 struct NoConfigTraits { | 50 struct NoConfigTraits { |
50 static const int kClass = 0xff; | 51 static const int kClass = 0xff; |
51 static const int kSubclass = 0x42; | 52 static const int kSubclass = 0x42; |
52 static const int kProtocol = 0x1; | 53 static const int kProtocol = 0x1; |
53 static const bool kBreaks = false; | 54 static const bool kBreaks = false; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 177 |
177 void ResetDevice(const ResultCallback& callback) override { | 178 void ResetDevice(const ResultCallback& callback) override { |
178 NOTIMPLEMENTED(); | 179 NOTIMPLEMENTED(); |
179 } | 180 } |
180 | 181 |
181 void ClearHalt(uint8_t endpoint, const ResultCallback& callback) override { | 182 void ClearHalt(uint8_t endpoint, const ResultCallback& callback) override { |
182 NOTIMPLEMENTED(); | 183 NOTIMPLEMENTED(); |
183 } | 184 } |
184 | 185 |
185 // Async IO. Can be called on any thread. | 186 // Async IO. Can be called on any thread. |
186 void ControlTransfer(UsbEndpointDirection direction, | 187 void ControlTransfer(UsbTransferDirection direction, |
187 TransferRequestType request_type, | 188 device::UsbControlTransferType request_type, |
188 TransferRecipient recipient, | 189 device::UsbControlTransferRecipient recipient, |
189 uint8_t request, | 190 uint8_t request, |
190 uint16_t value, | 191 uint16_t value, |
191 uint16_t index, | 192 uint16_t index, |
192 scoped_refptr<net::IOBuffer> buffer, | 193 scoped_refptr<net::IOBuffer> buffer, |
193 size_t length, | 194 size_t length, |
194 unsigned int timeout, | 195 unsigned int timeout, |
195 const TransferCallback& callback) override {} | 196 const TransferCallback& callback) override {} |
196 | 197 |
197 void GenericTransfer(UsbEndpointDirection direction, | 198 void GenericTransfer(UsbTransferDirection direction, |
198 uint8_t endpoint, | 199 uint8_t endpoint, |
199 scoped_refptr<net::IOBuffer> buffer, | 200 scoped_refptr<net::IOBuffer> buffer, |
200 size_t length, | 201 size_t length, |
201 unsigned int timeout, | 202 unsigned int timeout, |
202 const TransferCallback& callback) override { | 203 const TransferCallback& callback) override { |
203 if (direction == device::USB_DIRECTION_OUTBOUND) { | 204 if (direction == device::UsbTransferDirection::OUTBOUND) { |
204 if (remaining_body_length_ == 0) { | 205 if (remaining_body_length_ == 0) { |
205 std::vector<uint32_t> header(6); | 206 std::vector<uint32_t> header(6); |
206 memcpy(&header[0], buffer->data(), length); | 207 memcpy(&header[0], buffer->data(), length); |
207 current_message_.reset( | 208 current_message_.reset( |
208 new AdbMessage(header[0], header[1], header[2], std::string())); | 209 new AdbMessage(header[0], header[1], header[2], std::string())); |
209 remaining_body_length_ = header[3]; | 210 remaining_body_length_ = header[3]; |
210 uint32_t magic = header[5]; | 211 uint32_t magic = header[5]; |
211 if ((current_message_->command ^ 0xffffffff) != magic) { | 212 if ((current_message_->command ^ 0xffffffff) != magic) { |
212 DCHECK(false) << "Header checksum error"; | 213 DCHECK(false) << "Header checksum error"; |
213 return; | 214 return; |
214 } | 215 } |
215 } else { | 216 } else { |
216 DCHECK(current_message_.get()); | 217 DCHECK(current_message_.get()); |
217 current_message_->body += std::string(buffer->data(), length); | 218 current_message_->body += std::string(buffer->data(), length); |
218 remaining_body_length_ -= length; | 219 remaining_body_length_ -= length; |
219 } | 220 } |
220 | 221 |
221 if (remaining_body_length_ == 0) { | 222 if (remaining_body_length_ == 0) { |
222 ProcessIncoming(); | 223 ProcessIncoming(); |
223 } | 224 } |
224 | 225 |
225 device::UsbTransferStatus status = | 226 device::UsbTransferStatus status = broken_ |
226 broken_ ? device::USB_TRANSFER_ERROR : device::USB_TRANSFER_COMPLETED; | 227 ? UsbTransferStatus::TRANSFER_ERROR |
| 228 : UsbTransferStatus::COMPLETED; |
227 base::ThreadTaskRunnerHandle::Get()->PostTask( | 229 base::ThreadTaskRunnerHandle::Get()->PostTask( |
228 FROM_HERE, base::Bind(callback, status, nullptr, 0)); | 230 FROM_HERE, base::Bind(callback, status, nullptr, 0)); |
229 ProcessQueries(); | 231 ProcessQueries(); |
230 } else if (direction == device::USB_DIRECTION_INBOUND) { | 232 } else if (direction == device::UsbTransferDirection::INBOUND) { |
231 queries_.push(Query(callback, buffer, length)); | 233 queries_.push(Query(callback, buffer, length)); |
232 ProcessQueries(); | 234 ProcessQueries(); |
233 } | 235 } |
234 } | 236 } |
235 | 237 |
236 const UsbInterfaceDescriptor* FindInterfaceByEndpoint( | 238 const UsbInterfaceDescriptor* FindInterfaceByEndpoint( |
237 uint8_t endpoint_address) { | 239 uint8_t endpoint_address) { |
238 NOTIMPLEMENTED(); | 240 NOTIMPLEMENTED(); |
239 return nullptr; | 241 return nullptr; |
240 } | 242 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 } | 332 } |
331 ProcessQueries(); | 333 ProcessQueries(); |
332 } | 334 } |
333 | 335 |
334 void ProcessQueries() { | 336 void ProcessQueries() { |
335 if (queries_.empty()) | 337 if (queries_.empty()) |
336 return; | 338 return; |
337 Query query = queries_.front(); | 339 Query query = queries_.front(); |
338 if (broken_) { | 340 if (broken_) { |
339 base::ThreadTaskRunnerHandle::Get()->PostTask( | 341 base::ThreadTaskRunnerHandle::Get()->PostTask( |
340 FROM_HERE, | 342 FROM_HERE, base::Bind(query.callback, |
341 base::Bind(query.callback, device::USB_TRANSFER_ERROR, nullptr, 0)); | 343 UsbTransferStatus::TRANSFER_ERROR, nullptr, 0)); |
342 } | 344 } |
343 | 345 |
344 if (query.size > output_buffer_.size()) | 346 if (query.size > output_buffer_.size()) |
345 return; | 347 return; |
346 | 348 |
347 queries_.pop(); | 349 queries_.pop(); |
348 std::copy(output_buffer_.begin(), | 350 std::copy(output_buffer_.begin(), |
349 output_buffer_.begin() + query.size, | 351 output_buffer_.begin() + query.size, |
350 query.buffer->data()); | 352 query.buffer->data()); |
351 output_buffer_.erase(output_buffer_.begin(), | 353 output_buffer_.erase(output_buffer_.begin(), |
352 output_buffer_.begin() + query.size); | 354 output_buffer_.begin() + query.size); |
353 base::ThreadTaskRunnerHandle::Get()->PostTask( | 355 base::ThreadTaskRunnerHandle::Get()->PostTask( |
354 FROM_HERE, base::Bind(query.callback, device::USB_TRANSFER_COMPLETED, | 356 FROM_HERE, base::Bind(query.callback, UsbTransferStatus::COMPLETED, |
355 query.buffer, query.size)); | 357 query.buffer, query.size)); |
356 } | 358 } |
357 | 359 |
358 void IsochronousTransferIn( | 360 void IsochronousTransferIn( |
359 uint8_t endpoint_number, | 361 uint8_t endpoint_number, |
360 const std::vector<uint32_t>& packet_lengths, | 362 const std::vector<uint32_t>& packet_lengths, |
361 unsigned int timeout, | 363 unsigned int timeout, |
362 const IsochronousTransferCallback& callback) override {} | 364 const IsochronousTransferCallback& callback) override {} |
363 | 365 |
364 void IsochronousTransferOut( | 366 void IsochronousTransferOut( |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 EXPECT_EQ(2, listener.invoked_); | 765 EXPECT_EQ(2, listener.invoked_); |
764 EXPECT_EQ(listener.invoked_ - 1, scheduler_invoked_); | 766 EXPECT_EQ(listener.invoked_ - 1, scheduler_invoked_); |
765 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); | 767 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); |
766 } | 768 } |
767 | 769 |
768 IN_PROC_BROWSER_TEST_F(AndroidUsbTraitsTest, TestDeviceCounting) { | 770 IN_PROC_BROWSER_TEST_F(AndroidUsbTraitsTest, TestDeviceCounting) { |
769 MockCountListenerForCheckingTraits listener(adb_bridge_); | 771 MockCountListenerForCheckingTraits listener(adb_bridge_); |
770 adb_bridge_->AddDeviceCountListener(&listener); | 772 adb_bridge_->AddDeviceCountListener(&listener); |
771 runner_->Run(); | 773 runner_->Run(); |
772 } | 774 } |
OLD | NEW |