forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepson_driver_matching.cc
51 lines (40 loc) · 1.75 KB
/
epson_driver_matching.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/printing/epson_driver_matching.h"
#include <algorithm>
#include "chromeos/printing/ppd_provider.h"
namespace chromeos {
bool CanUseEpsonGenericPPD(const PrinterSearchData& sd) {
// Needed to check if its an Epson printer.
if (sd.make_and_model.empty()) {
return false;
}
// Fail if this isn't an Epson printer.
// Note: Assumes make and model strings are already lowercase.
auto it = std::find_if(sd.make_and_model.begin(), sd.make_and_model.end(),
[](base::StringPiece emm) {
return emm.find("epson") != base::StringPiece::npos;
});
if (it == sd.make_and_model.end()) {
return false;
}
switch (sd.discovery_type) {
case PrinterSearchData::PrinterDiscoveryType::kManual:
// For manually discovered printers, supported_document_formats is
// retrieved via an ippGetAttributes query to the printer.
return base::ContainsValue(sd.supported_document_formats,
"application/octet-stream");
case PrinterSearchData::PrinterDiscoveryType::kUsb:
return base::ContainsValue(sd.usb_command_set, "ESC/P-R");
case PrinterSearchData::PrinterDiscoveryType::kZeroconf:
// For printers found through mDNS/DNS-SD discovery,
// supported_document_formats is retrieved via the Printer Description TXT
// Record(from the key 'pdl').
return base::ContainsValue(sd.supported_document_formats,
"application/vnd.epson.escpr");
default:
return false;
}
}
} // namespace chromeos