diff options
author | gdk@chromium.org <gdk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-13 22:10:56 +0000 |
---|---|---|
committer | gdk@chromium.org <gdk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-13 22:10:56 +0000 |
commit | eb40b23d8dfce79ba31be50b2388512e68f92ffc (patch) | |
tree | 1f4d5ed52be70d0e6329217c912ff485be319616 /chrome/browser/usb | |
parent | 357ca5928171bb58b82c8ff2c3b60eb98009aecc (diff) | |
download | chromium_src-eb40b23d8dfce79ba31be50b2388512e68f92ffc.zip chromium_src-eb40b23d8dfce79ba31be50b2388512e68f92ffc.tar.gz chromium_src-eb40b23d8dfce79ba31be50b2388512e68f92ffc.tar.bz2 |
Fix missing callback chaining in UsbService.
On OS_CHROMEOS when the permission_broker checks a set of devices the
UsbService needs to wait for the async work to complete before responding.
This worked on OS_CHROMEOS desktop builds because the stub implementation of
PermissionBrokerClient wasn't racing to modify the devices vector.
BUG=chromium-os:38836
Review URL: https://chromiumcodereview.appspot.com/12226137
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182320 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/usb')
-rw-r--r-- | chrome/browser/usb/usb_service.cc | 16 | ||||
-rw-r--r-- | chrome/browser/usb/usb_service.h | 6 |
2 files changed, 16 insertions, 6 deletions
diff --git a/chrome/browser/usb/usb_service.cc b/chrome/browser/usb/usb_service.cc index 21e2e33..fcad23d 100644 --- a/chrome/browser/usb/usb_service.cc +++ b/chrome/browser/usb/usb_service.cc @@ -70,30 +70,38 @@ void UsbService::Cleanup() { void UsbService::FindDevices(const uint16 vendor_id, const uint16 product_id, - vector<scoped_refptr<UsbDevice> >* devices) { + vector<scoped_refptr<UsbDevice> >* devices, + const base::Callback<void()>& callback) { DCHECK(event_handler_) << "FindDevices called after event handler stopped."; #if defined(OS_CHROMEOS) chromeos::PermissionBrokerClient* client = chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient(); DCHECK(client) << "Could not get permission broker client."; - if (!client) + if (!client) { + callback.Run(); return; + } + client->RequestUsbAccess(vendor_id, product_id, base::Bind(&UsbService::FindDevicesImpl, base::Unretained(this), vendor_id, product_id, - devices)); + devices, + callback)); #else - FindDevicesImpl(vendor_id, product_id, devices, true); + FindDevicesImpl(vendor_id, product_id, devices, callback, true); #endif // defined(OS_CHROMEOS) } void UsbService::FindDevicesImpl(const uint16 vendor_id, const uint16 product_id, vector<scoped_refptr<UsbDevice> >* devices, + const base::Callback<void()>& callback, bool success) { + base::ScopedClosureRunner run_callback(callback); + devices->clear(); // If the permission broker was unable to obtain permission for the specified diff --git a/chrome/browser/usb/usb_service.h b/chrome/browser/usb/usb_service.h index b18c71d..3987786d3 100644 --- a/chrome/browser/usb/usb_service.h +++ b/chrome/browser/usb/usb_service.h @@ -33,10 +33,11 @@ class UsbService : public ProfileKeyedService { // Find all of the devices attached to the system that are identified by // |vendor_id| and |product_id|, inserting them into |devices|. Clears - // |devices| before use. + // |devices| before use. Calls |callback| once |devices| is populated. void FindDevices(const uint16 vendor_id, const uint16 product_id, - std::vector<scoped_refptr<UsbDevice> >* devices); + std::vector<scoped_refptr<UsbDevice> >* devices, + const base::Callback<void()>& callback); // This function should not be called by normal code. It is invoked by a // UsbDevice's Close function and disposes of the associated platform handle. @@ -73,6 +74,7 @@ class UsbService : public ProfileKeyedService { void FindDevicesImpl(const uint16 vendor_id, const uint16 product_id, std::vector<scoped_refptr<UsbDevice> >* devices, + const base::Callback<void()>& callback, bool success); // Populates |output| with the result of enumerating all attached USB devices. |