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

Side by Side Diff: chrome/browser/usb/usb_context.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 unified diff | Download patch
« no previous file with comments | « chrome/browser/usb/usb_context.h ('k') | chrome/browser/usb/usb_context_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/usb/usb_context.h" 5 #include "chrome/browser/usb/usb_context.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/synchronization/waitable_event.h" 8 #include "base/synchronization/waitable_event.h"
9 #include "base/threading/platform_thread.h" 9 #include "base/threading/platform_thread.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 VLOG(1) << "UsbEventHandler started."; 53 VLOG(1) << "UsbEventHandler started.";
54 if (running_) { 54 if (running_) {
55 start_polling_.Signal(); 55 start_polling_.Signal();
56 libusb_handle_events(context_); 56 libusb_handle_events(context_);
57 } 57 }
58 while (running_) 58 while (running_)
59 libusb_handle_events(context_); 59 libusb_handle_events(context_);
60 VLOG(1) << "UsbEventHandler shutting down."; 60 VLOG(1) << "UsbEventHandler shutting down.";
61 } 61 }
62 62
63 UsbContext::UsbContext() : context_(NULL) { 63 UsbContext::UsbContext(PlatformUsbContext context) : context_(context) {
64 DCHECK(thread_checker_.CalledOnValidThread()); 64 DCHECK(thread_checker_.CalledOnValidThread());
65 CHECK_EQ(0, libusb_init(&context_)) << "Cannot initialize libusb";
66 event_handler_ = new UsbEventHandler(context_); 65 event_handler_ = new UsbEventHandler(context_);
67 } 66 }
68 67
69 UsbContext::~UsbContext() { 68 UsbContext::~UsbContext() {
70 // destruction of UsbEventHandler is a blocking operation. 69 // destruction of UsbEventHandler is a blocking operation.
71 DCHECK(thread_checker_.CalledOnValidThread()); 70 DCHECK(thread_checker_.CalledOnValidThread());
72 delete event_handler_; 71 delete event_handler_;
73 event_handler_ = NULL; 72 event_handler_ = NULL;
74 libusb_exit(context_); 73 libusb_exit(context_);
75 } 74 }
OLDNEW
« no previous file with comments | « chrome/browser/usb/usb_context.h ('k') | chrome/browser/usb/usb_context_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698