diff options
author | reillyg <reillyg@chromium.org> | 2016-02-04 14:45:36 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-04 22:46:40 +0000 |
commit | 6bc4255ecd25658b430cec1f6191e0044c5e6c7f (patch) | |
tree | c49c64afc96020ce05e698d317e254f9bf50aff4 /device/devices_app/usb | |
parent | 51b446ee6bfbf2d14c9caec773a9d6b1227785ad (diff) | |
download | chromium_src-6bc4255ecd25658b430cec1f6191e0044c5e6c7f.zip chromium_src-6bc4255ecd25658b430cec1f6191e0044c5e6c7f.tar.gz chromium_src-6bc4255ecd25658b430cec1f6191e0044c5e6c7f.tar.bz2 |
Make UsbDeviceHandle::ReleaseInterface asynchronous.
This patch adds a callback to UsbDeviceHandle::ReleaseInterface that is
called when the interface has been released. Previously this result was
returned synchronously while the actual release operation happened in
the background.
In the process I've fixed an issue where libusb_release_interface could
have been called from the UI thread if there were no pending transfers
to delay it.
BUG=None
Review URL: https://codereview.chromium.org/1664023002
Cr-Commit-Position: refs/heads/master@{#373641}
Diffstat (limited to 'device/devices_app/usb')
-rw-r--r-- | device/devices_app/usb/device_impl.cc | 3 | ||||
-rw-r--r-- | device/devices_app/usb/device_impl_unittest.cc | 14 |
2 files changed, 10 insertions, 7 deletions
diff --git a/device/devices_app/usb/device_impl.cc b/device/devices_app/usb/device_impl.cc index ae8ad40..2eb3ed5 100644 --- a/device/devices_app/usb/device_impl.cc +++ b/device/devices_app/usb/device_impl.cc @@ -303,7 +303,8 @@ void DeviceImpl::ReleaseInterface(uint8_t interface_number, return; } - callback.Run(device_handle_->ReleaseInterface(interface_number)); + device_handle_->ReleaseInterface(interface_number, + WrapMojoCallback(callback)); } void DeviceImpl::SetInterfaceAlternateSetting( diff --git a/device/devices_app/usb/device_impl_unittest.cc b/device/devices_app/usb/device_impl_unittest.cc index e5ee893..b98d330 100644 --- a/device/devices_app/usb/device_impl_unittest.cc +++ b/device/devices_app/usb/device_impl_unittest.cc @@ -192,7 +192,7 @@ class USBDeviceImplTest : public testing::Test { .WillByDefault(Invoke(this, &USBDeviceImplTest::SetConfiguration)); ON_CALL(mock_handle(), ClaimInterface(_, _)) .WillByDefault(Invoke(this, &USBDeviceImplTest::ClaimInterface)); - ON_CALL(mock_handle(), ReleaseInterface(_)) + ON_CALL(mock_handle(), ReleaseInterface(_, _)) .WillByDefault(Invoke(this, &USBDeviceImplTest::ReleaseInterface)); ON_CALL(mock_handle(), SetInterfaceAlternateSetting(_, _, _)) .WillByDefault( @@ -290,12 +290,14 @@ class USBDeviceImplTest : public testing::Test { callback.Run(false); } - bool ReleaseInterface(uint8_t interface_number) { + void ReleaseInterface(uint8_t interface_number, + const UsbDeviceHandle::ResultCallback& callback) { if (ContainsKey(claimed_interfaces_, interface_number)) { claimed_interfaces_.erase(interface_number); - return true; + callback.Run(true); + } else { + callback.Run(false); } - return false; } void SetInterfaceAlternateSetting( @@ -638,7 +640,7 @@ TEST_F(USBDeviceImplTest, ClaimAndReleaseInterface) { loop.Run(); } - EXPECT_CALL(mock_handle(), ReleaseInterface(2)); + EXPECT_CALL(mock_handle(), ReleaseInterface(2, _)); { // Releasing a non-existent interface should fail. @@ -648,7 +650,7 @@ TEST_F(USBDeviceImplTest, ClaimAndReleaseInterface) { loop.Run(); } - EXPECT_CALL(mock_handle(), ReleaseInterface(1)); + EXPECT_CALL(mock_handle(), ReleaseInterface(1, _)); { // Now this should release the claimed interface and close the handle. |