OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "extensions/common/api/printer_provider/usb_printer_manifest_data.h" |
| 6 |
| 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "device/usb/usb_device_filter.h" |
| 9 #include "extensions/common/api/extensions_manifest_types.h" |
| 10 #include "extensions/common/manifest_constants.h" |
| 11 |
| 12 namespace extensions { |
| 13 |
| 14 UsbPrinterManifestData::UsbPrinterManifestData() { |
| 15 } |
| 16 |
| 17 UsbPrinterManifestData::~UsbPrinterManifestData() { |
| 18 } |
| 19 |
| 20 // static |
| 21 const UsbPrinterManifestData* UsbPrinterManifestData::Get( |
| 22 const Extension* extension) { |
| 23 return static_cast<UsbPrinterManifestData*>( |
| 24 extension->GetManifestData(manifest_keys::kUsbPrinters)); |
| 25 } |
| 26 |
| 27 // static |
| 28 scoped_ptr<UsbPrinterManifestData> UsbPrinterManifestData::FromValue( |
| 29 const base::Value& value, |
| 30 base::string16* error) { |
| 31 scoped_ptr<core_api::extensions_manifest_types::UsbPrinters> usb_printers = |
| 32 core_api::extensions_manifest_types::UsbPrinters::FromValue(value, error); |
| 33 if (!usb_printers) { |
| 34 return nullptr; |
| 35 } |
| 36 |
| 37 scoped_ptr<UsbPrinterManifestData> result(new UsbPrinterManifestData()); |
| 38 for (const auto& input : usb_printers->filters) { |
| 39 DCHECK(input.get()); |
| 40 device::UsbDeviceFilter output; |
| 41 output.SetVendorId(input->vendor_id); |
| 42 if (input->product_id && input->interface_class) { |
| 43 *error = base::ASCIIToUTF16( |
| 44 "Only one of productId or interfaceClass may be specified."); |
| 45 return nullptr; |
| 46 } |
| 47 if (input->product_id) { |
| 48 output.SetProductId(*input->product_id); |
| 49 } |
| 50 if (input->interface_class) { |
| 51 output.SetInterfaceClass(*input->interface_class); |
| 52 if (input->interface_subclass) { |
| 53 output.SetInterfaceSubclass(*input->interface_subclass); |
| 54 if (input->interface_protocol) { |
| 55 output.SetInterfaceProtocol(*input->interface_protocol); |
| 56 } |
| 57 } |
| 58 } |
| 59 result->filters_.push_back(output); |
| 60 } |
| 61 return result.Pass(); |
| 62 } |
| 63 |
| 64 } // namespace extensions |
OLD | NEW |