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

Unified Diff: device/usb/usb_service.cc

Issue 2204713006: Add chrome://usb-internals page for adding and removing test devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses dpapad@'s nits. Created 4 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: device/usb/usb_service.cc
diff --git a/device/usb/usb_service.cc b/device/usb/usb_service.cc
index e571b9646da99246ddc60748e226e35233703305..b6e6dca0667c93fef1912fd241d46eae47a62967 100644
--- a/device/usb/usb_service.cc
+++ b/device/usb/usb_service.cc
@@ -90,6 +90,40 @@ void UsbService::RemoveObserver(Observer* observer) {
observer_list_.RemoveObserver(observer);
}
+void UsbService::AddDeviceForTesting(scoped_refptr<UsbDevice> device) {
+ DCHECK(CalledOnValidThread());
+ DCHECK(!ContainsKey(devices_, device->guid()));
Robert Sesek 2016/08/08 19:11:36 In production, this would allow a testing device t
Reilly Grant (use Gerrit) 2016/08/08 20:48:24 The GUIDs are generated randomly so there's no pra
+ devices_[device->guid()] = device;
+ testing_devices_.insert(device->guid());
+ NotifyDeviceAdded(device);
+}
+
+void UsbService::RemoveDeviceForTesting(const std::string& device_guid) {
+ DCHECK(CalledOnValidThread());
+ // Allow only devices added with AddDeviceForTesting to be removed with this
+ // method.
+ auto testing_devices_it = testing_devices_.find(device_guid);
+ if (testing_devices_it != testing_devices_.end()) {
+ auto devices_it = devices_.find(device_guid);
+ DCHECK(devices_it != devices_.end());
+ scoped_refptr<UsbDevice> device = devices_it->second;
+ devices_.erase(devices_it);
+ testing_devices_.erase(testing_devices_it);
+ UsbService::NotifyDeviceRemoved(device);
+ }
+}
+
+void UsbService::GetTestDevices(
+ std::vector<scoped_refptr<UsbDevice>>* devices) {
+ devices->clear();
+ devices->reserve(testing_devices_.size());
+ for (const std::string& guid : testing_devices_) {
+ auto it = devices_.find(guid);
+ DCHECK(it != devices_.end());
+ devices->push_back(it->second);
+ }
+}
+
void UsbService::NotifyDeviceAdded(scoped_refptr<UsbDevice> device) {
DCHECK(CalledOnValidThread());

Powered by Google App Engine
This is Rietveld 408576698