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

Unified Diff: chrome/browser/usb/usb_service.h

Issue 16316004: Separate usb device handle from usb device. (deprecate) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix the threading mess Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/usb/usb_interface.cc ('k') | chrome/browser/usb/usb_service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/usb/usb_service.h
diff --git a/chrome/browser/usb/usb_service.h b/chrome/browser/usb/usb_service.h
index 8e04ce2646a96c5cc693a910d4a08c7ffa2de6a6..0d2a42e4cda26fdfb196b63c3425f32818a0c188 100644
--- a/chrome/browser/usb/usb_service.h
+++ b/chrome/browser/usb/usb_service.h
@@ -10,89 +10,75 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/threading/non_thread_safe.h"
#include "base/threading/platform_thread.h"
-#include "chrome/browser/usb/usb_device.h"
+#include "chrome/browser/usb/usb_device_handle.h"
#include "components/browser_context_keyed_service/browser_context_keyed_service.h"
#include "third_party/libusb/src/libusb/libusb.h"
-class UsbEventHandler;
-typedef libusb_context* PlatformUsbContext;
+class UsbDevice;
+class UsbContext;
+
+typedef struct libusb_context* PlatformUsbContext;
+typedef struct libusb_device* PlatformUsbDevice;
// The USB service handles creating and managing an event handler thread that is
// used to manage and dispatch USB events. It is also responsbile for device
// discovery on the system, which allows it to re-use device handles to prevent
// competition for the same USB device.
-class UsbService : public BrowserContextKeyedService {
+//
+// This class should commonly be used on FILE thread.
+class UsbService : public BrowserContextKeyedService,
+ public base::NonThreadSafe {
public:
UsbService();
virtual ~UsbService();
- // Cleanup must be invoked before the service is destroyed. It interrupts the
- // event handling thread and disposes of open devices.
- void Cleanup();
-
+ virtual void Shutdown() OVERRIDE;
// Find all of the devices attached to the system that are identified by
// |vendor_id| and |product_id|, inserting them into |devices|. Clears
// |devices| before use. Calls |callback| once |devices| is populated.
- void FindDevices(const uint16 vendor_id,
- const uint16 product_id,
- int interface_id,
- std::vector<scoped_refptr<UsbDevice> >* devices,
+ void FindDevices(const uint16 vendor_id, const uint16 product_id,
+ const int interface_id, std::vector<int>* devices,
const base::Callback<void()>& callback);
+ // Open a device for further communication.
+ scoped_refptr<UsbDeviceHandle> OpenDevice(int device);
+
// This function should not be called by normal code. It is invoked by a
// UsbDevice's Close function and disposes of the associated platform handle.
- void CloseDevice(scoped_refptr<UsbDevice> device);
+ void CloseDeviceHandle(scoped_refptr<UsbDeviceHandle> device);
- private:
- // RefCountedPlatformUsbDevice takes care of managing the underlying reference
- // count of a single PlatformUsbDevice. This allows us to construct things
- // like vectors of RefCountedPlatformUsbDevices and not worry about having to
- // explicitly unreference them after use.
- class RefCountedPlatformUsbDevice {
- public:
- explicit RefCountedPlatformUsbDevice(PlatformUsbDevice device);
- RefCountedPlatformUsbDevice(const RefCountedPlatformUsbDevice& other);
- virtual ~RefCountedPlatformUsbDevice();
- PlatformUsbDevice device();
-
- private:
- PlatformUsbDevice device_;
- };
-
- typedef std::vector<RefCountedPlatformUsbDevice> DeviceVector;
+ // Schedule an update to USB device info.
+ // This method can be called on any thread.
+ void ScheduleEnumerateDevice();
+ private:
// Return true if |device|'s vendor and product identifiers match |vendor_id|
// and |product_id|.
- static bool DeviceMatches(PlatformUsbDevice device,
- const uint16 vendor_id,
+ static bool DeviceMatches(const UsbDevice* device, const uint16 vendor_id,
const uint16 product_id);
// FindDevicesImpl is called by FindDevices on ChromeOS after the permission
- // broker has signalled that permission has been granted to access the
+ // broker has signaled that permission has been granted to access the
// underlying device nodes. On other platforms, it is called directly by
// FindDevices.
- void FindDevicesImpl(const uint16 vendor_id,
- const uint16 product_id,
- std::vector<scoped_refptr<UsbDevice> >* devices,
- const base::Callback<void()>& callback,
- bool success);
-
- // Populates |output| with the result of enumerating all attached USB devices.
- void EnumerateDevices(DeviceVector* output);
-
- // If a UsbDevice wrapper corresponding to |device| has already been created,
- // returns it. Otherwise, opens the device, creates a wrapper, and associates
- // the wrapper with the device internally.
- UsbDevice* LookupOrCreateDevice(PlatformUsbDevice device);
-
- PlatformUsbContext context_;
- UsbEventHandler* event_handler_;
-
- // The devices_ map contains scoped_refptrs to all open devices, indicated by
- // their vendor and product id. This allows for reusing an open device without
- // creating another platform handle for it.
- typedef std::map<PlatformUsbDevice, scoped_refptr<UsbDevice> > DeviceMap;
+ void FindDevicesImpl(const uint16 vendor_id, const uint16 product_id,
+ std::vector<int>* devices,
+ const base::Callback<void()>& callback, bool success);
+
+ // Enumerate USB devices from OS and Update devices_ map.
+ void EnumerateDevices();
+
+ scoped_refptr<UsbContext> context_;
+ int next_unique_id_;
+
+ bool device_enumeration_scheduled_;
+
+ // The devices_ map contains all connected devices.
+ // They are not to be used directly outside UsbService. Instead, FindDevice
+ // methods returns their id for accessing them.
+ typedef std::map<PlatformUsbDevice, UsbDevice*> DeviceMap;
DeviceMap devices_;
DISALLOW_COPY_AND_ASSIGN(UsbService);
« no previous file with comments | « chrome/browser/usb/usb_interface.cc ('k') | chrome/browser/usb/usb_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698