Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(788)

Unified Diff: chrome/browser/usb/usb_service.cc

Issue 22914023: Introducing chrome.usb.getDevices/openDevice API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@usb-interface
Patch Set: Fix comments Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/usb/usb_service.cc
diff --git a/chrome/browser/usb/usb_service.cc b/chrome/browser/usb/usb_service.cc
index 4425d9b4b728bef2a60a47d31e0f7cc1d00b9252..3501c05b2d37f0106fce1ba05e609284679ea315 100644
--- a/chrome/browser/usb/usb_service.cc
+++ b/chrome/browser/usb/usb_service.cc
@@ -64,7 +64,8 @@ class ExitObserver : public content::NotificationObserver {
using content::BrowserThread;
UsbService::UsbService()
- : context_(new UsbContext()) {
+ : context_(new UsbContext()),
+ next_unique_id_(0) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
}
@@ -167,7 +168,7 @@ void UsbService::FindDevicesImpl(
RefreshDevices();
for (DeviceMap::iterator it = devices_.begin();
- it != devices_.end(); ++it) {
+ it != devices_.end(); ++it) {
if (DeviceMatches(it->second, vendor_id, product_id))
devices->push_back(it->second);
}
@@ -175,6 +176,16 @@ void UsbService::FindDevicesImpl(
callback.Run(devices.Pass());
}
+scoped_refptr<UsbDevice> UsbService::GetDeviceById(uint32 unique_id) {
+ RefreshDevices();
+ for (DeviceMap::iterator it = devices_.begin();
+ it != devices_.end(); ++it) {
+ if (it->second->unique_id() == unique_id)
+ return it->second;
+ }
+ return NULL;
+}
+
void UsbService::RefreshDevices() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
@@ -193,9 +204,10 @@ void UsbService::RefreshDevices() {
if (0 != libusb_get_device_descriptor(platform_devices[i], &descriptor))
continue;
UsbDevice* new_device = new UsbDevice(context_,
- platform_devices[i],
- descriptor.idVendor,
- descriptor.idProduct);
+ platform_devices[i],
+ descriptor.idVendor,
+ descriptor.idProduct,
+ ++next_unique_id_);
devices_[platform_devices[i]] = new_device;
connected_devices.insert(new_device);
} else {

Powered by Google App Engine
This is Rietveld 408576698