| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/usb_guid_map.h" | 5 #include "extensions/browser/api/usb/usb_guid_map.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 return false; | 49 return false; |
| 50 *guid = iter->second; | 50 *guid = iter->second; |
| 51 return true; | 51 return true; |
| 52 } | 52 } |
| 53 | 53 |
| 54 void UsbGuidMap::GetApiDevice(scoped_refptr<const device::UsbDevice> device_in, | 54 void UsbGuidMap::GetApiDevice(scoped_refptr<const device::UsbDevice> device_in, |
| 55 extensions::api::usb::Device* device_out) { | 55 extensions::api::usb::Device* device_out) { |
| 56 device_out->device = GetIdFromGuid(device_in->guid()); | 56 device_out->device = GetIdFromGuid(device_in->guid()); |
| 57 device_out->vendor_id = device_in->vendor_id(); | 57 device_out->vendor_id = device_in->vendor_id(); |
| 58 device_out->product_id = device_in->product_id(); | 58 device_out->product_id = device_in->product_id(); |
| 59 device_out->version = device_in->device_version(); |
| 59 device_out->product_name = base::UTF16ToUTF8(device_in->product_string()); | 60 device_out->product_name = base::UTF16ToUTF8(device_in->product_string()); |
| 60 device_out->manufacturer_name = | 61 device_out->manufacturer_name = |
| 61 base::UTF16ToUTF8(device_in->manufacturer_string()); | 62 base::UTF16ToUTF8(device_in->manufacturer_string()); |
| 62 device_out->serial_number = base::UTF16ToUTF8(device_in->serial_number()); | 63 device_out->serial_number = base::UTF16ToUTF8(device_in->serial_number()); |
| 63 } | 64 } |
| 64 | 65 |
| 65 UsbGuidMap::UsbGuidMap(content::BrowserContext* browser_context) | 66 UsbGuidMap::UsbGuidMap(content::BrowserContext* browser_context) |
| 66 : browser_context_(browser_context), observer_(this) { | 67 : browser_context_(browser_context), observer_(this) { |
| 67 device::UsbService* service = device::DeviceClient::Get()->GetUsbService(); | 68 device::UsbService* service = device::DeviceClient::Get()->GetUsbService(); |
| 68 DCHECK(service); | 69 DCHECK(service); |
| 69 observer_.Add(service); | 70 observer_.Add(service); |
| 70 } | 71 } |
| 71 | 72 |
| 72 UsbGuidMap::~UsbGuidMap() { | 73 UsbGuidMap::~UsbGuidMap() { |
| 73 } | 74 } |
| 74 | 75 |
| 75 void UsbGuidMap::OnDeviceRemovedCleanup( | 76 void UsbGuidMap::OnDeviceRemovedCleanup( |
| 76 scoped_refptr<device::UsbDevice> device) { | 77 scoped_refptr<device::UsbDevice> device) { |
| 77 auto iter = guid_to_id_map_.find(device->guid()); | 78 auto iter = guid_to_id_map_.find(device->guid()); |
| 78 if (iter != guid_to_id_map_.end()) { | 79 if (iter != guid_to_id_map_.end()) { |
| 79 int id = iter->second; | 80 int id = iter->second; |
| 80 guid_to_id_map_.erase(iter); | 81 guid_to_id_map_.erase(iter); |
| 81 id_to_guid_map_.erase(id); | 82 id_to_guid_map_.erase(id); |
| 82 } | 83 } |
| 83 } | 84 } |
| 84 | 85 |
| 85 } // namespace extensions | 86 } // namespace extensions |
| OLD | NEW |