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

Unified Diff: device/usb/usb_device_impl.cc

Issue 809743006: Add an Observer interface to UsbService for device add/remove. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clarify comment. Created 5 years, 11 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/usb_device.h ('k') | device/usb/usb_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/usb/usb_device_impl.cc
diff --git a/device/usb/usb_device_impl.cc b/device/usb/usb_device_impl.cc
index 407862c55d6d0170de23d2eaad167a9bf3b45392..bc3d68978e50376a0f27e3c8964fa18fbe07e5f0 100644
--- a/device/usb/usb_device_impl.cc
+++ b/device/usb/usb_device_impl.cc
@@ -104,17 +104,6 @@ UsbUsageType GetUsageType(const libusb_endpoint_descriptor* descriptor) {
} // namespace
-UsbDevice::UsbDevice(uint16 vendor_id, uint16 product_id, uint32 unique_id)
- : vendor_id_(vendor_id), product_id_(product_id), unique_id_(unique_id) {
-}
-
-UsbDevice::~UsbDevice() {
-}
-
-void UsbDevice::NotifyDisconnect() {
- FOR_EACH_OBSERVER(Observer, observer_list_, OnDisconnect(this));
-}
-
UsbDeviceImpl::UsbDeviceImpl(
scoped_refptr<UsbContext> context,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
@@ -184,12 +173,7 @@ UsbDeviceImpl::UsbDeviceImpl(
}
UsbDeviceImpl::~UsbDeviceImpl() {
- DCHECK(thread_checker_.CalledOnValidThread());
- for (HandlesVector::iterator it = handles_.begin(); it != handles_.end();
- ++it) {
- (*it)->InternalClose();
- }
- STLClearObject(&handles_);
+ // The destructor must be safe to call from any thread.
libusb_unref_device(platform_device_);
}
@@ -377,10 +361,15 @@ bool UsbDeviceImpl::GetSerialNumber(base::string16* serial_number) {
void UsbDeviceImpl::OnDisconnect() {
DCHECK(thread_checker_.CalledOnValidThread());
+
+ // Swap the list of handles into a local variable because closing all open
+ // handles may release the last reference to this object.
HandlesVector handles;
swap(handles, handles_);
- for (HandlesVector::iterator it = handles.begin(); it != handles.end(); ++it)
- (*it)->InternalClose();
+
+ for (const scoped_refptr<UsbDeviceHandleImpl>& handle : handles_) {
+ handle->InternalClose();
+ }
}
#if !defined(USE_UDEV)
« no previous file with comments | « device/usb/usb_device.h ('k') | device/usb/usb_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698