Commit 2a05b7cc authored by Daniel Hosseinian's avatar Daniel Hosseinian Committed by Commit Bot

Add PrintBackend::CreateInstanceForCloudPrint() to use CUPS PPD backend

Change the interface of PrintBackend::CreateInstanceImpl() to include a
flag indicating that the backend is to be used for Cloud Print. The new
interface PrintBackend::CreateInstanceForCloudPrint() passes |true| for
the flag, but usage of the flag will follow in a future CL.

The flag is necessary for runtime switching of the CUPS backend on
macOS. Because cloud print is still configured to rely on PPD
attributes, we want to still use the CUPS PPD backend over the CUPS IPP
one. CreateInstanceForCloudPrint(), which will only be built and called
on CUPS platforms, would ensure that the CUPS PPD backend is used.

Bug: 226176
Change-Id: Ic9c376af9992bb70516d1de39da3c9666cff145e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2089987
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: default avatarSean Kau <skau@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750854}
parent 21cbc653
...@@ -259,8 +259,8 @@ class PrinterWatcherCUPS ...@@ -259,8 +259,8 @@ class PrinterWatcherCUPS
// PrintSystem::PrinterWatcher implementation. // PrintSystem::PrinterWatcher implementation.
bool StartWatching(PrintSystem::PrinterWatcher::Delegate* delegate) override { bool StartWatching(PrintSystem::PrinterWatcher::Delegate* delegate) override {
scoped_refptr<printing::PrintBackend> print_backend( scoped_refptr<printing::PrintBackend> print_backend(
printing::PrintBackend::CreateInstance(nullptr, printing::PrintBackend::CreateInstanceForCloudPrint(
/*locale=*/std::string())); /*print_backend_settings=*/nullptr));
crash_keys::ScopedPrinterInfo crash_key( crash_keys::ScopedPrinterInfo crash_key(
print_backend->GetPrinterDriverInfo(printer_name_)); print_backend->GetPrinterDriverInfo(printer_name_));
if (delegate_) if (delegate_)
...@@ -463,8 +463,8 @@ void PrintSystemCUPS::AddPrintServer(const std::string& url) { ...@@ -463,8 +463,8 @@ void PrintSystemCUPS::AddPrintServer(const std::string& url) {
backend_settings.SetInteger(kCUPSEncryption, cups_encryption_); backend_settings.SetInteger(kCUPSEncryption, cups_encryption_);
PrintServerInfoCUPS print_server; PrintServerInfoCUPS print_server;
print_server.backend = printing::PrintBackend::CreateInstance( print_server.backend =
&backend_settings, /*locale=*/std::string()); printing::PrintBackend::CreateInstanceForCloudPrint(&backend_settings);
print_server.url = GURL(url.c_str()); print_server.url = GURL(url.c_str());
print_servers_.push_back(print_server); print_servers_.push_back(print_server);
......
...@@ -61,9 +61,20 @@ scoped_refptr<PrintBackend> PrintBackend::CreateInstance( ...@@ -61,9 +61,20 @@ scoped_refptr<PrintBackend> PrintBackend::CreateInstance(
const std::string& locale) { const std::string& locale) {
return g_print_backend_for_test return g_print_backend_for_test
? g_print_backend_for_test ? g_print_backend_for_test
: PrintBackend::CreateInstanceImpl(print_backend_settings, locale); : PrintBackend::CreateInstanceImpl(print_backend_settings, locale,
/*for_cloud_print=*/false);
} }
#if defined(USE_CUPS)
// static
scoped_refptr<PrintBackend> PrintBackend::CreateInstanceForCloudPrint(
const base::DictionaryValue* print_backend_settings) {
return PrintBackend::CreateInstanceImpl(print_backend_settings,
/*locale=*/std::string(),
/*for_cloud_print=*/true);
}
#endif // defined(USE_CUPS)
// static // static
void PrintBackend::SetPrintBackendForTesting(PrintBackend* backend) { void PrintBackend::SetPrintBackendForTesting(PrintBackend* backend) {
g_print_backend_for_test = backend; g_print_backend_for_test = backend;
......
...@@ -185,6 +185,15 @@ class PRINTING_EXPORT PrintBackend ...@@ -185,6 +185,15 @@ class PRINTING_EXPORT PrintBackend
const base::DictionaryValue* print_backend_settings, const base::DictionaryValue* print_backend_settings,
const std::string& locale); const std::string& locale);
#if defined(USE_CUPS)
// TODO(crbug.com/1062136): Remove this static function when Cloud Print is
// supposed to stop working. Follow up after Jan 1, 2021.
// Similar to CreateInstance(), but ensures that the CUPS PPD backend is used
// instead of the CUPS IPP backend.
static scoped_refptr<PrintBackend> CreateInstanceForCloudPrint(
const base::DictionaryValue* print_backend_settings);
#endif // defined(USE_CUPS)
// Test method to override the print backend for testing. Caller should // Test method to override the print backend for testing. Caller should
// retain ownership. // retain ownership.
static void SetPrintBackendForTesting(PrintBackend* print_backend); static void SetPrintBackendForTesting(PrintBackend* print_backend);
...@@ -197,7 +206,8 @@ class PRINTING_EXPORT PrintBackend ...@@ -197,7 +206,8 @@ class PRINTING_EXPORT PrintBackend
// Provide the actual backend for CreateInstance(). // Provide the actual backend for CreateInstance().
static scoped_refptr<PrintBackend> CreateInstanceImpl( static scoped_refptr<PrintBackend> CreateInstanceImpl(
const base::DictionaryValue* print_backend_settings, const base::DictionaryValue* print_backend_settings,
const std::string& locale); const std::string& locale,
bool for_cloud_print);
const std::string& locale() const { return locale_; } const std::string& locale() const { return locale_; }
......
...@@ -73,7 +73,8 @@ bool PrintBackendChromeOS::IsValidPrinter(const std::string& printer_name) { ...@@ -73,7 +73,8 @@ bool PrintBackendChromeOS::IsValidPrinter(const std::string& printer_name) {
// static // static
scoped_refptr<PrintBackend> PrintBackend::CreateInstanceImpl( scoped_refptr<PrintBackend> PrintBackend::CreateInstanceImpl(
const base::DictionaryValue* print_backend_settings, const base::DictionaryValue* print_backend_settings,
const std::string& locale) { const std::string& locale,
bool /*for_cloud_print*/) {
#if defined(USE_CUPS) #if defined(USE_CUPS)
return base::MakeRefCounted<PrintBackendCupsIpp>( return base::MakeRefCounted<PrintBackendCupsIpp>(
CreateConnection(print_backend_settings), locale); CreateConnection(print_backend_settings), locale);
......
...@@ -214,7 +214,8 @@ bool PrintBackendCUPS::IsValidPrinter(const std::string& printer_name) { ...@@ -214,7 +214,8 @@ bool PrintBackendCUPS::IsValidPrinter(const std::string& printer_name) {
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
scoped_refptr<PrintBackend> PrintBackend::CreateInstanceImpl( scoped_refptr<PrintBackend> PrintBackend::CreateInstanceImpl(
const base::DictionaryValue* print_backend_settings, const base::DictionaryValue* print_backend_settings,
const std::string& locale) { const std::string& locale,
bool for_cloud_print) {
std::string print_server_url_str, cups_blocking; std::string print_server_url_str, cups_blocking;
int encryption = HTTP_ENCRYPT_NEVER; int encryption = HTTP_ENCRYPT_NEVER;
if (print_backend_settings) { if (print_backend_settings) {
......
...@@ -57,7 +57,8 @@ class DummyPrintBackend : public PrintBackend { ...@@ -57,7 +57,8 @@ class DummyPrintBackend : public PrintBackend {
// static // static
scoped_refptr<PrintBackend> PrintBackend::CreateInstanceImpl( scoped_refptr<PrintBackend> PrintBackend::CreateInstanceImpl(
const base::DictionaryValue* print_backend_settings, const base::DictionaryValue* print_backend_settings,
const std::string& locale) { const std::string& locale,
bool /*for_cloud_print*/) {
return base::MakeRefCounted<DummyPrintBackend>(locale); return base::MakeRefCounted<DummyPrintBackend>(locale);
} }
......
...@@ -393,7 +393,8 @@ bool PrintBackendWin::IsValidPrinter(const std::string& printer_name) { ...@@ -393,7 +393,8 @@ bool PrintBackendWin::IsValidPrinter(const std::string& printer_name) {
// static // static
scoped_refptr<PrintBackend> PrintBackend::CreateInstanceImpl( scoped_refptr<PrintBackend> PrintBackend::CreateInstanceImpl(
const base::DictionaryValue* print_backend_settings, const base::DictionaryValue* print_backend_settings,
const std::string& locale) { const std::string& locale,
bool /*for_cloud_print*/) {
return base::MakeRefCounted<PrintBackendWin>(locale); return base::MakeRefCounted<PrintBackendWin>(locale);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment