summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorreillyg <reillyg@chromium.org>2016-02-04 14:45:36 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-04 22:46:40 +0000
commit6bc4255ecd25658b430cec1f6191e0044c5e6c7f (patch)
treec49c64afc96020ce05e698d317e254f9bf50aff4 /extensions
parent51b446ee6bfbf2d14c9caec773a9d6b1227785ad (diff)
downloadchromium_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 'extensions')
-rw-r--r--extensions/browser/api/usb/usb_api.cc16
-rw-r--r--extensions/browser/api/usb/usb_api.h2
2 files changed, 13 insertions, 5 deletions
diff --git a/extensions/browser/api/usb/usb_api.cc b/extensions/browser/api/usb/usb_api.cc
index 3035239..73099f9 100644
--- a/extensions/browser/api/usb/usb_api.cc
+++ b/extensions/browser/api/usb/usb_api.cc
@@ -925,11 +925,17 @@ ExtensionFunction::ResponseAction UsbReleaseInterfaceFunction::Run() {
return RespondNow(Error(kErrorNoConnection));
}
- if (device_handle->ReleaseInterface(parameters->interface_number)) {
- return RespondNow(NoArguments());
- } else {
- return RespondNow(Error(kErrorCannotReleaseInterface));
- }
+ device_handle->ReleaseInterface(
+ parameters->interface_number,
+ base::Bind(&UsbReleaseInterfaceFunction::OnComplete, this));
+ return RespondLater();
+}
+
+void UsbReleaseInterfaceFunction::OnComplete(bool success) {
+ if (success)
+ Respond(NoArguments());
+ else
+ Respond(Error(kErrorCannotReleaseInterface));
}
UsbSetInterfaceAlternateSettingFunction::
diff --git a/extensions/browser/api/usb/usb_api.h b/extensions/browser/api/usb/usb_api.h
index 3d1dec1..397b1ad 100644
--- a/extensions/browser/api/usb/usb_api.h
+++ b/extensions/browser/api/usb/usb_api.h
@@ -268,6 +268,8 @@ class UsbReleaseInterfaceFunction : public UsbConnectionFunction {
// ExtensionFunction:
ResponseAction Run() override;
+ void OnComplete(bool success);
+
DISALLOW_COPY_AND_ASSIGN(UsbReleaseInterfaceFunction);
};