epson_driver_matching.cc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2019 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. #include "chromeos/printing/epson_driver_matching.h"
  5. #include <algorithm>
  6. #include "base/strings/string_util.h"
  7. #include "chromeos/printing/ppd_provider.h"
  8. namespace chromeos {
  9. bool CanUseEpsonGenericPPD(const PrinterSearchData& sd) {
  10. // Only matches USB printers.
  11. if (sd.discovery_type != PrinterSearchData::PrinterDiscoveryType::kUsb) {
  12. return false;
  13. }
  14. // Needed to check if its an Epson printer.
  15. if (sd.make_and_model.empty()) {
  16. return false;
  17. }
  18. // Fail if this isn't an Epson printer.
  19. // Note: Assumes make and model strings are already lowercase.
  20. auto it = std::find_if(sd.make_and_model.begin(), sd.make_and_model.end(),
  21. [](base::StringPiece emm) {
  22. return emm.find("epson") != base::StringPiece::npos;
  23. });
  24. if (it == sd.make_and_model.end()) {
  25. return false;
  26. }
  27. // The command set is retrieved from the 'CMD' field of the printer's IEEE
  28. // 1284 Device ID.
  29. for (base::StringPiece format : sd.printer_id.command_set()) {
  30. if (base::StartsWith(format, "ESCPR")) {
  31. return true;
  32. }
  33. }
  34. return false;
  35. }
  36. } // namespace chromeos