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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/devtools/device/devtools_android_bridge.h" | 8 #include "chrome/browser/devtools/device/devtools_android_bridge.h" |
9 #include "chrome/browser/devtools/device/usb/android_usb_device.h" | 9 #include "chrome/browser/devtools/device/usb/android_usb_device.h" |
10 #include "chrome/browser/devtools/device/usb/usb_device_provider.h" | 10 #include "chrome/browser/devtools/device/usb/usb_device_provider.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 *product = base::UTF8ToUTF16(kDeviceModel); | 155 *product = base::UTF8ToUTF16(kDeviceModel); |
156 return true; | 156 return true; |
157 } | 157 } |
158 | 158 |
159 virtual bool GetSerial(base::string16* serial) OVERRIDE { | 159 virtual bool GetSerial(base::string16* serial) OVERRIDE { |
160 *serial = base::UTF8ToUTF16(kDeviceSerial); | 160 *serial = base::UTF8ToUTF16(kDeviceSerial); |
161 return true; | 161 return true; |
162 } | 162 } |
163 | 163 |
164 // Async IO. Can be called on any thread. | 164 // Async IO. Can be called on any thread. |
165 virtual void ControlTransfer(const UsbEndpointDirection direction, | 165 virtual void ControlTransfer(UsbEndpointDirection direction, |
166 const TransferRequestType request_type, | 166 TransferRequestType request_type, |
167 const TransferRecipient recipient, | 167 TransferRecipient recipient, |
168 const uint8 request, | 168 uint8 request, |
169 const uint16 value, | 169 uint16 value, |
170 const uint16 index, | 170 uint16 index, |
171 net::IOBuffer* buffer, | 171 net::IOBuffer* buffer, |
172 const size_t length, | 172 size_t length, |
173 const unsigned int timeout, | 173 unsigned int timeout, |
174 const UsbTransferCallback& callback) OVERRIDE {} | 174 const UsbTransferCallback& callback) OVERRIDE {} |
175 | 175 |
176 virtual void BulkTransfer(const UsbEndpointDirection direction, | 176 virtual void BulkTransfer(UsbEndpointDirection direction, |
177 const uint8 endpoint, | 177 uint8 endpoint, |
178 net::IOBuffer* buffer, | 178 net::IOBuffer* buffer, |
179 const size_t length, | 179 size_t length, |
180 const unsigned int timeout, | 180 unsigned int timeout, |
181 const UsbTransferCallback& callback) OVERRIDE { | 181 const UsbTransferCallback& callback) OVERRIDE { |
182 if (direction == device::USB_DIRECTION_OUTBOUND) { | 182 if (direction == device::USB_DIRECTION_OUTBOUND) { |
183 if (remaining_body_length_ == 0) { | 183 if (remaining_body_length_ == 0) { |
184 std::vector<uint32> header(6); | 184 std::vector<uint32> header(6); |
185 memcpy(&header[0], buffer->data(), length); | 185 memcpy(&header[0], buffer->data(), length); |
186 current_message_ = new AdbMessage(header[0], header[1], header[2], ""); | 186 current_message_ = new AdbMessage(header[0], header[1], header[2], ""); |
187 remaining_body_length_ = header[3]; | 187 remaining_body_length_ = header[3]; |
188 uint32 magic = header[5]; | 188 uint32 magic = header[5]; |
189 if ((current_message_->command ^ 0xffffffff) != magic) { | 189 if ((current_message_->command ^ 0xffffffff) != magic) { |
190 DCHECK(false) << "Header checksum error"; | 190 DCHECK(false) << "Header checksum error"; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 output_buffer_.erase(output_buffer_.begin(), | 297 output_buffer_.erase(output_buffer_.begin(), |
298 output_buffer_.begin() + query.size); | 298 output_buffer_.begin() + query.size); |
299 base::MessageLoop::current()->PostTask( | 299 base::MessageLoop::current()->PostTask( |
300 FROM_HERE, | 300 FROM_HERE, |
301 base::Bind(query.callback, | 301 base::Bind(query.callback, |
302 device::USB_TRANSFER_COMPLETED, | 302 device::USB_TRANSFER_COMPLETED, |
303 query.buffer, | 303 query.buffer, |
304 query.size)); | 304 query.size)); |
305 } | 305 } |
306 | 306 |
307 virtual void InterruptTransfer(const UsbEndpointDirection direction, | 307 virtual void InterruptTransfer(UsbEndpointDirection direction, |
308 const uint8 endpoint, | 308 uint8 endpoint, |
309 net::IOBuffer* buffer, | 309 net::IOBuffer* buffer, |
310 const size_t length, | 310 size_t length, |
311 const unsigned int timeout, | 311 unsigned int timeout, |
312 const UsbTransferCallback& callback) OVERRIDE { | 312 const UsbTransferCallback& callback) OVERRIDE { |
313 } | 313 } |
314 | 314 |
315 virtual void IsochronousTransfer( | 315 virtual void IsochronousTransfer( |
316 const UsbEndpointDirection direction, | 316 UsbEndpointDirection direction, |
317 const uint8 endpoint, | 317 uint8 endpoint, |
318 net::IOBuffer* buffer, | 318 net::IOBuffer* buffer, |
319 const size_t length, | 319 size_t length, |
320 const unsigned int packets, | 320 unsigned int packets, |
321 const unsigned int packet_length, | 321 unsigned int packet_length, |
322 const unsigned int timeout, | 322 unsigned int timeout, |
323 const UsbTransferCallback& callback) OVERRIDE {} | 323 const UsbTransferCallback& callback) OVERRIDE {} |
324 | 324 |
325 protected: | 325 protected: |
326 virtual ~MockUsbDeviceHandle() {} | 326 virtual ~MockUsbDeviceHandle() {} |
327 | 327 |
328 struct Query { | 328 struct Query { |
329 UsbTransferCallback callback; | 329 UsbTransferCallback callback; |
330 scoped_refptr<net::IOBuffer> buffer; | 330 scoped_refptr<net::IOBuffer> buffer; |
331 size_t size; | 331 size_t size; |
332 | 332 |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 runner_->Run(); | 762 runner_->Run(); |
763 EXPECT_EQ(2, listener.invoked_); | 763 EXPECT_EQ(2, listener.invoked_); |
764 EXPECT_EQ(listener.invoked_ - 1, scheduler_invoked_); | 764 EXPECT_EQ(listener.invoked_ - 1, scheduler_invoked_); |
765 } | 765 } |
766 | 766 |
767 IN_PROC_BROWSER_TEST_F(AndroidUsbTraitsTest, TestDeviceCounting) { | 767 IN_PROC_BROWSER_TEST_F(AndroidUsbTraitsTest, TestDeviceCounting) { |
768 MockCountListenerForCheckingTraits listener(adb_bridge_); | 768 MockCountListenerForCheckingTraits listener(adb_bridge_); |
769 adb_bridge_->AddDeviceCountListener(&listener); | 769 adb_bridge_->AddDeviceCountListener(&listener); |
770 runner_->Run(); | 770 runner_->Run(); |
771 } | 771 } |
OLD | NEW |