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

Unified Diff: device/usb/usb_device.h

Issue 580963002: Add a service to track devices selected by the user. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
Index: device/usb/usb_device.h
diff --git a/device/usb/usb_device.h b/device/usb/usb_device.h
index a012025b35784be2a1e1f90f467e80c9d1938973..f4bd5915467086be66671c7751e6347770d141f8 100644
--- a/device/usb/usb_device.h
+++ b/device/usb/usb_device.h
@@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/memory/ref_counted.h"
+#include "base/observer_list.h"
namespace device {
@@ -19,6 +20,11 @@ struct UsbConfigDescriptor;
// UsbDeviceHandle must be created from Open() method.
class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> {
public:
+ class Observer {
+ public:
+ virtual void OnDisconnect(scoped_refptr<UsbDevice> device) = 0;
+ };
+
// Accessors to basic information.
uint16 vendor_id() const { return vendor_id_; }
uint16 product_id() const { return product_id_; }
@@ -48,11 +54,14 @@ class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> {
// Blocking method. Must be called on FILE thread.
virtual const UsbConfigDescriptor& GetConfiguration() = 0;
+ void AddObserver(Observer* obs) { observer_list_.AddObserver(obs); }
+ void RemoveObserver(Observer* obs) { observer_list_.RemoveObserver(obs); }
+
protected:
- UsbDevice(uint16 vendor_id, uint16 product_id, uint32 unique_id)
- : vendor_id_(vendor_id), product_id_(product_id), unique_id_(unique_id) {}
+ UsbDevice(uint16 vendor_id, uint16 product_id, uint32 unique_id);
+ virtual ~UsbDevice();
- virtual ~UsbDevice() {}
+ void NotifyDisconnect();
private:
friend class base::RefCountedThreadSafe<UsbDevice>;
@@ -61,6 +70,8 @@ class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> {
const uint16 product_id_;
const uint32 unique_id_;
+ ObserverList<Observer> observer_list_;
+
DISALLOW_COPY_AND_ASSIGN(UsbDevice);
};

Powered by Google App Engine
This is Rietveld 408576698