Commit 5e6837c4 authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

[usb] Remove active configuration cache

This change removes the |active_configuration_| variable so that a
pointer to the mojom::ConfigurationInfo for the active configuration is
no longer cached and is instead computed based on configuration value
of the currently selected active configuration.

Bug: 1016596
Change-Id: If84f0a5207d6743d775d2f314b4f341a2dcc707e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1873919
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Ovidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarOvidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708325}
parent 39478af8
......@@ -130,7 +130,7 @@ bool DeviceImpl::HasControlTransferPermission(
return true;
}
const mojom::UsbConfigurationInfo* config = device_->active_configuration();
const mojom::UsbConfigurationInfo* config = device_->GetActiveConfiguration();
if (!config)
return false;
......@@ -218,7 +218,7 @@ void DeviceImpl::ClaimInterface(uint8_t interface_number,
return;
}
const mojom::UsbConfigurationInfo* config = device_->active_configuration();
const mojom::UsbConfigurationInfo* config = device_->GetActiveConfiguration();
if (!config) {
std::move(callback).Run(false);
return;
......
......@@ -73,6 +73,14 @@ uint16_t UsbDevice::device_version() const {
return GetDeviceVersion(*device_info_);
}
const mojom::UsbConfigurationInfo* UsbDevice::GetActiveConfiguration() const {
for (const auto& config : configurations()) {
if (config->configuration_value == device_info_->active_configuration)
return config.get();
}
return nullptr;
}
void UsbDevice::CheckUsbAccess(ResultCallback callback) {
// By default assume that access to the device is allowed. This is implemented
// on Chrome OS by checking with permission_broker.
......@@ -99,12 +107,6 @@ void UsbDevice::RemoveObserver(Observer* observer) {
void UsbDevice::ActiveConfigurationChanged(int configuration_value) {
device_info_->active_configuration = configuration_value;
for (const auto& config : configurations()) {
if (config->configuration_value == configuration_value) {
active_configuration_ = config.get();
return;
}
}
}
void UsbDevice::NotifyDeviceRemoved() {
......
......@@ -92,9 +92,7 @@ class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> {
const std::vector<mojom::UsbConfigurationInfoPtr>& configurations() const {
return device_info_->configurations;
}
const mojom::UsbConfigurationInfo* active_configuration() const {
return active_configuration_;
}
const mojom::UsbConfigurationInfo* GetActiveConfiguration() const;
// On ChromeOS the permission_broker service must be used to open USB devices.
// This function asks it to check whether a future Open call will be allowed.
......@@ -156,11 +154,6 @@ class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> {
void OnDisconnect();
void HandleClosed(UsbDeviceHandle* handle);
// The current device configuration descriptor. May be null if the device is
// in an unconfigured state; if not null, it is a pointer to one of the
// items in |descriptor_.configurations|.
const mojom::UsbConfigurationInfo* active_configuration_ = nullptr;
// Weak pointers to open handles. HandleClosed() will be called before each
// is freed.
std::list<UsbDeviceHandle*> handles_;
......
......@@ -1000,7 +1000,7 @@ void UsbDeviceHandleImpl::RefreshEndpointMap() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(device_);
endpoint_map_.clear();
const mojom::UsbConfigurationInfo* config = device_->active_configuration();
const mojom::UsbConfigurationInfo* config = device_->GetActiveConfiguration();
if (!config)
return;
......
......@@ -872,7 +872,7 @@ void UsbDeviceHandleUsbfs::RefreshEndpointInfo() {
DCHECK(device_);
endpoints_.clear();
const mojom::UsbConfigurationInfo* config = device_->active_configuration();
const mojom::UsbConfigurationInfo* config = device_->GetActiveConfiguration();
if (!config)
return;
......
......@@ -491,9 +491,9 @@ UsbDeviceHandleWin::UsbDeviceHandleWin(scoped_refptr<UsbDeviceWin> device,
blocking_task_runner_(UsbService::CreateBlockingTaskRunner()) {
DCHECK(!composite);
// Windows only supports configuration 1, which therefore must be active.
DCHECK(device_->active_configuration());
DCHECK(device_->GetActiveConfiguration());
for (const auto& interface : device_->active_configuration()->interfaces) {
for (const auto& interface : device_->GetActiveConfiguration()->interfaces) {
for (const auto& alternate : interface->alternates) {
if (alternate->alternate_setting != 0)
continue;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment