Index: device/usb/usb_device.h |
diff --git a/device/usb/usb_device.h b/device/usb/usb_device.h |
index 27454051a010e113b3c3e15766e2da5a587a0f0e..b1406d9b23be76c37264c6dc8b800480fabe6f6b 100644 |
--- a/device/usb/usb_device.h |
+++ b/device/usb/usb_device.h |
@@ -13,6 +13,7 @@ |
#include "base/callback.h" |
#include "base/macros.h" |
#include "base/memory/ref_counted.h" |
+#include "base/observer_list.h" |
#include "base/strings/string16.h" |
#include "device/usb/usb_descriptors.h" |
#include "url/gurl.h" |
@@ -32,6 +33,18 @@ class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> { |
using OpenCallback = base::Callback<void(scoped_refptr<UsbDeviceHandle>)>; |
using ResultCallback = base::Callback<void(bool success)>; |
+ // This observer interface should be used by objects that need only be |
+ // notified about the removal of a particular device as it is more efficient |
+ // than registering a large number of observers with UsbService::AddObserver. |
+ class Observer { |
+ public: |
+ virtual ~Observer(); |
+ |
+ // This method is called when the UsbService that created this object |
+ // detects that the device has been disconnected from the host. |
+ virtual void OnDeviceRemoved(scoped_refptr<UsbDevice> device); |
+ }; |
+ |
// A unique identifier which remains stable for the lifetime of this device |
// object (i.e., until the device is unplugged or the USB service dies.) |
const std::string& guid() const { return guid_; } |
@@ -64,7 +77,12 @@ class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> { |
// if the device is unconfigured. |
virtual const UsbConfigDescriptor* GetActiveConfiguration() = 0; |
+ void AddObserver(Observer* observer); |
+ void RemoveObserver(Observer* observer); |
+ |
protected: |
+ friend class UsbService; |
+ |
UsbDevice(uint16_t vendor_id, |
uint16_t product_id, |
const base::string16& manufacturer_string, |
@@ -72,6 +90,8 @@ class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> { |
const base::string16& serial_number); |
virtual ~UsbDevice(); |
+ void NotifyDeviceRemoved(); |
+ |
// These members must be mutable by subclasses as necessary during device |
// enumeration. To preserve the thread safety of this object they must remain |
// constant afterwards. |
@@ -91,6 +111,8 @@ class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> { |
const uint16_t vendor_id_; |
const uint16_t product_id_; |
+ base::ObserverList<Observer, true> observer_list_; |
+ |
DISALLOW_COPY_AND_ASSIGN(UsbDevice); |
}; |