Home | History | Annotate | Download | only in usb
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_USB_USB_CONTEXT_H_
      6 #define CHROME_BROWSER_USB_USB_CONTEXT_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/memory/ref_counted.h"
     10 #include "base/memory/scoped_ptr.h"
     11 #include "base/threading/thread_checker.h"
     12 #include "content/public/browser/browser_thread.h"
     13 
     14 struct libusb_context;
     15 
     16 typedef libusb_context* PlatformUsbContext;
     17 
     18 // Ref-counted wrapper for libusb_context*.
     19 // It also manages the life-cycle of UsbEventHandler.
     20 // It is a blocking operation to delete UsbContext.
     21 // Destructor must be called on FILE thread.
     22 class UsbContext : public base::RefCountedThreadSafe<UsbContext> {
     23  public:
     24   PlatformUsbContext context() const { return context_; }
     25 
     26  protected:
     27   friend class UsbService;
     28   friend class base::RefCountedThreadSafe<UsbContext>;
     29 
     30   UsbContext();
     31   virtual ~UsbContext();
     32 
     33  private:
     34   class UsbEventHandler;
     35   PlatformUsbContext context_;
     36   UsbEventHandler* event_handler_;
     37   base::ThreadChecker thread_checker_;
     38 
     39   DISALLOW_COPY_AND_ASSIGN(UsbContext);
     40 };
     41 
     42 #endif  // CHROME_BROWSER_USB_USB_CONTEXT_H_
     43