This source file includes following definitions.
- start_polling_
- ThreadMain
#include "chrome/browser/usb/usb_context.h"
#include "base/logging.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/platform_thread.h"
#include "third_party/libusb/src/libusb/interrupt.h"
#include "third_party/libusb/src/libusb/libusb.h"
class UsbContext::UsbEventHandler : public base::PlatformThread::Delegate {
 public:
  explicit UsbEventHandler(libusb_context* context);
  virtual ~UsbEventHandler();
  
  virtual void ThreadMain() OVERRIDE;
 private:
  volatile bool running_;
  libusb_context* context_;
  base::PlatformThreadHandle thread_handle_;
  base::WaitableEvent start_polling_;
  DISALLOW_COPY_AND_ASSIGN(UsbEventHandler);
};
UsbContext::UsbEventHandler::UsbEventHandler(libusb_context* context)
    : running_(true),
      context_(context),
      thread_handle_(0),
      start_polling_(false, false) {
  bool success = base::PlatformThread::Create(0, this, &thread_handle_);
  DCHECK(success) << "Failed to create USB IO handling thread.";
  start_polling_.Wait();
}
UsbContext::UsbEventHandler::~UsbEventHandler() {
  running_ = false;
  
  base::subtle::MemoryBarrier();
  libusb_interrupt_handle_event(context_);
  base::PlatformThread::Join(thread_handle_);
}
void UsbContext::UsbEventHandler::ThreadMain() {
  base::PlatformThread::SetName("UsbEventHandler");
  VLOG(1) << "UsbEventHandler started.";
  if (running_) {
    start_polling_.Signal();
    libusb_handle_events(context_);
  }
  while (running_)
    libusb_handle_events(context_);
  VLOG(1) << "UsbEventHandler shutting down.";
}
UsbContext::UsbContext(PlatformUsbContext context) : context_(context) {
  DCHECK(thread_checker_.CalledOnValidThread());
  event_handler_ = new UsbEventHandler(context_);
}
UsbContext::~UsbContext() {
  
  DCHECK(thread_checker_.CalledOnValidThread());
  delete event_handler_;
  event_handler_ = NULL;
  libusb_exit(context_);
}