| 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 "device/test/usb_test_gadget.h" | 5 #include "device/test/usb_test_gadget.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 static const int kReconnectRetries = 100; // 5 seconds | 51 static const int kReconnectRetries = 100; // 5 seconds |
| 52 static const int kUpdateRetries = 100; // 5 seconds | 52 static const int kUpdateRetries = 100; // 5 seconds |
| 53 | 53 |
| 54 struct UsbTestGadgetConfiguration { | 54 struct UsbTestGadgetConfiguration { |
| 55 UsbTestGadget::Type type; | 55 UsbTestGadget::Type type; |
| 56 const char* http_resource; | 56 const char* http_resource; |
| 57 uint16 product_id; | 57 uint16 product_id; |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 static const struct UsbTestGadgetConfiguration kConfigurations[] = { | 60 static const struct UsbTestGadgetConfiguration kConfigurations[] = { |
| 61 { UsbTestGadget::DEFAULT, "/unconfigure", 0x2000 }, | 61 { UsbTestGadget::DEFAULT, "/unconfigure", 0x58F0 }, |
| 62 { UsbTestGadget::KEYBOARD, "/keyboard/configure", 0x2001 }, | 62 { UsbTestGadget::KEYBOARD, "/keyboard/configure", 0x58F1 }, |
| 63 { UsbTestGadget::MOUSE, "/mouse/configure", 0x2002 }, | 63 { UsbTestGadget::MOUSE, "/mouse/configure", 0x58F2 }, |
| 64 { UsbTestGadget::HID_ECHO, "/hid_echo/configure", 0x2003 }, | 64 { UsbTestGadget::HID_ECHO, "/hid_echo/configure", 0x58F3 }, |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 class UsbTestGadgetImpl : public UsbTestGadget { | 67 class UsbTestGadgetImpl : public UsbTestGadget { |
| 68 public: | 68 public: |
| 69 virtual ~UsbTestGadgetImpl(); | 69 virtual ~UsbTestGadgetImpl(); |
| 70 | 70 |
| 71 virtual bool Unclaim() OVERRIDE; | 71 virtual bool Unclaim() OVERRIDE; |
| 72 virtual bool Disconnect() OVERRIDE; | 72 virtual bool Disconnect() OVERRIDE; |
| 73 virtual bool Reconnect() OVERRIDE; | 73 virtual bool Reconnect() OVERRIDE; |
| 74 virtual bool SetType(Type type) OVERRIDE; | 74 virtual bool SetType(Type type) OVERRIDE; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 return url_fetcher->GetResponseCode(); | 199 return url_fetcher->GetResponseCode(); |
| 200 } | 200 } |
| 201 | 201 |
| 202 bool UsbTestGadgetImpl::FindUnclaimed() { | 202 bool UsbTestGadgetImpl::FindUnclaimed() { |
| 203 std::vector<scoped_refptr<UsbDevice> > devices; | 203 std::vector<scoped_refptr<UsbDevice> > devices; |
| 204 usb_service_->GetDevices(&devices); | 204 usb_service_->GetDevices(&devices); |
| 205 | 205 |
| 206 for (std::vector<scoped_refptr<UsbDevice> >::const_iterator iter = | 206 for (std::vector<scoped_refptr<UsbDevice> >::const_iterator iter = |
| 207 devices.begin(); iter != devices.end(); ++iter) { | 207 devices.begin(); iter != devices.end(); ++iter) { |
| 208 const scoped_refptr<UsbDevice> &device = *iter; | 208 const scoped_refptr<UsbDevice> &device = *iter; |
| 209 if (device->vendor_id() == 0x18D1 && device->product_id() == 0x2000) { | 209 if (device->vendor_id() == 0x18D1 && device->product_id() == 0x58F0) { |
| 210 scoped_refptr<UsbDeviceHandle> handle = device->Open(); | 210 scoped_refptr<UsbDeviceHandle> handle = device->Open(); |
| 211 if (handle.get() == NULL) { | 211 if (handle.get() == NULL) { |
| 212 continue; | 212 continue; |
| 213 } | 213 } |
| 214 | 214 |
| 215 base::string16 serial_utf16; | 215 base::string16 serial_utf16; |
| 216 if (!handle->GetSerial(&serial_utf16)) { | 216 if (!handle->GetSerial(&serial_utf16)) { |
| 217 continue; | 217 continue; |
| 218 } | 218 } |
| 219 | 219 |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 } | 526 } |
| 527 PlatformThread::Sleep(TimeDelta::FromMilliseconds(kRetryPeriod)); | 527 PlatformThread::Sleep(TimeDelta::FromMilliseconds(kRetryPeriod)); |
| 528 } | 528 } |
| 529 VLOG(1) << "It took " << (kDisconnectRetries - retries) | 529 VLOG(1) << "It took " << (kDisconnectRetries - retries) |
| 530 << " retries for the device to reconnect."; | 530 << " retries for the device to reconnect."; |
| 531 | 531 |
| 532 return true; | 532 return true; |
| 533 } | 533 } |
| 534 | 534 |
| 535 } // namespace device | 535 } // namespace device |
| OLD | NEW |