| 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/common/api/printer_provider/usb_printer_manifest_data.h" | 5 #include "extensions/common/api/printer_provider/usb_printer_manifest_data.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "device/usb/usb_device.h" | 8 #include "device/usb/usb_device.h" |
| 9 #include "device/usb/usb_device_filter.h" | 9 #include "device/usb/usb_device_filter.h" |
| 10 #include "extensions/common/api/extensions_manifest_types.h" | 10 #include "extensions/common/api/extensions_manifest_types.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 } | 21 } |
| 22 | 22 |
| 23 // static | 23 // static |
| 24 const UsbPrinterManifestData* UsbPrinterManifestData::Get( | 24 const UsbPrinterManifestData* UsbPrinterManifestData::Get( |
| 25 const Extension* extension) { | 25 const Extension* extension) { |
| 26 return static_cast<UsbPrinterManifestData*>( | 26 return static_cast<UsbPrinterManifestData*>( |
| 27 extension->GetManifestData(manifest_keys::kUsbPrinters)); | 27 extension->GetManifestData(manifest_keys::kUsbPrinters)); |
| 28 } | 28 } |
| 29 | 29 |
| 30 // static | 30 // static |
| 31 scoped_ptr<UsbPrinterManifestData> UsbPrinterManifestData::FromValue( | 31 std::unique_ptr<UsbPrinterManifestData> UsbPrinterManifestData::FromValue( |
| 32 const base::Value& value, | 32 const base::Value& value, |
| 33 base::string16* error) { | 33 base::string16* error) { |
| 34 scoped_ptr<api::extensions_manifest_types::UsbPrinters> usb_printers = | 34 std::unique_ptr<api::extensions_manifest_types::UsbPrinters> usb_printers = |
| 35 api::extensions_manifest_types::UsbPrinters::FromValue(value, error); | 35 api::extensions_manifest_types::UsbPrinters::FromValue(value, error); |
| 36 if (!usb_printers) { | 36 if (!usb_printers) { |
| 37 return nullptr; | 37 return nullptr; |
| 38 } | 38 } |
| 39 | 39 |
| 40 scoped_ptr<UsbPrinterManifestData> result(new UsbPrinterManifestData()); | 40 std::unique_ptr<UsbPrinterManifestData> result(new UsbPrinterManifestData()); |
| 41 for (const auto& input : usb_printers->filters) { | 41 for (const auto& input : usb_printers->filters) { |
| 42 UsbDeviceFilter output; | 42 UsbDeviceFilter output; |
| 43 output.SetVendorId(input.vendor_id); | 43 output.SetVendorId(input.vendor_id); |
| 44 if (input.product_id && input.interface_class) { | 44 if (input.product_id && input.interface_class) { |
| 45 *error = base::ASCIIToUTF16( | 45 *error = base::ASCIIToUTF16( |
| 46 "Only one of productId or interfaceClass may be specified."); | 46 "Only one of productId or interfaceClass may be specified."); |
| 47 return nullptr; | 47 return nullptr; |
| 48 } | 48 } |
| 49 if (input.product_id) { | 49 if (input.product_id) { |
| 50 output.SetProductId(*input.product_id); | 50 output.SetProductId(*input.product_id); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 62 } | 62 } |
| 63 return result; | 63 return result; |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool UsbPrinterManifestData::SupportsDevice( | 66 bool UsbPrinterManifestData::SupportsDevice( |
| 67 const scoped_refptr<device::UsbDevice>& device) const { | 67 const scoped_refptr<device::UsbDevice>& device) const { |
| 68 return UsbDeviceFilter::MatchesAny(device, filters_); | 68 return UsbDeviceFilter::MatchesAny(device, filters_); |
| 69 } | 69 } |
| 70 | 70 |
| 71 } // namespace extensions | 71 } // namespace extensions |
| OLD | NEW |