print_backend_chromeos.cc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright 2016 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 "printing/backend/print_backend.h"
  5. #include "base/memory/ref_counted.h"
  6. #include "base/notreached.h"
  7. #include "base/values.h"
  8. #include "printing/mojom/print.mojom.h"
  9. #if defined(USE_CUPS)
  10. #include "printing/backend/cups_ipp_utils.h"
  11. #include "printing/backend/print_backend_cups_ipp.h"
  12. #endif // defined(USE_CUPS)
  13. namespace printing {
  14. // Provides either a stubbed out PrintBackend implementation or a CUPS IPP
  15. // implementation for use on ChromeOS.
  16. class PrintBackendChromeOS : public PrintBackend {
  17. public:
  18. PrintBackendChromeOS() = default;
  19. // PrintBackend implementation.
  20. mojom::ResultCode EnumeratePrinters(PrinterList& printer_list) override;
  21. mojom::ResultCode GetDefaultPrinterName(
  22. std::string& default_printer) override;
  23. mojom::ResultCode GetPrinterBasicInfo(
  24. const std::string& printer_name,
  25. PrinterBasicInfo* printer_info) override;
  26. mojom::ResultCode GetPrinterCapsAndDefaults(
  27. const std::string& printer_name,
  28. PrinterCapsAndDefaults* printer_info) override;
  29. mojom::ResultCode GetPrinterSemanticCapsAndDefaults(
  30. const std::string& printer_name,
  31. PrinterSemanticCapsAndDefaults* printer_info) override;
  32. std::string GetPrinterDriverInfo(const std::string& printer_name) override;
  33. bool IsValidPrinter(const std::string& printer_name) override;
  34. protected:
  35. ~PrintBackendChromeOS() override = default;
  36. };
  37. mojom::ResultCode PrintBackendChromeOS::EnumeratePrinters(
  38. PrinterList& printer_list) {
  39. return mojom::ResultCode::kSuccess;
  40. }
  41. mojom::ResultCode PrintBackendChromeOS::GetPrinterBasicInfo(
  42. const std::string& printer_name,
  43. PrinterBasicInfo* printer_info) {
  44. return mojom::ResultCode::kFailed;
  45. }
  46. mojom::ResultCode PrintBackendChromeOS::GetPrinterCapsAndDefaults(
  47. const std::string& printer_name,
  48. PrinterCapsAndDefaults* printer_info) {
  49. NOTREACHED();
  50. return mojom::ResultCode::kFailed;
  51. }
  52. mojom::ResultCode PrintBackendChromeOS::GetPrinterSemanticCapsAndDefaults(
  53. const std::string& printer_name,
  54. PrinterSemanticCapsAndDefaults* printer_info) {
  55. NOTREACHED();
  56. return mojom::ResultCode::kFailed;
  57. }
  58. std::string PrintBackendChromeOS::GetPrinterDriverInfo(
  59. const std::string& printer_name) {
  60. NOTREACHED();
  61. return std::string();
  62. }
  63. mojom::ResultCode PrintBackendChromeOS::GetDefaultPrinterName(
  64. std::string& default_printer) {
  65. default_printer = std::string();
  66. return mojom::ResultCode::kSuccess;
  67. }
  68. bool PrintBackendChromeOS::IsValidPrinter(const std::string& printer_name) {
  69. NOTREACHED();
  70. return true;
  71. }
  72. // static
  73. scoped_refptr<PrintBackend> PrintBackend::CreateInstanceImpl(
  74. const base::Value::Dict* print_backend_settings,
  75. const std::string& /*locale*/) {
  76. #if defined(USE_CUPS)
  77. return base::MakeRefCounted<PrintBackendCupsIpp>(
  78. CreateConnection(print_backend_settings));
  79. #else
  80. return base::MakeRefCounted<PrintBackendChromeOS>();
  81. #endif // defined(USE_CUPS)
  82. }
  83. } // namespace printing