0

[Printing] Add runtime checks for cupsFindDest functions

Check to see if cupsFindDestSupported() and cupsFindDestDefault() are
available at runtime, as these may not be available in distros with
older CUPS releases.

Bug: 359789132
Change-Id: I063ced62499f135f800b43f564b663400980e3ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5855339
Reviewed-by: Thomas Anderson <thomasanderson@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1354117}
This commit is contained in:
Lei Zhang
2024-09-11 19:13:13 +00:00
committed by Chromium LUCI CQ
parent 7ac5835457
commit b3b3d0e2ce
3 changed files with 12 additions and 4 deletions

@ -22,6 +22,7 @@
#include "printing/backend/cups_connection.h"
#include "printing/backend/cups_ipp_constants.h"
#include "printing/backend/cups_ipp_helper.h"
#include "printing/backend/cups_weak_functions.h"
#include "printing/backend/print_backend.h"
#include "printing/backend/print_backend_consts.h"
#include "printing/backend/print_backend_utils.h"

@ -12,5 +12,7 @@
WEAK_CUPS_FN(httpConnect2);
// This may be removed when Amazon Linux 2 reaches EOL (30 Jun 2025).
// These may be removed when Amazon Linux 2 reaches EOL (30 Jun 2025).
WEAK_CUPS_FN(cupsFindDestDefault);
WEAK_CUPS_FN(cupsFindDestSupported);
WEAK_CUPS_FN(ippValidateAttributes);

@ -63,6 +63,13 @@ int CaptureCupsDestCallback(void* data, unsigned flags, cups_dest_t* dest) {
return 1; // Keep going.
}
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_MAC)
// This may be removed when Amazon Linux 2 reaches EOL (30 Jun 2025).
bool AreNewerCupsFunctionsAvailable() {
return cupsFindDestDefault && cupsFindDestSupported && ippValidateAttributes;
}
#endif
} // namespace
PrintBackendCUPS::PrintBackendCUPS(const GURL& print_server_url,
@ -285,9 +292,7 @@ bool PrintBackendCUPS::IsValidPrinter(const std::string& printer_name) {
scoped_refptr<PrintBackend> PrintBackend::CreateInstanceImpl(
const std::string& locale) {
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_MAC)
// The `ippValidateAttributes` check may be removed when Amazon Linux 2
// reaches EOL (30 Jun 2025).
if (ippValidateAttributes &&
if (AreNewerCupsFunctionsAvailable() &&
base::FeatureList::IsEnabled(features::kCupsIppPrintingBackend)) {
return base::MakeRefCounted<PrintBackendCupsIpp>(CupsConnection::Create());
}