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

Side by Side Diff: device/usb/usb_device_impl.cc

Issue 497363004: Merge components/usb_service into device/usb. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 6 years, 3 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
« no previous file with comments | « device/usb/usb_device_impl.h ('k') | device/usb/usb_error.h » ('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 "device/usb/usb_device_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
14 #include "components/usb_service/usb_context.h" 14 #include "device/usb/usb_context.h"
15 #include "components/usb_service/usb_device_handle_impl.h" 15 #include "device/usb/usb_device_handle_impl.h"
16 #include "components/usb_service/usb_error.h" 16 #include "device/usb/usb_error.h"
17 #include "components/usb_service/usb_interface_impl.h" 17 #include "device/usb/usb_interface_impl.h"
18 #include "third_party/libusb/src/libusb/libusb.h" 18 #include "third_party/libusb/src/libusb/libusb.h"
19 19
20 #if defined(OS_CHROMEOS) 20 #if defined(OS_CHROMEOS)
21 #include "base/sys_info.h" 21 #include "base/sys_info.h"
22 #include "chromeos/dbus/dbus_thread_manager.h" 22 #include "chromeos/dbus/dbus_thread_manager.h"
23 #include "chromeos/dbus/permission_broker_client.h" 23 #include "chromeos/dbus/permission_broker_client.h"
24 #endif // defined(OS_CHROMEOS) 24 #endif // defined(OS_CHROMEOS)
25 25
26 namespace { 26 namespace {
27 27
28 #if defined(OS_CHROMEOS) 28 #if defined(OS_CHROMEOS)
29 void OnRequestUsbAccessReplied( 29 void OnRequestUsbAccessReplied(
30 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 30 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
31 const base::Callback<void(bool success)>& callback, 31 const base::Callback<void(bool success)>& callback,
32 bool success) { 32 bool success) {
33 task_runner->PostTask(FROM_HERE, base::Bind(callback, success)); 33 task_runner->PostTask(FROM_HERE, base::Bind(callback, success));
34 } 34 }
35 #endif // defined(OS_CHROMEOS) 35 #endif // defined(OS_CHROMEOS)
36 36
37 } // namespace 37 } // namespace
38 38
39 namespace usb_service { 39 namespace device {
40 40
41 UsbDeviceImpl::UsbDeviceImpl( 41 UsbDeviceImpl::UsbDeviceImpl(
42 scoped_refptr<UsbContext> context, 42 scoped_refptr<UsbContext> context,
43 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, 43 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
44 PlatformUsbDevice platform_device, 44 PlatformUsbDevice platform_device,
45 uint16 vendor_id, 45 uint16 vendor_id,
46 uint16 product_id, 46 uint16 product_id,
47 uint32 unique_id) 47 uint32 unique_id)
48 : UsbDevice(vendor_id, product_id, unique_id), 48 : UsbDevice(vendor_id, product_id, unique_id),
49 platform_device_(platform_device), 49 platform_device_(platform_device),
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 const int rv = libusb_open(platform_device_, &handle); 102 const int rv = libusb_open(platform_device_, &handle);
103 if (LIBUSB_SUCCESS == rv) { 103 if (LIBUSB_SUCCESS == rv) {
104 scoped_refptr<UsbConfigDescriptor> interfaces = ListInterfaces(); 104 scoped_refptr<UsbConfigDescriptor> interfaces = ListInterfaces();
105 if (!interfaces.get()) 105 if (!interfaces.get())
106 return NULL; 106 return NULL;
107 scoped_refptr<UsbDeviceHandleImpl> device_handle = 107 scoped_refptr<UsbDeviceHandleImpl> device_handle =
108 new UsbDeviceHandleImpl(context_, this, handle, interfaces); 108 new UsbDeviceHandleImpl(context_, this, handle, interfaces);
109 handles_.push_back(device_handle); 109 handles_.push_back(device_handle);
110 return device_handle; 110 return device_handle;
111 } else { 111 } else {
112 VLOG(1) << "Failed to open device: " << ConvertErrorToString(rv); 112 VLOG(1) << "Failed to open device: " << ConvertPlatformUsbErrorToString(rv);
113 return NULL; 113 return NULL;
114 } 114 }
115 } 115 }
116 116
117 bool UsbDeviceImpl::Close(scoped_refptr<UsbDeviceHandle> handle) { 117 bool UsbDeviceImpl::Close(scoped_refptr<UsbDeviceHandle> handle) {
118 DCHECK(thread_checker_.CalledOnValidThread()); 118 DCHECK(thread_checker_.CalledOnValidThread());
119 119
120 for (HandlesVector::iterator it = handles_.begin(); it != handles_.end(); 120 for (HandlesVector::iterator it = handles_.begin(); it != handles_.end();
121 ++it) { 121 ++it) {
122 if (it->get() == handle.get()) { 122 if (it->get() == handle.get()) {
123 (*it)->InternalClose(); 123 (*it)->InternalClose();
124 handles_.erase(it); 124 handles_.erase(it);
125 return true; 125 return true;
126 } 126 }
127 } 127 }
128 return false; 128 return false;
129 } 129 }
130 130
131 scoped_refptr<UsbConfigDescriptor> UsbDeviceImpl::ListInterfaces() { 131 scoped_refptr<UsbConfigDescriptor> UsbDeviceImpl::ListInterfaces() {
132 DCHECK(thread_checker_.CalledOnValidThread()); 132 DCHECK(thread_checker_.CalledOnValidThread());
133 133
134 PlatformUsbConfigDescriptor platform_config; 134 PlatformUsbConfigDescriptor platform_config;
135 const int rv = 135 const int rv =
136 libusb_get_active_config_descriptor(platform_device_, &platform_config); 136 libusb_get_active_config_descriptor(platform_device_, &platform_config);
137 if (rv == LIBUSB_SUCCESS) { 137 if (rv == LIBUSB_SUCCESS) {
138 return new UsbConfigDescriptorImpl(platform_config); 138 return new UsbConfigDescriptorImpl(platform_config);
139 } else { 139 } else {
140 VLOG(1) << "Failed to get config descriptor: " << ConvertErrorToString(rv); 140 VLOG(1) << "Failed to get config descriptor: "
141 << ConvertPlatformUsbErrorToString(rv);
141 return NULL; 142 return NULL;
142 } 143 }
143 } 144 }
144 145
145 void UsbDeviceImpl::OnDisconnect() { 146 void UsbDeviceImpl::OnDisconnect() {
146 DCHECK(thread_checker_.CalledOnValidThread()); 147 DCHECK(thread_checker_.CalledOnValidThread());
147 HandlesVector handles; 148 HandlesVector handles;
148 swap(handles, handles_); 149 swap(handles, handles_);
149 for (HandlesVector::iterator it = handles.begin(); it != handles.end(); ++it) 150 for (HandlesVector::iterator it = handles.begin(); it != handles.end(); ++it)
150 (*it)->InternalClose(); 151 (*it)->InternalClose();
151 } 152 }
152 153
153 } // namespace usb_service 154 } // namespace device
OLDNEW
« no previous file with comments | « device/usb/usb_device_impl.h ('k') | device/usb/usb_error.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698