| 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 "apps/saved_devices_service.h" | 5 #include "apps/saved_devices_service.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "apps/saved_devices_service_factory.h" | 10 #include "apps/saved_devices_service_factory.h" |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/values.h" | 14 #include "base/values.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 15 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 17 #include "device/usb/usb_device.h" | 19 #include "device/usb/usb_device.h" |
| 18 #include "device/usb/usb_device_handle.h" | 20 #include "device/usb/usb_device_handle.h" |
| 21 #include "device/usb/usb_ids.h" |
| 19 #include "extensions/browser/extension_host.h" | 22 #include "extensions/browser/extension_host.h" |
| 20 #include "extensions/browser/extension_prefs.h" | 23 #include "extensions/browser/extension_prefs.h" |
| 21 #include "extensions/browser/extension_system.h" | 24 #include "extensions/browser/extension_system.h" |
| 22 #include "extensions/browser/extension_util.h" | 25 #include "extensions/browser/extension_util.h" |
| 23 #include "extensions/browser/notification_types.h" | 26 #include "extensions/browser/notification_types.h" |
| 24 #include "extensions/common/permissions/api_permission.h" | 27 #include "extensions/common/permissions/api_permission.h" |
| 25 #include "extensions/common/permissions/permission_set.h" | 28 #include "extensions/common/permissions/permission_set.h" |
| 26 #include "extensions/common/permissions/permissions_data.h" | 29 #include "extensions/common/permissions/permissions_data.h" |
| 30 #include "extensions/strings/grit/extensions_strings.h" |
| 31 #include "ui/base/l10n/l10n_util.h" |
| 27 | 32 |
| 28 namespace apps { | 33 namespace apps { |
| 29 | 34 |
| 30 using device::UsbDevice; | 35 using device::UsbDevice; |
| 31 using device::UsbDeviceHandle; | 36 using device::UsbDeviceHandle; |
| 32 using extensions::APIPermission; | 37 using extensions::APIPermission; |
| 33 using extensions::Extension; | 38 using extensions::Extension; |
| 34 using extensions::ExtensionHost; | 39 using extensions::ExtensionHost; |
| 35 using extensions::ExtensionPrefs; | 40 using extensions::ExtensionPrefs; |
| 36 | 41 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 SavedDevices* saved_devices = Get(extension_id); | 268 SavedDevices* saved_devices = Get(extension_id); |
| 264 if (saved_devices) { | 269 if (saved_devices) { |
| 265 return saved_devices; | 270 return saved_devices; |
| 266 } | 271 } |
| 267 | 272 |
| 268 saved_devices = new SavedDevices(profile_, extension_id); | 273 saved_devices = new SavedDevices(profile_, extension_id); |
| 269 extension_id_to_saved_devices_[extension_id] = saved_devices; | 274 extension_id_to_saved_devices_[extension_id] = saved_devices; |
| 270 return saved_devices; | 275 return saved_devices; |
| 271 } | 276 } |
| 272 | 277 |
| 273 std::vector<SavedDeviceEntry> SavedDevicesService::GetAllDevices( | 278 std::vector<base::string16> SavedDevicesService::GetPermissionMessageStrings( |
| 274 const std::string& extension_id) const { | 279 const std::string& extension_id) const { |
| 275 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_); | 280 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_); |
| 276 return GetSavedDeviceEntries(prefs, extension_id); | 281 std::vector<apps::SavedDeviceEntry> device_entries = |
| 282 GetSavedDeviceEntries(prefs, extension_id); |
| 283 std::vector<base::string16> messages; |
| 284 for (std::vector<apps::SavedDeviceEntry>::const_iterator it = |
| 285 device_entries.begin(); |
| 286 it != device_entries.end(); |
| 287 ++it) { |
| 288 const char* vendorName = device::UsbIds::GetVendorName(it->vendor_id); |
| 289 const char* productName = |
| 290 device::UsbIds::GetProductName(it->vendor_id, it->product_id); |
| 291 if (vendorName) { |
| 292 if (productName) { |
| 293 messages.push_back(l10n_util::GetStringFUTF16( |
| 294 IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_SERIAL, |
| 295 base::UTF8ToUTF16(vendorName), |
| 296 base::UTF8ToUTF16(productName), |
| 297 it->serial_number)); |
| 298 } else { |
| 299 messages.push_back(l10n_util::GetStringFUTF16( |
| 300 IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_PID_SERIAL, |
| 301 base::UTF8ToUTF16(vendorName), |
| 302 base::ASCIIToUTF16(base::StringPrintf("0x%04X", it->product_id)), |
| 303 it->serial_number)); |
| 304 } |
| 305 } else { |
| 306 messages.push_back(l10n_util::GetStringFUTF16( |
| 307 IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_VID_PID_SERIAL, |
| 308 base::ASCIIToUTF16(base::StringPrintf("0x%04X", it->vendor_id)), |
| 309 base::ASCIIToUTF16(base::StringPrintf("0x%04X", it->product_id)), |
| 310 it->serial_number)); |
| 311 } |
| 312 } |
| 313 return messages; |
| 277 } | 314 } |
| 278 | 315 |
| 279 void SavedDevicesService::Clear(const std::string& extension_id) { | 316 void SavedDevicesService::Clear(const std::string& extension_id) { |
| 280 DCHECK(thread_checker_.CalledOnValidThread()); | 317 DCHECK(thread_checker_.CalledOnValidThread()); |
| 281 ClearSavedDeviceEntries(ExtensionPrefs::Get(profile_), extension_id); | 318 ClearSavedDeviceEntries(ExtensionPrefs::Get(profile_), extension_id); |
| 282 std::map<std::string, SavedDevices*>::iterator it = | 319 std::map<std::string, SavedDevices*>::iterator it = |
| 283 extension_id_to_saved_devices_.find(extension_id); | 320 extension_id_to_saved_devices_.find(extension_id); |
| 284 if (it != extension_id_to_saved_devices_.end()) { | 321 if (it != extension_id_to_saved_devices_.end()) { |
| 285 delete it->second; | 322 delete it->second; |
| 286 extension_id_to_saved_devices_.erase(it); | 323 extension_id_to_saved_devices_.erase(it); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 311 std::map<std::string, SavedDevices*>::const_iterator it = | 348 std::map<std::string, SavedDevices*>::const_iterator it = |
| 312 extension_id_to_saved_devices_.find(extension_id); | 349 extension_id_to_saved_devices_.find(extension_id); |
| 313 if (it != extension_id_to_saved_devices_.end()) { | 350 if (it != extension_id_to_saved_devices_.end()) { |
| 314 return it->second; | 351 return it->second; |
| 315 } | 352 } |
| 316 | 353 |
| 317 return NULL; | 354 return NULL; |
| 318 } | 355 } |
| 319 | 356 |
| 320 } // namespace apps | 357 } // namespace apps |
| OLD | NEW |