Fixes crashing in RequestUsbDevicesAccess

Pointer returned by vector::begin is not checked before use.

BUG=291012, 288070

Review URL: https://chromiumcodereview.appspot.com/23475048

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223516 0039d316-1c4b-4281-b951-d872f2087c98
parent c7b3c677
......@@ -325,6 +325,10 @@ void RequestUsbDevicesAccess(
ScopedDeviceVector devices,
int interface_id,
const base::Callback<void(ScopedDeviceVector result)>& callback) {
if (devices->empty()) {
callback.Run(devices.Pass());
return;
}
(*devices->begin())->RequestUsbAcess(
interface_id,
base::Bind(RequestUsbDevicesAccessHelper, base::Passed(devices.Pass()),
......
......@@ -20,6 +20,17 @@
using content::BrowserThread;
namespace {
void OnRequestUsbAccessReplied(
const base::Callback<void(bool success)>& callback,
bool success) {
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
base::Bind(callback, success));
}
} // namespace
UsbDevice::UsbDevice(
scoped_refptr<UsbContext> context,
PlatformUsbDevice platform_device,
......@@ -55,6 +66,7 @@ UsbDevice::~UsbDevice() {
}
#if defined(OS_CHROMEOS)
void UsbDevice::RequestUsbAcess(
int interface_id,
const base::Callback<void(bool success)>& callback) {
......@@ -78,19 +90,10 @@ void UsbDevice::RequestUsbAcess(
this->vendor_id_,
this->product_id_,
interface_id,
base::Bind(&UsbDevice::OnRequestUsbAccessReplied,
base::Unretained(this),
callback)));
base::Bind(&OnRequestUsbAccessReplied, callback)));
}
}
void UsbDevice::OnRequestUsbAccessReplied(
const base::Callback<void(bool success)>& callback,
bool success) {
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
base::Bind(callback, success));
}
#endif
scoped_refptr<UsbDeviceHandle> UsbDevice::Open() {
......
......@@ -73,15 +73,6 @@ class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> {
// Called only be UsbService.
virtual void OnDisconnect();
#if defined(OS_CHROMEOS)
// This method is called when permission broker replied our request.
// We will simply relay it to FILE thread.
// |callback| comes first because it will be base::Bind'ed.
void OnRequestUsbAccessReplied(
const base::Callback<void(bool success)>& callback,
bool success);
#endif // OS_CHROMEOS
private:
PlatformUsbDevice platform_device_;
uint16 vendor_id_;
......
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