OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/usb/usb_service.h" | 5 #include "chrome/browser/usb/usb_service.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "chrome/browser/usb/usb_device.h" | 13 #include "chrome/browser/usb/usb_device.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/chromeos/chromeos_version.h" |
17 #include "chromeos/dbus/dbus_thread_manager.h" | 18 #include "chromeos/dbus/dbus_thread_manager.h" |
18 #include "chromeos/dbus/permission_broker_client.h" | 19 #include "chromeos/dbus/permission_broker_client.h" |
19 #endif // defined(OS_CHROMEOS) | 20 #endif // defined(OS_CHROMEOS) |
20 | 21 |
21 using std::vector; | 22 using std::vector; |
22 | 23 |
23 // The UsbEventHandler works around a design flaw in the libusb interface. There | 24 // The UsbEventHandler works around a design flaw in the libusb interface. There |
24 // is currently no way to signal to libusb that any caller into one of the event | 25 // is currently no way to signal to libusb that any caller into one of the event |
25 // handler calls should return without handling any events. | 26 // handler calls should return without handling any events. |
26 class UsbEventHandler : public base::PlatformThread::Delegate { | 27 class UsbEventHandler : public base::PlatformThread::Delegate { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 event_handler_->Stop(); | 68 event_handler_->Stop(); |
68 event_handler_ = NULL; | 69 event_handler_ = NULL; |
69 } | 70 } |
70 | 71 |
71 void UsbService::FindDevices(const uint16 vendor_id, | 72 void UsbService::FindDevices(const uint16 vendor_id, |
72 const uint16 product_id, | 73 const uint16 product_id, |
73 vector<scoped_refptr<UsbDevice> >* devices, | 74 vector<scoped_refptr<UsbDevice> >* devices, |
74 const base::Callback<void()>& callback) { | 75 const base::Callback<void()>& callback) { |
75 DCHECK(event_handler_) << "FindDevices called after event handler stopped."; | 76 DCHECK(event_handler_) << "FindDevices called after event handler stopped."; |
76 #if defined(OS_CHROMEOS) | 77 #if defined(OS_CHROMEOS) |
77 chromeos::PermissionBrokerClient* client = | 78 // ChromeOS builds on non-ChromeOS machines (dev) should not attempt to |
78 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient(); | 79 // use permission broker. |
79 DCHECK(client) << "Could not get permission broker client."; | 80 if (base::chromeos::IsRunningOnChromeOS()) { |
80 if (!client) { | 81 chromeos::PermissionBrokerClient* client = |
81 callback.Run(); | 82 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient(); |
82 return; | 83 DCHECK(client) << "Could not get permission broker client."; |
| 84 if (!client) { |
| 85 callback.Run(); |
| 86 return; |
| 87 } |
| 88 |
| 89 client->RequestUsbAccess(vendor_id, |
| 90 product_id, |
| 91 base::Bind(&UsbService::FindDevicesImpl, |
| 92 base::Unretained(this), |
| 93 vendor_id, |
| 94 product_id, |
| 95 devices, |
| 96 callback)); |
| 97 } else { |
| 98 FindDevicesImpl(vendor_id, product_id, devices, callback, true); |
83 } | 99 } |
84 | |
85 client->RequestUsbAccess(vendor_id, | |
86 product_id, | |
87 base::Bind(&UsbService::FindDevicesImpl, | |
88 base::Unretained(this), | |
89 vendor_id, | |
90 product_id, | |
91 devices, | |
92 callback)); | |
93 #else | 100 #else |
94 FindDevicesImpl(vendor_id, product_id, devices, callback, true); | 101 FindDevicesImpl(vendor_id, product_id, devices, callback, true); |
95 #endif // defined(OS_CHROMEOS) | 102 #endif // defined(OS_CHROMEOS) |
96 } | 103 } |
97 | 104 |
98 void UsbService::FindDevicesImpl(const uint16 vendor_id, | 105 void UsbService::FindDevicesImpl(const uint16 vendor_id, |
99 const uint16 product_id, | 106 const uint16 product_id, |
100 vector<scoped_refptr<UsbDevice> >* devices, | 107 vector<scoped_refptr<UsbDevice> >* devices, |
101 const base::Callback<void()>& callback, | 108 const base::Callback<void()>& callback, |
102 bool success) { | 109 bool success) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 if (libusb_open(device, &handle)) { | 195 if (libusb_open(device, &handle)) { |
189 LOG(WARNING) << "Could not open device."; | 196 LOG(WARNING) << "Could not open device."; |
190 return NULL; | 197 return NULL; |
191 } | 198 } |
192 | 199 |
193 UsbDevice* wrapper = new UsbDevice(this, handle); | 200 UsbDevice* wrapper = new UsbDevice(this, handle); |
194 devices_[device] = wrapper; | 201 devices_[device] = wrapper; |
195 } | 202 } |
196 return devices_[device]; | 203 return devices_[device]; |
197 } | 204 } |
OLD | NEW |