cups_helper.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright (c) 2012 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. #ifndef PRINTING_BACKEND_CUPS_HELPER_H_
  5. #define PRINTING_BACKEND_CUPS_HELPER_H_
  6. #include <cups/cups.h>
  7. #include "base/component_export.h"
  8. #include "base/memory/raw_ptr.h"
  9. #include "base/strings/string_piece.h"
  10. class GURL;
  11. // These are helper functions for dealing with CUPS.
  12. namespace printing {
  13. struct PrinterSemanticCapsAndDefaults;
  14. // Time willing to wait for individual CUPS calls to complete, such as
  15. // establishing a new connection or enumerating list of printers.
  16. constexpr int kCupsTimeoutMs = 3000;
  17. // Exclude fax and scanner devices when enumerating printers.
  18. // Also exclude discovered printers that have not been added locally.
  19. // On macOS, AirPrint destinations show up even if they're not added to
  20. // the system, and their capabilities cannot be read in that situation.
  21. // (crbug.com/1027834)
  22. constexpr cups_ptype_t kDestinationsFilterMask =
  23. CUPS_PRINTER_FAX | CUPS_PRINTER_SCANNER | CUPS_PRINTER_DISCOVERED;
  24. // Helper wrapper around http_t structure, with connection and cleanup
  25. // functionality.
  26. class COMPONENT_EXPORT(PRINT_BACKEND) HttpConnectionCUPS {
  27. public:
  28. HttpConnectionCUPS(const GURL& print_server_url,
  29. http_encryption_t encryption,
  30. bool blocking);
  31. ~HttpConnectionCUPS();
  32. http_t* http();
  33. private:
  34. raw_ptr<http_t> http_;
  35. };
  36. // Helper function to parse and convert PPD capabilitites to
  37. // semantic options.
  38. COMPONENT_EXPORT(PRINT_BACKEND)
  39. bool ParsePpdCapabilities(cups_dest_t* dest,
  40. base::StringPiece locale,
  41. base::StringPiece printer_capabilities,
  42. PrinterSemanticCapsAndDefaults* printer_info);
  43. } // namespace printing
  44. #endif // PRINTING_BACKEND_CUPS_HELPER_H_