Chromium Code Reviews| 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..8cd33689288f3a1c304d6c67bc81e783c94ba6c3 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,21 @@ UsbService::~UsbService() { |
| } |
| } |
| +struct InitUsbContextTraits : public LeakySingletonTraits<UsbService> { |
| + // LeakySingletonTraits<UsbService> |
| + static UsbService* New() { |
| + PlatformUsbContext context; |
| + libusb_init(&context); |
| + if (!context) |
|
xiyuan
2013/09/04 20:22:22
nit: should we check the return code of libusb_ini
Bei Zhang
2013/09/04 21:04:58
I see. There's chance that context is not even ini
|
| + 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) { |