OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/usb_service/usb_device_impl.h" | 5 #include "components/usb_service/usb_device_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "components/usb_service/usb_context.h" | 10 #include "components/usb_service/usb_context.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 } | 90 } |
91 | 91 |
92 #endif | 92 #endif |
93 | 93 |
94 scoped_refptr<UsbDeviceHandle> UsbDeviceImpl::Open() { | 94 scoped_refptr<UsbDeviceHandle> UsbDeviceImpl::Open() { |
95 DCHECK(thread_checker_.CalledOnValidThread()); | 95 DCHECK(thread_checker_.CalledOnValidThread()); |
96 PlatformUsbDeviceHandle handle; | 96 PlatformUsbDeviceHandle handle; |
97 const int rv = libusb_open(platform_device_, &handle); | 97 const int rv = libusb_open(platform_device_, &handle); |
98 if (LIBUSB_SUCCESS == rv) { | 98 if (LIBUSB_SUCCESS == rv) { |
99 scoped_refptr<UsbConfigDescriptor> interfaces = ListInterfaces(); | 99 scoped_refptr<UsbConfigDescriptor> interfaces = ListInterfaces(); |
100 if (!interfaces) | 100 if (!interfaces.get()) |
101 return NULL; | 101 return NULL; |
102 scoped_refptr<UsbDeviceHandleImpl> device_handle = | 102 scoped_refptr<UsbDeviceHandleImpl> device_handle = |
103 new UsbDeviceHandleImpl(context_, this, handle, interfaces); | 103 new UsbDeviceHandleImpl(context_, this, handle, interfaces); |
104 handles_.push_back(device_handle); | 104 handles_.push_back(device_handle); |
105 return device_handle; | 105 return device_handle; |
106 } else { | 106 } else { |
107 VLOG(1) << "Failed to open device: " << ConvertErrorToString(rv); | 107 VLOG(1) << "Failed to open device: " << ConvertErrorToString(rv); |
108 return NULL; | 108 return NULL; |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 bool UsbDeviceImpl::Close(scoped_refptr<UsbDeviceHandle> handle) { | 112 bool UsbDeviceImpl::Close(scoped_refptr<UsbDeviceHandle> handle) { |
113 DCHECK(thread_checker_.CalledOnValidThread()); | 113 DCHECK(thread_checker_.CalledOnValidThread()); |
114 | 114 |
115 for (HandlesVector::iterator it = handles_.begin(); it != handles_.end(); | 115 for (HandlesVector::iterator it = handles_.begin(); it != handles_.end(); |
116 ++it) { | 116 ++it) { |
117 if (*it == handle) { | 117 if (it->get() == handle.get()) { |
118 (*it)->InternalClose(); | 118 (*it)->InternalClose(); |
119 handles_.erase(it); | 119 handles_.erase(it); |
120 return true; | 120 return true; |
121 } | 121 } |
122 } | 122 } |
123 return false; | 123 return false; |
124 } | 124 } |
125 | 125 |
126 scoped_refptr<UsbConfigDescriptor> UsbDeviceImpl::ListInterfaces() { | 126 scoped_refptr<UsbConfigDescriptor> UsbDeviceImpl::ListInterfaces() { |
127 DCHECK(thread_checker_.CalledOnValidThread()); | 127 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 11 matching lines...) Expand all Loading... |
139 | 139 |
140 void UsbDeviceImpl::OnDisconnect() { | 140 void UsbDeviceImpl::OnDisconnect() { |
141 DCHECK(thread_checker_.CalledOnValidThread()); | 141 DCHECK(thread_checker_.CalledOnValidThread()); |
142 HandlesVector handles; | 142 HandlesVector handles; |
143 swap(handles, handles_); | 143 swap(handles, handles_); |
144 for (HandlesVector::iterator it = handles.begin(); it != handles.end(); ++it) | 144 for (HandlesVector::iterator it = handles.begin(); it != handles.end(); ++it) |
145 (*it)->InternalClose(); | 145 (*it)->InternalClose(); |
146 } | 146 } |
147 | 147 |
148 } // namespace usb_service | 148 } // namespace usb_service |
OLD | NEW |