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

Unified Diff: chrome/browser/usb/usb_service.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 | « chrome/browser/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: chrome/browser/usb/usb_service.cc
diff --git a/chrome/browser/usb/usb_service.cc b/chrome/browser/usb/usb_service.cc
index b44c1fa0136871e2492564da77d2312348ee8b4f..15e6abfc1e9f090e7ab2503201661af6812cfc9d 100644
--- a/chrome/browser/usb/usb_service.cc
+++ b/chrome/browser/usb/usb_service.cc
@@ -64,8 +64,8 @@ class ExitObserver : public content::NotificationObserver {
using content::BrowserThread;
-UsbService::UsbService()
- : context_(new UsbContext()),
+UsbService::UsbService(PlatformUsbContext context)
+ : context_(new UsbContext(context)),
next_unique_id_(0) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
// Will be deleted upon NOTIFICATION_APP_TERMINATING.
@@ -79,10 +79,22 @@ UsbService::~UsbService() {
}
}
+struct InitUsbContextTraits : public LeakySingletonTraits<UsbService> {
+ // LeakySingletonTraits<UsbService>
+ static UsbService* New() {
+ PlatformUsbContext context = NULL;
+ if (libusb_init(&context) != LIBUSB_SUCCESS)
+ return NULL;
+ if (!context)
+ return NULL;
+ return new UsbService(context);
+ }
+};
+
UsbService* UsbService::GetInstance() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
// UsbService deletes itself upon APP_TERMINATING.
- return Singleton<UsbService, LeakySingletonTraits<UsbService> >::get();
+ return Singleton<UsbService, InitUsbContextTraits>::get();
}
void UsbService::GetDevices(std::vector<scoped_refptr<UsbDevice> >* devices) {
« no previous file with comments | « chrome/browser/usb/usb_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698