Index: chrome/browser/extensions/api/usb/usb_api.cc |
diff --git a/chrome/browser/extensions/api/usb/usb_api.cc b/chrome/browser/extensions/api/usb/usb_api.cc |
index fd6981296cd8c767d69108928528ad79c4331816..b7ae9c5ee41072f2b056183d913597be247fdb10 100644 |
--- a/chrome/browser/extensions/api/usb/usb_api.cc |
+++ b/chrome/browser/extensions/api/usb/usb_api.cc |
@@ -39,10 +39,16 @@ bool UsbAsyncApiFunction::PrePrepare() { |
return manager_ != NULL; |
} |
+UsbDevice* UsbFindDeviceFunction::device_for_test_ = NULL; |
+ |
UsbFindDeviceFunction::UsbFindDeviceFunction() : event_notifier_(NULL) {} |
UsbFindDeviceFunction::~UsbFindDeviceFunction() {} |
+void UsbFindDeviceFunction::SetDeviceForTest(UsbDevice* device) { |
+ device_for_test_ = device; |
+} |
+ |
bool UsbFindDeviceFunction::Prepare() { |
parameters_ = FindDevice::Params::Create(*args_); |
EXTENSION_FUNCTION_VALIDATE(parameters_.get()); |
@@ -51,12 +57,18 @@ bool UsbFindDeviceFunction::Prepare() { |
} |
void UsbFindDeviceFunction::Work() { |
- UsbService* const service = |
- UsbServiceFactory::GetInstance()->GetForProfile(profile()); |
- DCHECK(service) << "No UsbService associated with profile."; |
+ UsbDevice* device = NULL; |
+ if (device_for_test_) { |
+ device = device_for_test_; |
+ } else { |
+ UsbService* const service = UsbServiceFactory::GetInstance()->GetForProfile( |
+ profile()); |
+ DCHECK(service) << "No UsbService associated with profile."; |
asargent_no_longer_on_chrome
2012/08/14 22:31:06
nit: Since we'll crash on the next line anyway if
|
+ |
+ device = service->FindDevice(parameters_->vendor_id, |
+ parameters_->product_id); |
+ } |
- UsbDevice* const device = service->FindDevice(parameters_->vendor_id, |
- parameters_->product_id); |
if (!device) { |
SetResult(base::Value::CreateNullValue()); |
return; |
@@ -87,6 +99,10 @@ bool UsbCloseDeviceFunction::Prepare() { |
} |
void UsbCloseDeviceFunction::Work() { |
+ UsbDeviceResource* const device = manager_->Get(parameters_->device.handle); |
+ if (device) |
+ device->Close(); |
+ |
manager_->Remove(parameters_->device.handle); |
} |