| 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/memory/ptr_util.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 8 #include "device/usb/usb_device.h" | 9 #include "device/usb/usb_device.h" |
| 9 #include "device/usb/usb_device_filter.h" | 10 #include "device/usb/usb_device_filter.h" |
| 10 #include "extensions/common/api/extensions_manifest_types.h" | 11 #include "extensions/common/api/extensions_manifest_types.h" |
| 11 #include "extensions/common/manifest_constants.h" | 12 #include "extensions/common/manifest_constants.h" |
| 12 | 13 |
| 13 using device::UsbDeviceFilter; | 14 using device::UsbDeviceFilter; |
| 14 | 15 |
| 15 namespace extensions { | 16 namespace extensions { |
| 16 | 17 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 30 // static | 31 // static |
| 31 std::unique_ptr<UsbPrinterManifestData> UsbPrinterManifestData::FromValue( | 32 std::unique_ptr<UsbPrinterManifestData> UsbPrinterManifestData::FromValue( |
| 32 const base::Value& value, | 33 const base::Value& value, |
| 33 base::string16* error) { | 34 base::string16* error) { |
| 34 std::unique_ptr<api::extensions_manifest_types::UsbPrinters> usb_printers = | 35 std::unique_ptr<api::extensions_manifest_types::UsbPrinters> usb_printers = |
| 35 api::extensions_manifest_types::UsbPrinters::FromValue(value, error); | 36 api::extensions_manifest_types::UsbPrinters::FromValue(value, error); |
| 36 if (!usb_printers) { | 37 if (!usb_printers) { |
| 37 return nullptr; | 38 return nullptr; |
| 38 } | 39 } |
| 39 | 40 |
| 40 std::unique_ptr<UsbPrinterManifestData> result(new UsbPrinterManifestData()); | 41 auto result = base::MakeUnique<UsbPrinterManifestData>(); |
| 41 for (const auto& input : usb_printers->filters) { | 42 for (const auto& input : usb_printers->filters) { |
| 42 UsbDeviceFilter output; | |
| 43 output.SetVendorId(input.vendor_id); | |
| 44 if (input.product_id && input.interface_class) { | 43 if (input.product_id && input.interface_class) { |
| 45 *error = base::ASCIIToUTF16( | 44 *error = base::ASCIIToUTF16( |
| 46 "Only one of productId or interfaceClass may be specified."); | 45 "Only one of productId or interfaceClass may be specified."); |
| 47 return nullptr; | 46 return nullptr; |
| 48 } | 47 } |
| 49 if (input.product_id) { | 48 |
| 50 output.SetProductId(*input.product_id); | 49 UsbDeviceFilter output; |
| 51 } | 50 output.vendor_id = input.vendor_id; |
| 51 |
| 52 if (input.product_id) |
| 53 output.product_id = *input.product_id; |
| 54 |
| 52 if (input.interface_class) { | 55 if (input.interface_class) { |
| 53 output.SetInterfaceClass(*input.interface_class); | 56 output.interface_class = *input.interface_class; |
| 54 if (input.interface_subclass) { | 57 if (input.interface_subclass) { |
| 55 output.SetInterfaceSubclass(*input.interface_subclass); | 58 output.interface_subclass = *input.interface_subclass; |
| 56 if (input.interface_protocol) { | 59 if (input.interface_protocol) |
| 57 output.SetInterfaceProtocol(*input.interface_protocol); | 60 output.interface_protocol = *input.interface_protocol; |
| 58 } | |
| 59 } | 61 } |
| 60 } | 62 } |
| 63 |
| 61 result->filters_.push_back(output); | 64 result->filters_.push_back(output); |
| 62 } | 65 } |
| 63 return result; | 66 return result; |
| 64 } | 67 } |
| 65 | 68 |
| 66 bool UsbPrinterManifestData::SupportsDevice( | 69 bool UsbPrinterManifestData::SupportsDevice( |
| 67 const scoped_refptr<device::UsbDevice>& device) const { | 70 const scoped_refptr<device::UsbDevice>& device) const { |
| 68 for (const auto& filter : filters_) { | 71 for (const auto& filter : filters_) { |
| 69 if (filter.Matches(device)) | 72 if (filter.Matches(device)) |
| 70 return true; | 73 return true; |
| 71 } | 74 } |
| 72 | 75 |
| 73 return false; | 76 return false; |
| 74 } | 77 } |
| 75 | 78 |
| 76 } // namespace extensions | 79 } // namespace extensions |
| OLD | NEW |