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

Unified Diff: chrome/browser/extensions/api/usb/usb_api.cc

Issue 23571007: Fail gracefully when libusb_init fails (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@usb-safe-exit
Patch Set: Fix tests Created 7 years, 3 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 | « no previous file | chrome/browser/usb/usb_context.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 e6ca32719227234f0c338b134e3f11198121cd34..f6bf5c174408d1beb05f4bb4926e4f2c7bec0f16 100644
--- a/chrome/browser/extensions/api/usb/usb_api.cc
+++ b/chrome/browser/extensions/api/usb/usb_api.cc
@@ -59,6 +59,8 @@ namespace {
const char kDataKey[] = "data";
const char kResultCodeKey[] = "resultCode";
+const char kErrorInitService[] = "Failed to initialize USB service.";
+
const char kErrorOpen[] = "Failed to open device.";
const char kErrorCancelled[] = "Transfer was cancelled.";
const char kErrorDisconnect[] = "Device disconnected.";
@@ -412,6 +414,10 @@ UsbAsyncApiFunction::GetDeviceOrOrCompleteWithError(
}
UsbService* service = UsbService::GetInstance();
+ if (!service) {
+ CompleteWithError(kErrorInitService);
+ return NULL;
+ }
scoped_refptr<UsbDevice> device;
device = service->GetDeviceById(input_device.device);
@@ -537,6 +543,11 @@ void UsbFindDevicesFunction::AsyncWorkStart() {
}
UsbService *service = UsbService::GetInstance();
+ if (!service) {
+ CompleteWithError(kErrorInitService);
+ return;
+ }
+
ScopedDeviceVector devices(new DeviceVector());
service->GetDevices(devices.get());
@@ -624,6 +635,11 @@ void UsbGetDevicesFunction::AsyncWorkStart() {
}
UsbService* service = UsbService::GetInstance();
+ if (!service) {
+ CompleteWithError(kErrorInitService);
+ return;
+ }
+
DeviceVector devices;
service->GetDevices(&devices);
« no previous file with comments | « no previous file | chrome/browser/usb/usb_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698