Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: extensions/common/api/printer_provider/usb_printer_manifest_data.cc

Issue 1153173002: Include USB printers in printer list as "provisional" devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed more comments. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/common/api/printer_provider/usb_printer_manifest_data.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_filter.h" 9 #include "device/usb/usb_device_filter.h"
9 #include "extensions/common/api/extensions_manifest_types.h" 10 #include "extensions/common/api/extensions_manifest_types.h"
10 #include "extensions/common/manifest_constants.h" 11 #include "extensions/common/manifest_constants.h"
11 12
13 using device::UsbDeviceFilter;
14
12 namespace extensions { 15 namespace extensions {
13 16
14 UsbPrinterManifestData::UsbPrinterManifestData() { 17 UsbPrinterManifestData::UsbPrinterManifestData() {
15 } 18 }
16 19
17 UsbPrinterManifestData::~UsbPrinterManifestData() { 20 UsbPrinterManifestData::~UsbPrinterManifestData() {
18 } 21 }
19 22
20 // static 23 // static
21 const UsbPrinterManifestData* UsbPrinterManifestData::Get( 24 const UsbPrinterManifestData* UsbPrinterManifestData::Get(
22 const Extension* extension) { 25 const Extension* extension) {
23 return static_cast<UsbPrinterManifestData*>( 26 return static_cast<UsbPrinterManifestData*>(
24 extension->GetManifestData(manifest_keys::kUsbPrinters)); 27 extension->GetManifestData(manifest_keys::kUsbPrinters));
25 } 28 }
26 29
27 // static 30 // static
28 scoped_ptr<UsbPrinterManifestData> UsbPrinterManifestData::FromValue( 31 scoped_ptr<UsbPrinterManifestData> UsbPrinterManifestData::FromValue(
29 const base::Value& value, 32 const base::Value& value,
30 base::string16* error) { 33 base::string16* error) {
31 scoped_ptr<core_api::extensions_manifest_types::UsbPrinters> usb_printers = 34 scoped_ptr<core_api::extensions_manifest_types::UsbPrinters> usb_printers =
32 core_api::extensions_manifest_types::UsbPrinters::FromValue(value, error); 35 core_api::extensions_manifest_types::UsbPrinters::FromValue(value, error);
33 if (!usb_printers) { 36 if (!usb_printers) {
34 return nullptr; 37 return nullptr;
35 } 38 }
36 39
37 scoped_ptr<UsbPrinterManifestData> result(new UsbPrinterManifestData()); 40 scoped_ptr<UsbPrinterManifestData> result(new UsbPrinterManifestData());
38 for (const auto& input : usb_printers->filters) { 41 for (const auto& input : usb_printers->filters) {
39 DCHECK(input.get()); 42 DCHECK(input.get());
40 device::UsbDeviceFilter output; 43 UsbDeviceFilter output;
41 output.SetVendorId(input->vendor_id); 44 output.SetVendorId(input->vendor_id);
42 if (input->product_id && input->interface_class) { 45 if (input->product_id && input->interface_class) {
43 *error = base::ASCIIToUTF16( 46 *error = base::ASCIIToUTF16(
44 "Only one of productId or interfaceClass may be specified."); 47 "Only one of productId or interfaceClass may be specified.");
45 return nullptr; 48 return nullptr;
46 } 49 }
47 if (input->product_id) { 50 if (input->product_id) {
48 output.SetProductId(*input->product_id); 51 output.SetProductId(*input->product_id);
49 } 52 }
50 if (input->interface_class) { 53 if (input->interface_class) {
51 output.SetInterfaceClass(*input->interface_class); 54 output.SetInterfaceClass(*input->interface_class);
52 if (input->interface_subclass) { 55 if (input->interface_subclass) {
53 output.SetInterfaceSubclass(*input->interface_subclass); 56 output.SetInterfaceSubclass(*input->interface_subclass);
54 if (input->interface_protocol) { 57 if (input->interface_protocol) {
55 output.SetInterfaceProtocol(*input->interface_protocol); 58 output.SetInterfaceProtocol(*input->interface_protocol);
56 } 59 }
57 } 60 }
58 } 61 }
59 result->filters_.push_back(output); 62 result->filters_.push_back(output);
60 } 63 }
61 return result.Pass(); 64 return result.Pass();
62 } 65 }
63 66
67 bool UsbPrinterManifestData::SupportsDevice(
68 const scoped_refptr<device::UsbDevice>& device) const {
69 return UsbDeviceFilter::MatchesAny(device, filters_);
70 }
71
64 } // namespace extensions 72 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/api/printer_provider/usb_printer_manifest_data.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698