Skip to content

Commit

Permalink
Remove PrintBackend::GetPrinterCapsAndDefaults() from most platforms
Browse files Browse the repository at this point in the history
GetPrinterCapsAndDefaults() has no callers. Save the implementation in
PrintBackendWin because that one looks useful.

The PrintBackendCUPS version does have an internal caller. Simplify this
version and rename it to GetPrinterCapabilities().

Change-Id: I5475cfe01d1c5994e3937a250d4349b11c356c4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4368803
Reviewed-by: Alan Screen <awscreen@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1122029}
  • Loading branch information
leizleiz authored and Chromium LUCI CQ committed Mar 25, 2023
1 parent 5748e68 commit ef84cce
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 53 deletions.
3 changes: 3 additions & 0 deletions printing/backend/print_backend.h
Expand Up @@ -277,10 +277,13 @@ class COMPONENT_EXPORT(PRINT_BACKEND) PrintBackend
const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) = 0;

#if BUILDFLAG(IS_WIN)
// Gets the capabilities and defaults for a specific printer.
// TODO(crbug.com/1008222): Evaluate if this code is useful and delete if not.
virtual mojom::ResultCode GetPrinterCapsAndDefaults(
const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) = 0;
#endif

// Gets the information about driver for a specific printer.
virtual std::string GetPrinterDriverInfo(const std::string& printer_name) = 0;
Expand Down
10 changes: 0 additions & 10 deletions printing/backend/print_backend_chromeos.cc
Expand Up @@ -30,9 +30,6 @@ class PrintBackendChromeOS : public PrintBackend {
mojom::ResultCode GetPrinterBasicInfo(
const std::string& printer_name,
PrinterBasicInfo* printer_info) override;
mojom::ResultCode GetPrinterCapsAndDefaults(
const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) override;
mojom::ResultCode GetPrinterSemanticCapsAndDefaults(
const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) override;
Expand All @@ -54,13 +51,6 @@ mojom::ResultCode PrintBackendChromeOS::GetPrinterBasicInfo(
return mojom::ResultCode::kFailed;
}

mojom::ResultCode PrintBackendChromeOS::GetPrinterCapsAndDefaults(
const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) {
NOTREACHED();
return mojom::ResultCode::kFailed;
}

mojom::ResultCode PrintBackendChromeOS::GetPrinterSemanticCapsAndDefaults(
const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) {
Expand Down
36 changes: 12 additions & 24 deletions printing/backend/print_backend_cups.cc
Expand Up @@ -240,51 +240,39 @@ mojom::ResultCode PrintBackendCUPS::GetPrinterBasicInfo(
mojom::ResultCode PrintBackendCUPS::GetPrinterSemanticCapsAndDefaults(
const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) {
PrinterCapsAndDefaults info;
if (!IsValidPrinter(printer_name))
return mojom::ResultCode::kFailed;

mojom::ResultCode result_code =
GetPrinterCapsAndDefaults(printer_name, &info);
if (result_code != mojom::ResultCode::kSuccess)
return result_code;
std::string printer_capabilities = GetPrinterCapabilities(printer_name);
if (printer_capabilities.empty()) {
return mojom::ResultCode::kFailed;
}

ScopedDestination dest = GetNamedDest(printer_name);
return ParsePpdCapabilities(dest.get(), locale_, info.printer_capabilities,
return ParsePpdCapabilities(dest.get(), locale_, printer_capabilities,
printer_info)
? mojom::ResultCode::kSuccess
: mojom::ResultCode::kFailed;
}

mojom::ResultCode PrintBackendCUPS::GetPrinterCapsAndDefaults(
const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) {
DCHECK(printer_info);

std::string PrintBackendCUPS::GetPrinterCapabilities(
const std::string& printer_name) {
VLOG(1) << "CUPS: Getting caps and defaults, printer name: " << printer_name;

base::FilePath ppd_path(GetPPD(printer_name.c_str()));
// In some cases CUPS failed to get ppd file.
if (ppd_path.empty()) {
LOG(ERROR) << "CUPS: Failed to get PPD, printer name: " << printer_name;
return mojom::ResultCode::kFailed;
return std::string();
}

std::string content;
bool res = base::ReadFileToString(ppd_path, &content);
if (!base::ReadFileToString(ppd_path, &content)) {
content.clear();
}

base::DeleteFile(ppd_path);

if (!res)
return mojom::ResultCode::kFailed;

printer_info->printer_capabilities.swap(content);
printer_info->caps_mime_type = "application/pagemaker";
// In CUPS, printer defaults is a part of PPD file. Nothing to upload here.
printer_info->printer_defaults.clear();
printer_info->defaults_mime_type.clear();

return mojom::ResultCode::kSuccess;
return content;
}

std::string PrintBackendCUPS::GetPrinterDriverInfo(
Expand Down
5 changes: 2 additions & 3 deletions printing/backend/print_backend_cups.h
Expand Up @@ -51,12 +51,11 @@ class PrintBackendCUPS : public PrintBackend {
mojom::ResultCode GetPrinterSemanticCapsAndDefaults(
const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) override;
mojom::ResultCode GetPrinterCapsAndDefaults(
const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) override;
std::string GetPrinterDriverInfo(const std::string& printer_name) override;
bool IsValidPrinter(const std::string& printer_name) override;

std::string GetPrinterCapabilities(const std::string& printer_name);

// The following functions are wrappers around corresponding CUPS functions.
// <functions>2() are called when print server is specified, and plain version
// in another case. There is an issue specifying CUPS_HTTP_DEFAULT in the
Expand Down
7 changes: 0 additions & 7 deletions printing/backend/print_backend_cups_ipp.cc
Expand Up @@ -87,13 +87,6 @@ mojom::ResultCode PrintBackendCupsIpp::GetPrinterBasicInfo(
: mojom::ResultCode::kFailed;
}

mojom::ResultCode PrintBackendCupsIpp::GetPrinterCapsAndDefaults(
const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) {
NOTREACHED();
return mojom::ResultCode::kFailed;
}

mojom::ResultCode PrintBackendCupsIpp::GetPrinterSemanticCapsAndDefaults(
const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) {
Expand Down
3 changes: 0 additions & 3 deletions printing/backend/print_backend_cups_ipp.h
Expand Up @@ -28,9 +28,6 @@ class PrintBackendCupsIpp : public PrintBackend {
mojom::ResultCode GetPrinterBasicInfo(
const std::string& printer_name,
PrinterBasicInfo* printer_info) override;
mojom::ResultCode GetPrinterCapsAndDefaults(
const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) override;
mojom::ResultCode GetPrinterSemanticCapsAndDefaults(
const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) override;
Expand Down
6 changes: 0 additions & 6 deletions printing/backend/print_backend_dummy.cc
Expand Up @@ -41,12 +41,6 @@ class DummyPrintBackend : public PrintBackend {
return mojom::ResultCode::kFailed;
}

mojom::ResultCode GetPrinterCapsAndDefaults(
const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) override {
return mojom::ResultCode::kFailed;
}

std::string GetPrinterDriverInfo(const std::string& printer_name) override {
return std::string();
}
Expand Down
4 changes: 4 additions & 0 deletions printing/backend/test_print_backend.cc
Expand Up @@ -51,10 +51,12 @@ mojom::ResultCode ReportErrorNoDevice(const base::Location& from_here) {
return mojom::ResultCode::kFailed;
}

#if BUILDFLAG(IS_WIN)
mojom::ResultCode ReportErrorNotImplemented(const base::Location& from_here) {
DLOG(ERROR) << from_here.ToString() << " failed, method not implemented";
return mojom::ResultCode::kFailed;
}
#endif // BUILDFLAG(IS_WIN)

} // namespace

Expand Down Expand Up @@ -124,11 +126,13 @@ mojom::ResultCode TestPrintBackend::GetPrinterSemanticCapsAndDefaults(
return mojom::ResultCode::kSuccess;
}

#if BUILDFLAG(IS_WIN)
mojom::ResultCode TestPrintBackend::GetPrinterCapsAndDefaults(
const std::string& printer_name,
PrinterCapsAndDefaults* printer_caps) {
return ReportErrorNotImplemented(FROM_HERE);
}
#endif // BUILDFLAG(IS_WIN)

std::string TestPrintBackend::GetPrinterDriverInfo(
const std::string& printer_name) {
Expand Down
2 changes: 2 additions & 0 deletions printing/backend/test_print_backend.h
Expand Up @@ -35,9 +35,11 @@ class TestPrintBackend : public PrintBackend {
mojom::ResultCode GetPrinterSemanticCapsAndDefaults(
const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) override;
#if BUILDFLAG(IS_WIN)
mojom::ResultCode GetPrinterCapsAndDefaults(
const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) override;
#endif
std::string GetPrinterDriverInfo(const std::string& printer_name) override;
bool IsValidPrinter(const std::string& printer_name) override;
#if BUILDFLAG(IS_WIN)
Expand Down

0 comments on commit ef84cce

Please sign in to comment.