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

Unified Diff: device/usb/usb_device.h

Issue 1695643002: Destroy DeviceImpl when the underlying UsbDevice is disconnected. (Closed) Base URL: reillyg-linux.mtv.corp.google.com:/src/chromium/src@mojo_device_autoclose
Patch Set: Revert change to web_usb_device_impl.cc. Created 4 years, 10 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 | « device/usb/mojo/device_impl_unittest.cc ('k') | device/usb/usb_device.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
};
« no previous file with comments | « device/usb/mojo/device_impl_unittest.cc ('k') | device/usb/usb_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698