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

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: Use typemaped types in the TestDeviceInfo struct. 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
« no previous file with comments | « device/usb/usb_service.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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()));
+ 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());
« no previous file with comments | « device/usb/usb_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698