Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / extensions / common / api / printer_provider / usb_printer_manifest_data.cc
blob79c1eed27853dfbcdbedf509860aacfe61c01cc7
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.
5 #include "extensions/common/api/printer_provider/usb_printer_manifest_data.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "device/usb/usb_device.h"
9 #include "device/usb/usb_device_filter.h"
10 #include "extensions/common/api/extensions_manifest_types.h"
11 #include "extensions/common/manifest_constants.h"
13 using device::UsbDeviceFilter;
15 namespace extensions {
17 UsbPrinterManifestData::UsbPrinterManifestData() {
20 UsbPrinterManifestData::~UsbPrinterManifestData() {
23 // static
24 const UsbPrinterManifestData* UsbPrinterManifestData::Get(
25 const Extension* extension) {
26 return static_cast<UsbPrinterManifestData*>(
27 extension->GetManifestData(manifest_keys::kUsbPrinters));
30 // static
31 scoped_ptr<UsbPrinterManifestData> UsbPrinterManifestData::FromValue(
32 const base::Value& value,
33 base::string16* error) {
34 scoped_ptr<api::extensions_manifest_types::UsbPrinters> usb_printers =
35 api::extensions_manifest_types::UsbPrinters::FromValue(value, error);
36 if (!usb_printers) {
37 return nullptr;
40 scoped_ptr<UsbPrinterManifestData> result(new UsbPrinterManifestData());
41 for (const auto& input : usb_printers->filters) {
42 DCHECK(input.get());
43 UsbDeviceFilter output;
44 output.SetVendorId(input->vendor_id);
45 if (input->product_id && input->interface_class) {
46 *error = base::ASCIIToUTF16(
47 "Only one of productId or interfaceClass may be specified.");
48 return nullptr;
50 if (input->product_id) {
51 output.SetProductId(*input->product_id);
53 if (input->interface_class) {
54 output.SetInterfaceClass(*input->interface_class);
55 if (input->interface_subclass) {
56 output.SetInterfaceSubclass(*input->interface_subclass);
57 if (input->interface_protocol) {
58 output.SetInterfaceProtocol(*input->interface_protocol);
62 result->filters_.push_back(output);
64 return result.Pass();
67 bool UsbPrinterManifestData::SupportsDevice(
68 const scoped_refptr<device::UsbDevice>& device) const {
69 return UsbDeviceFilter::MatchesAny(device, filters_);
72 } // namespace extensions