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 if (base::chromeos::IsRunningOnChromeOS()) { |
bryeung
2013/05/27 12:40:54
This looks very wrong, so I must not understand.
zel
2013/05/27 18:48:12
base::chromeos::IsRunningOnChromeOS() returns fals
bryeung
2013/05/27 18:50:26
Got it: thanks for the explanation. A brief comme
zel
2013/05/28 16:58:27
Done.
| |
78 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient(); | 79 chromeos::PermissionBrokerClient* client = |
79 DCHECK(client) << "Could not get permission broker client."; | 80 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient(); |
80 if (!client) { | 81 DCHECK(client) << "Could not get permission broker client."; |
81 callback.Run(); | 82 if (!client) { |
82 return; | 83 callback.Run(); |
84 return; | |
85 } | |
86 | |
87 client->RequestUsbAccess(vendor_id, | |
88 product_id, | |
89 base::Bind(&UsbService::FindDevicesImpl, | |
90 base::Unretained(this), | |
91 vendor_id, | |
92 product_id, | |
93 devices, | |
94 callback)); | |
95 } else { | |
96 FindDevicesImpl(vendor_id, product_id, devices, callback, true); | |
83 } | 97 } |
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 | 98 #else |
94 FindDevicesImpl(vendor_id, product_id, devices, callback, true); | 99 FindDevicesImpl(vendor_id, product_id, devices, callback, true); |
95 #endif // defined(OS_CHROMEOS) | 100 #endif // defined(OS_CHROMEOS) |
96 } | 101 } |
97 | 102 |
98 void UsbService::FindDevicesImpl(const uint16 vendor_id, | 103 void UsbService::FindDevicesImpl(const uint16 vendor_id, |
99 const uint16 product_id, | 104 const uint16 product_id, |
100 vector<scoped_refptr<UsbDevice> >* devices, | 105 vector<scoped_refptr<UsbDevice> >* devices, |
101 const base::Callback<void()>& callback, | 106 const base::Callback<void()>& callback, |
102 bool success) { | 107 bool success) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 if (libusb_open(device, &handle)) { | 193 if (libusb_open(device, &handle)) { |
189 LOG(WARNING) << "Could not open device."; | 194 LOG(WARNING) << "Could not open device."; |
190 return NULL; | 195 return NULL; |
191 } | 196 } |
192 | 197 |
193 UsbDevice* wrapper = new UsbDevice(this, handle); | 198 UsbDevice* wrapper = new UsbDevice(this, handle); |
194 devices_[device] = wrapper; | 199 devices_[device] = wrapper; |
195 } | 200 } |
196 return devices_[device]; | 201 return devices_[device]; |
197 } | 202 } |
OLD | NEW |