| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 118 |
| 119 void UsbPrivateGetDeviceInfoFunction::AsyncWorkStart() { | 119 void UsbPrivateGetDeviceInfoFunction::AsyncWorkStart() { |
| 120 UsbService* service = UsbService::GetInstance(); | 120 UsbService* service = UsbService::GetInstance(); |
| 121 if (!service) { | 121 if (!service) { |
| 122 CompleteWithError(kErrorInitService); | 122 CompleteWithError(kErrorInitService); |
| 123 return; | 123 return; |
| 124 } | 124 } |
| 125 | 125 |
| 126 scoped_refptr<UsbDevice> device = | 126 scoped_refptr<UsbDevice> device = |
| 127 service->GetDeviceById(parameters_->device_id); | 127 service->GetDeviceById(parameters_->device_id); |
| 128 if (!device) { | 128 if (!device.get()) { |
| 129 CompleteWithError(kErrorNoDevice); | 129 CompleteWithError(kErrorNoDevice); |
| 130 return; | 130 return; |
| 131 } | 131 } |
| 132 | 132 |
| 133 usb_private::DeviceInfo device_info; | 133 usb_private::DeviceInfo device_info; |
| 134 device_info.vendor_id = device->vendor_id(); | 134 device_info.vendor_id = device->vendor_id(); |
| 135 device_info.product_id = device->product_id(); | 135 device_info.product_id = device->product_id(); |
| 136 | 136 |
| 137 const char* name = device::UsbIds::GetVendorName(device_info.vendor_id); | 137 const char* name = device::UsbIds::GetVendorName(device_info.vendor_id); |
| 138 if (name) { | 138 if (name) { |
| 139 device_info.vendor_name.reset(new std::string(name)); | 139 device_info.vendor_name.reset(new std::string(name)); |
| 140 } | 140 } |
| 141 | 141 |
| 142 name = device::UsbIds::GetProductName(device_info.vendor_id, | 142 name = device::UsbIds::GetProductName(device_info.vendor_id, |
| 143 device_info.product_id); | 143 device_info.product_id); |
| 144 if (name) { | 144 if (name) { |
| 145 device_info.product_name.reset(new std::string(name)); | 145 device_info.product_name.reset(new std::string(name)); |
| 146 } | 146 } |
| 147 | 147 |
| 148 scoped_refptr<UsbDeviceHandle> device_handle = device->Open(); | 148 scoped_refptr<UsbDeviceHandle> device_handle = device->Open(); |
| 149 if (!device_handle) { | 149 if (!device_handle.get()) { |
| 150 CompleteWithError(kErrorOpen); | 150 CompleteWithError(kErrorOpen); |
| 151 return; | 151 return; |
| 152 } | 152 } |
| 153 | 153 |
| 154 base::string16 utf16; | 154 base::string16 utf16; |
| 155 if (device_handle->GetManufacturer(&utf16)) { | 155 if (device_handle->GetManufacturer(&utf16)) { |
| 156 device_info.manufacturer_string.reset( | 156 device_info.manufacturer_string.reset( |
| 157 new std::string(base::UTF16ToUTF8(utf16))); | 157 new std::string(base::UTF16ToUTF8(utf16))); |
| 158 } | 158 } |
| 159 | 159 |
| 160 if (device_handle->GetProduct(&utf16)) { | 160 if (device_handle->GetProduct(&utf16)) { |
| 161 device_info.product_string.reset(new std::string(base::UTF16ToUTF8(utf16))); | 161 device_info.product_string.reset(new std::string(base::UTF16ToUTF8(utf16))); |
| 162 } | 162 } |
| 163 | 163 |
| 164 if (device_handle->GetSerial(&utf16)) { | 164 if (device_handle->GetSerial(&utf16)) { |
| 165 device_info.serial_string.reset(new std::string(base::UTF16ToUTF8(utf16))); | 165 device_info.serial_string.reset(new std::string(base::UTF16ToUTF8(utf16))); |
| 166 } | 166 } |
| 167 | 167 |
| 168 SetResult(device_info.ToValue().release()); | 168 SetResult(device_info.ToValue().release()); |
| 169 AsyncWorkCompleted(); | 169 AsyncWorkCompleted(); |
| 170 } | 170 } |
| 171 | 171 |
| 172 } // namespace extensions | 172 } // namespace extensions |
| OLD | NEW |