Commit 3bcdf2a2 authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

Dispatch UsbChooserContext::GetDevices callback asynchronously

In r604906 this method was updated to return the device list from cache
if available. By running the passed callback synchronously however this
violated the assumptions of other code, such as the USB device chooser
on Android.

Methods that execute a callback either synchronously or asynchronously
tend to trigger errors in other code and so rather than work around this
change in behavior this patch forces the callback to always be run
asynchronously.

Bug: 904321
Change-Id: Ib6a71bee3c578e42e2812bc762db40ebc2bd6994
Reviewed-on: https://chromium-review.googlesource.com/c/1338941
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#608912}
parent d575b98b
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/usb/usb_blocklist.h" #include "chrome/browser/usb/usb_blocklist.h"
...@@ -279,15 +280,16 @@ bool UsbChooserContext::HasDevicePermission( ...@@ -279,15 +280,16 @@ bool UsbChooserContext::HasDevicePermission(
void UsbChooserContext::GetDevices( void UsbChooserContext::GetDevices(
device::mojom::UsbDeviceManager::GetDevicesCallback callback) { device::mojom::UsbDeviceManager::GetDevicesCallback callback) {
if (is_initialized_) { if (!is_initialized_) {
std::vector<device::mojom::UsbDeviceInfoPtr> device_list;
for (const auto& pair : devices_) {
device_list.push_back(pair.second->Clone());
}
std::move(callback).Run(std::move(device_list));
} else {
pending_get_devices_requests_.push(std::move(callback)); pending_get_devices_requests_.push(std::move(callback));
return;
} }
std::vector<device::mojom::UsbDeviceInfoPtr> device_list;
for (const auto& pair : devices_)
device_list.push_back(pair.second->Clone());
base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), std::move(device_list)));
} }
void UsbChooserContext::GetDevice( void UsbChooserContext::GetDevice(
......
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