OLD | NEW |
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 Loading... |
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 } |
OLD | NEW |