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

Side by Side Diff: components/usb_service/usb_device_impl.cc

Issue 278633003: Extracted UsbDeviceHandle as interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « components/usb_service/usb_device_impl.h ('k') | extensions/browser/api/usb/usb_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "components/usb_service/usb_device_handle.h" 11 #include "components/usb_service/usb_device_handle_impl.h"
12 #include "components/usb_service/usb_interface_impl.h" 12 #include "components/usb_service/usb_interface_impl.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "third_party/libusb/src/libusb/libusb.h" 14 #include "third_party/libusb/src/libusb/libusb.h"
15 15
16 #if defined(OS_CHROMEOS) 16 #if defined(OS_CHROMEOS)
17 #include "base/sys_info.h" 17 #include "base/sys_info.h"
18 #include "chromeos/dbus/dbus_thread_manager.h" 18 #include "chromeos/dbus/dbus_thread_manager.h"
19 #include "chromeos/dbus/permission_broker_client.h" 19 #include "chromeos/dbus/permission_broker_client.h"
20 #endif // defined(OS_CHROMEOS) 20 #endif // defined(OS_CHROMEOS)
21 21
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 #endif 91 #endif
92 92
93 scoped_refptr<UsbDeviceHandle> UsbDeviceImpl::Open() { 93 scoped_refptr<UsbDeviceHandle> UsbDeviceImpl::Open() {
94 DCHECK(thread_checker_.CalledOnValidThread()); 94 DCHECK(thread_checker_.CalledOnValidThread());
95 PlatformUsbDeviceHandle handle; 95 PlatformUsbDeviceHandle handle;
96 int rv = libusb_open(platform_device_, &handle); 96 int rv = libusb_open(platform_device_, &handle);
97 if (LIBUSB_SUCCESS == rv) { 97 if (LIBUSB_SUCCESS == rv) {
98 scoped_refptr<UsbConfigDescriptor> interfaces = ListInterfaces(); 98 scoped_refptr<UsbConfigDescriptor> interfaces = ListInterfaces();
99 if (!interfaces) 99 if (!interfaces)
100 return NULL; 100 return NULL;
101 scoped_refptr<UsbDeviceHandle> device_handle = 101 scoped_refptr<UsbDeviceHandleImpl> device_handle =
102 new UsbDeviceHandle(context_, this, handle, interfaces); 102 new UsbDeviceHandleImpl(context_, this, handle, interfaces);
103 handles_.push_back(device_handle); 103 handles_.push_back(device_handle);
104 return device_handle; 104 return device_handle;
105 } 105 }
106 return NULL; 106 return NULL;
107 } 107 }
108 108
109 bool UsbDeviceImpl::Close(scoped_refptr<UsbDeviceHandle> handle) { 109 bool UsbDeviceImpl::Close(scoped_refptr<UsbDeviceHandle> handle) {
110 DCHECK(thread_checker_.CalledOnValidThread()); 110 DCHECK(thread_checker_.CalledOnValidThread());
111 111
112 for (HandlesVector::iterator it = handles_.begin(); it != handles_.end(); 112 for (HandlesVector::iterator it = handles_.begin(); it != handles_.end();
(...skipping 16 matching lines...) Expand all
129 if (list_result == 0) 129 if (list_result == 0)
130 return new UsbConfigDescriptorImpl(platform_config); 130 return new UsbConfigDescriptorImpl(platform_config);
131 131
132 return NULL; 132 return NULL;
133 } 133 }
134 134
135 void UsbDeviceImpl::OnDisconnect() { 135 void UsbDeviceImpl::OnDisconnect() {
136 DCHECK(thread_checker_.CalledOnValidThread()); 136 DCHECK(thread_checker_.CalledOnValidThread());
137 HandlesVector handles; 137 HandlesVector handles;
138 swap(handles, handles_); 138 swap(handles, handles_);
139 for (std::vector<scoped_refptr<UsbDeviceHandle> >::iterator it = 139 for (HandlesVector::iterator it = handles.begin(); it != handles.end(); ++it)
140 handles.begin();
141 it != handles.end();
142 ++it) {
143 (*it)->InternalClose(); 140 (*it)->InternalClose();
144 }
145 } 141 }
146 142
147 } // namespace usb_service 143 } // namespace usb_service
OLDNEW
« no previous file with comments | « components/usb_service/usb_device_impl.h ('k') | extensions/browser/api/usb/usb_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698