| 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 "chrome/browser/usb/usb_chooser_context.h" | 5 #include "chrome/browser/usb/usb_chooser_context.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 std::move(device_dict)); | 145 std::move(device_dict)); |
| 146 } else { | 146 } else { |
| 147 ephemeral_devices_[std::make_pair(requesting_origin, embedding_origin)] | 147 ephemeral_devices_[std::make_pair(requesting_origin, embedding_origin)] |
| 148 .insert(guid); | 148 .insert(guid); |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 bool UsbChooserContext::HasDevicePermission( | 152 bool UsbChooserContext::HasDevicePermission( |
| 153 const GURL& requesting_origin, | 153 const GURL& requesting_origin, |
| 154 const GURL& embedding_origin, | 154 const GURL& embedding_origin, |
| 155 const device::usb::DeviceInfo& device_info) { | 155 scoped_refptr<const device::UsbDevice> device) { |
| 156 auto it = ephemeral_devices_.find( | 156 auto it = ephemeral_devices_.find( |
| 157 std::make_pair(requesting_origin, embedding_origin)); | 157 std::make_pair(requesting_origin, embedding_origin)); |
| 158 if (it != ephemeral_devices_.end() && | 158 if (it != ephemeral_devices_.end() && |
| 159 ContainsValue(it->second, device_info.guid)) { | 159 ContainsValue(it->second, device->guid())) { |
| 160 return true; | 160 return true; |
| 161 } | 161 } |
| 162 | 162 |
| 163 std::vector<scoped_ptr<base::DictionaryValue>> device_list = | 163 std::vector<scoped_ptr<base::DictionaryValue>> device_list = |
| 164 GetGrantedObjects(requesting_origin, embedding_origin); | 164 GetGrantedObjects(requesting_origin, embedding_origin); |
| 165 for (const scoped_ptr<base::DictionaryValue>& device_dict : device_list) { | 165 for (const scoped_ptr<base::DictionaryValue>& device_dict : device_list) { |
| 166 int vendor_id; | 166 int vendor_id; |
| 167 int product_id; | 167 int product_id; |
| 168 std::string serial_number; | 168 base::string16 serial_number; |
| 169 if (device_dict->GetInteger(kVendorIdKey, &vendor_id) && | 169 if (device_dict->GetInteger(kVendorIdKey, &vendor_id) && |
| 170 device_info.vendor_id == vendor_id && | 170 device->vendor_id() == vendor_id && |
| 171 device_dict->GetInteger(kProductIdKey, &product_id) && | 171 device_dict->GetInteger(kProductIdKey, &product_id) && |
| 172 device_info.product_id == product_id && | 172 device->product_id() == product_id && |
| 173 device_dict->GetString(kSerialNumberKey, &serial_number) && | 173 device_dict->GetString(kSerialNumberKey, &serial_number) && |
| 174 device_info.serial_number == serial_number) { | 174 device->serial_number() == serial_number) { |
| 175 return true; | 175 return true; |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 | 178 |
| 179 return false; | 179 return false; |
| 180 } | 180 } |
| 181 | 181 |
| 182 bool UsbChooserContext::IsValidObject(const base::DictionaryValue& object) { | 182 bool UsbChooserContext::IsValidObject(const base::DictionaryValue& object) { |
| 183 return object.size() == 4 && object.HasKey(kDeviceNameKey) && | 183 return object.size() == 4 && object.HasKey(kDeviceNameKey) && |
| 184 object.HasKey(kVendorIdKey) && object.HasKey(kProductIdKey) && | 184 object.HasKey(kVendorIdKey) && object.HasKey(kProductIdKey) && |
| 185 object.HasKey(kSerialNumberKey); | 185 object.HasKey(kSerialNumberKey); |
| 186 } | 186 } |
| 187 | 187 |
| 188 void UsbChooserContext::OnDeviceRemoved(scoped_refptr<UsbDevice> device) { | 188 void UsbChooserContext::OnDeviceRemoved(scoped_refptr<UsbDevice> device) { |
| 189 for (auto& map_entry : ephemeral_devices_) | 189 for (auto& map_entry : ephemeral_devices_) |
| 190 map_entry.second.erase(device->guid()); | 190 map_entry.second.erase(device->guid()); |
| 191 } | 191 } |
| OLD | NEW |