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 "extensions/browser/api/usb_private/usb_private_api.h" | 5 #include "extensions/browser/api/usb_private/usb_private_api.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 using device::UsbDeviceFilter; | 26 using device::UsbDeviceFilter; |
27 using device::UsbDeviceHandle; | 27 using device::UsbDeviceHandle; |
28 using device::UsbService; | 28 using device::UsbService; |
29 | 29 |
30 typedef std::vector<scoped_refptr<UsbDevice> > DeviceVector; | 30 typedef std::vector<scoped_refptr<UsbDevice> > DeviceVector; |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 const char kErrorInitService[] = "Failed to initialize USB service."; | 34 const char kErrorInitService[] = "Failed to initialize USB service."; |
35 const char kErrorNoDevice[] = "No such device."; | 35 const char kErrorNoDevice[] = "No such device."; |
36 const char kErrorOpen[] = "Failed to open device."; | |
37 | 36 |
38 } // namespace | 37 } // namespace |
39 | 38 |
40 namespace extensions { | 39 namespace extensions { |
41 | 40 |
42 UsbPrivateGetDevicesFunction::UsbPrivateGetDevicesFunction() { | 41 UsbPrivateGetDevicesFunction::UsbPrivateGetDevicesFunction() { |
43 } | 42 } |
44 | 43 |
45 UsbPrivateGetDevicesFunction::~UsbPrivateGetDevicesFunction() { | 44 UsbPrivateGetDevicesFunction::~UsbPrivateGetDevicesFunction() { |
46 } | 45 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 if (name) { | 112 if (name) { |
114 device_info.vendor_name.reset(new std::string(name)); | 113 device_info.vendor_name.reset(new std::string(name)); |
115 } | 114 } |
116 | 115 |
117 name = device::UsbIds::GetProductName(device_info.vendor_id, | 116 name = device::UsbIds::GetProductName(device_info.vendor_id, |
118 device_info.product_id); | 117 device_info.product_id); |
119 if (name) { | 118 if (name) { |
120 device_info.product_name.reset(new std::string(name)); | 119 device_info.product_name.reset(new std::string(name)); |
121 } | 120 } |
122 | 121 |
123 scoped_refptr<UsbDeviceHandle> device_handle = device->Open(); | |
124 if (!device_handle.get()) { | |
125 CompleteWithError(kErrorOpen); | |
126 return; | |
127 } | |
128 | |
129 base::string16 utf16; | 122 base::string16 utf16; |
130 if (device_handle->GetManufacturer(&utf16)) { | 123 if (device->GetManufacturer(&utf16)) { |
131 device_info.manufacturer_string.reset( | 124 device_info.manufacturer_string.reset( |
132 new std::string(base::UTF16ToUTF8(utf16))); | 125 new std::string(base::UTF16ToUTF8(utf16))); |
133 } | 126 } |
134 | 127 |
135 if (device_handle->GetProduct(&utf16)) { | 128 if (device->GetProduct(&utf16)) { |
136 device_info.product_string.reset(new std::string(base::UTF16ToUTF8(utf16))); | 129 device_info.product_string.reset(new std::string(base::UTF16ToUTF8(utf16))); |
137 } | 130 } |
138 | 131 |
139 if (device_handle->GetSerial(&utf16)) { | 132 if (device->GetSerialNumber(&utf16)) { |
140 device_info.serial_string.reset(new std::string(base::UTF16ToUTF8(utf16))); | 133 device_info.serial_string.reset(new std::string(base::UTF16ToUTF8(utf16))); |
141 } | 134 } |
142 | 135 |
143 SetResult(device_info.ToValue().release()); | 136 SetResult(device_info.ToValue().release()); |
144 AsyncWorkCompleted(); | 137 AsyncWorkCompleted(); |
145 } | 138 } |
146 | 139 |
147 } // namespace extensions | 140 } // namespace extensions |
OLD | NEW |