summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorreillyg <reillyg@chromium.org>2014-09-25 15:02:48 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-25 22:02:59 +0000
commit43c5c906400e24aa59382d47a8654c35c2cb9cc6 (patch)
tree02b7cd45c0427ef2b005a31ef747c3d5fc415d89 /apps
parentd0956cf3b7e8662b94e3ef26b4d685ddc6702a0a (diff)
downloadchromium_src-43c5c906400e24aa59382d47a8654c35c2cb9cc6.zip
chromium_src-43c5c906400e24aa59382d47a8654c35c2cb9cc6.tar.gz
chromium_src-43c5c906400e24aa59382d47a8654c35c2cb9cc6.tar.bz2
Move string descriptor getters from UsbDeviceHandle to UsbDevice.
The common string descriptors: iManufacturer, iProduct and iSerialNumber should be accessible without opening the device. On Linux these can be read out of sysfs without having access to the usbfs device node. This is critical on Chrome OS because otherwise the permission broker needs to be asked for permission to access the device. On other platforms we fall back to opening the device temporarily. This will stop being the case on OS X when libusb is no longer used and on Windows this will be part of the initial enumeration process. BUG= TBR=dgozman@chromium.org Review URL: https://codereview.chromium.org/601073002 Cr-Commit-Position: refs/heads/master@{#296802}
Diffstat (limited to 'apps')
-rw-r--r--apps/saved_devices_service.cc6
-rw-r--r--apps/saved_devices_service_unittest.cc81
2 files changed, 11 insertions, 76 deletions
diff --git a/apps/saved_devices_service.cc b/apps/saved_devices_service.cc
index df7db1d..d7e894c 100644
--- a/apps/saved_devices_service.cc
+++ b/apps/saved_devices_service.cc
@@ -158,11 +158,7 @@ bool SavedDevicesService::SavedDevices::IsRegistered(
continue;
}
if (!have_serial_number) {
- scoped_refptr<UsbDeviceHandle> device_handle = device->Open();
- if (!device_handle.get()) {
- break;
- }
- if (!device_handle->GetSerial(&serial_number)) {
+ if (!device->GetSerialNumber(&serial_number)) {
break;
}
have_serial_number = true;
diff --git a/apps/saved_devices_service_unittest.cc b/apps/saved_devices_service_unittest.cc
index b2ed544..b48e8a6 100644
--- a/apps/saved_devices_service_unittest.cc
+++ b/apps/saved_devices_service_unittest.cc
@@ -25,88 +25,27 @@ using device::UsbEndpointDirection;
using device::UsbTransferCallback;
using testing::Return;
-class MockUsbDeviceHandle : public UsbDeviceHandle {
- public:
- MockUsbDeviceHandle(const std::string& serial_number)
- : UsbDeviceHandle(), serial_number_(serial_number) {}
-
- MOCK_CONST_METHOD0(GetDevice, scoped_refptr<UsbDevice>());
- MOCK_METHOD0(Close, void());
-
- MOCK_METHOD10(ControlTransfer,
- void(UsbEndpointDirection direction,
- TransferRequestType request_type,
- TransferRecipient recipient,
- uint8 request,
- uint16 value,
- uint16 index,
- net::IOBuffer* buffer,
- size_t length,
- unsigned int timeout,
- const UsbTransferCallback& callback));
-
- MOCK_METHOD6(BulkTransfer,
- void(UsbEndpointDirection direction,
- uint8 endpoint,
- net::IOBuffer* buffer,
- size_t length,
- unsigned int timeout,
- const UsbTransferCallback& callback));
-
- MOCK_METHOD6(InterruptTransfer,
- void(UsbEndpointDirection direction,
- uint8 endpoint,
- net::IOBuffer* buffer,
- size_t length,
- unsigned int timeout,
- const UsbTransferCallback& callback));
-
- MOCK_METHOD8(IsochronousTransfer,
- void(UsbEndpointDirection direction,
- uint8 endpoint,
- net::IOBuffer* buffer,
- size_t length,
- unsigned int packets,
- unsigned int packet_length,
- unsigned int timeout,
- const UsbTransferCallback& callback));
-
- MOCK_METHOD0(ResetDevice, bool());
- MOCK_METHOD1(ClaimInterface, bool(int interface_number));
- MOCK_METHOD1(ReleaseInterface, bool(int interface_number));
- MOCK_METHOD2(SetInterfaceAlternateSetting,
- bool(int interface_number, int alternate_setting));
- MOCK_METHOD1(GetManufacturer, bool(base::string16* manufacturer));
- MOCK_METHOD1(GetProduct, bool(base::string16* product));
-
- bool GetSerial(base::string16* serial) OVERRIDE {
- if (serial_number_.empty()) {
- return false;
- }
-
- *serial = base::UTF8ToUTF16(serial_number_);
- return true;
- }
-
- private:
- virtual ~MockUsbDeviceHandle() {}
-
- const std::string serial_number_;
-};
-
class MockUsbDevice : public UsbDevice {
public:
MockUsbDevice(const std::string& serial_number, uint32 unique_id)
: UsbDevice(0, 0, unique_id), serial_number_(serial_number) {}
+ MOCK_METHOD0(Open, scoped_refptr<UsbDeviceHandle>());
MOCK_METHOD1(Close, bool(scoped_refptr<UsbDeviceHandle>));
#if defined(OS_CHROMEOS)
MOCK_METHOD2(RequestUsbAccess, void(int, const base::Callback<void(bool)>&));
#endif
MOCK_METHOD0(GetConfiguration, const device::UsbConfigDescriptor&());
+ MOCK_METHOD1(GetManufacturer, bool(base::string16*));
+ MOCK_METHOD1(GetProduct, bool(base::string16*));
+
+ bool GetSerialNumber(base::string16* serial) OVERRIDE {
+ if (serial_number_.empty()) {
+ return false;
+ }
- scoped_refptr<UsbDeviceHandle> Open() OVERRIDE {
- return new MockUsbDeviceHandle(serial_number_);
+ *serial = base::UTF8ToUTF16(serial_number_);
+ return true;
}
void NotifyDisconnect() { UsbDevice::NotifyDisconnect(); }