0

Implement getConfiguration in WebUSBDeviceImpl.

This USBDevice method allows a site to determine the current
configuration state of the device. A follow-up to this change will make
WebUSBDevice::getConfiguration a pure virtual method.

Blink change: https://codereview.chromium.org/1352283005/

BUG=492204

Review URL: https://codereview.chromium.org/1358763004

Cr-Commit-Position: refs/heads/master@{#350212}
This commit is contained in:
reillyg
2015-09-22 12:30:21 -07:00
committed by Commit bot
parent d4699bbca9
commit 8b606624ec
4 changed files with 28 additions and 4 deletions
content/renderer/usb
device/devices_app/usb

@ -23,6 +23,7 @@ namespace {
const char kClaimInterfaceFailed[] = "Unable to claim interface.";
const char kClearHaltFailed[] = "Unable to clear endpoint.";
const char kDeviceNoAccess[] = "Access denied.";
const char kDeviceNotConfigured[] = "Device not configured.";
const char kDeviceNotOpened[] = "Device not opened.";
const char kDeviceUnavailable[] = "Device unavailable.";
const char kDeviceResetFailed[] = "Unable to reset the device.";
@ -90,6 +91,16 @@ void OnDeviceClosed(
callbacks.PassCallbacks()->onSuccess();
}
void OnGetConfiguration(
ScopedWebCallbacks<blink::WebUSBDeviceGetConfigurationCallbacks> callbacks,
uint8_t configuration_value) {
auto scoped_callbacks = callbacks.PassCallbacks();
if (configuration_value == 0)
RejectWithDeviceError(kDeviceNotConfigured, scoped_callbacks.Pass());
else
scoped_callbacks->onSuccess(configuration_value);
}
void HandlePassFailDeviceOperation(
ScopedWebCallbacks<blink::WebCallbacks<void, const blink::WebUSBError&>>
callbacks,
@ -171,6 +182,17 @@ void WebUSBDeviceImpl::close(blink::WebUSBDeviceCloseCallbacks* callbacks) {
}
}
void WebUSBDeviceImpl::getConfiguration(
blink::WebUSBDeviceGetConfigurationCallbacks* callbacks) {
auto scoped_callbacks = MakeScopedUSBCallbacks(callbacks);
if (!device_) {
RejectWithDeviceError(kDeviceNotOpened, scoped_callbacks.PassCallbacks());
} else {
device_->GetConfiguration(
base::Bind(&OnGetConfiguration, base::Passed(&scoped_callbacks)));
}
}
void WebUSBDeviceImpl::setConfiguration(
uint8_t configuration_value,
blink::WebUSBDeviceSetConfigurationCallbacks* callbacks) {

@ -32,6 +32,8 @@ class WebUSBDeviceImpl : public blink::WebUSBDevice {
const blink::WebUSBDeviceInfo& info() const override;
void open(blink::WebUSBDeviceOpenCallbacks* callbacks) override;
void close(blink::WebUSBDeviceCloseCallbacks* callbacks) override;
void getConfiguration(
blink::WebUSBDeviceGetConfigurationCallbacks* callbacks) override;
void setConfiguration(
uint8_t configuration_value,
blink::WebUSBDeviceSetConfigurationCallbacks* callbacks) override;

@ -116,7 +116,7 @@ void DeviceImpl::GetDeviceInfo(const GetDeviceInfoCallback& callback) {
void DeviceImpl::GetConfiguration(const GetConfigurationCallback& callback) {
const UsbConfigDescriptor* config = device_->GetActiveConfiguration();
callback.Run(config ? ConfigurationInfo::From(*config) : nullptr);
callback.Run(config ? config->configuration_value : 0);
}
void DeviceImpl::Open(const OpenCallback& callback) {

@ -141,9 +141,9 @@ interface Device {
// including the set of all available device configurations.
GetDeviceInfo() => (DeviceInfo? info);
// Retrieves the device's currently active configuration. May return null if
// the device is unconfigured.
GetConfiguration() => (ConfigurationInfo? info);
// Retrieves the |configuration_value| of the device's currently active
// configuration. Will return 0 if the device is unconfigured.
GetConfiguration() => (uint8 value);
// Opens the device. Methods below require the device be opened first.
Open() => (OpenDeviceError error);