Skip to content

Commit c3213f8

Browse files
Sean KauCommit Bot
Sean Kau
authored and
Commit Bot
committed
Remove calls to deprecated CUPS API
httpConnect2 became preferred in CUPS 1.7. We expect that all supported clients are now past this CUPS version. Bug: 1020356 Change-Id: Id97a50beac7ac1d6b7f6ecd10a8e8c6303b3d4e2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2043031 Auto-Submit: Sean Kau <skau@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Daniel Hosseinian <dhoss@chromium.org> Cr-Commit-Position: refs/heads/master@{#740195}
1 parent 2314826 commit c3213f8

File tree

5 files changed

+22
-32
lines changed

5 files changed

+22
-32
lines changed

chrome/service/cloud_print/print_system_cups.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,7 @@ int PrintSystemCUPS::PrintFile(const GURL& url,
726726
if (url.is_empty())
727727
return cupsPrintFile(name, filename, title, num_options, options);
728728

729-
printing::HttpConnectionCUPS http(url, encryption);
730-
http.SetBlocking(false);
729+
printing::HttpConnectionCUPS http(url, encryption, /*blocking=*/false);
731730
return cupsPrintFile2(http.http(), name, filename, title, num_options,
732731
options);
733732
}
@@ -743,8 +742,7 @@ int PrintSystemCUPS::GetJobs(cups_job_t** jobs,
743742
if (url.is_empty())
744743
return cupsGetJobs(jobs, name, myjobs, whichjobs);
745744

746-
printing::HttpConnectionCUPS http(url, encryption);
747-
http.SetBlocking(false);
745+
printing::HttpConnectionCUPS http(url, encryption, /*blocking=*/false);
748746
return cupsGetJobs2(http.http(), jobs, name, myjobs, whichjobs);
749747
}
750748

printing/BUILD.gn

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -165,24 +165,15 @@ component("printing") {
165165
if (is_linux) {
166166
cflags += [
167167
# CUPS 1.6 deprecated the PPD APIs, but we will stay with this
168-
# API for now as supported Linux and Mac OS'es are still using
169-
# older versions of CUPS. More info: crbug.com/226176
168+
# API for now as the suitability of the replacement is unclear.
169+
# More info: crbug.com/226176
170170
"-Wno-deprecated-declarations",
171-
# CUPS 1.7 deprecates httpConnectEncrypt(), see the mac section
172-
# below.
173171
]
174172
}
175173

176174
if (is_mac) {
177-
# The 10.9 SDK includes cups 1.7, which deprecates
178-
# httpConnectEncrypt() in favor of httpConnect2(). hhttpConnect2()
179-
# is new in 1.7, so it doesn't exist on OS X 10.6-10.8 and we
180-
# can't use it until 10.9 is our minimum system version.
181-
# (cups_version isn't reliable on OS X, so key the check off of
182-
# mac_sdk).
183-
# With a 10.8 deployment target, several other APIs are deprecated.
184-
# We're still on CUPS 1.4 until Linux no longer needs to support it, see
185-
# comment above.
175+
# CUPS 1.6 deprecated the PPD APIs. We need to evaluate the
176+
# effect of migrating Mac. More info: crbug.com/226176
186177
cflags += [ "-Wno-deprecated-declarations" ]
187178
}
188179

printing/backend/cups_helper.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "base/strings/string_number_conversions.h"
1818
#include "base/strings/string_split.h"
1919
#include "base/strings/string_util.h"
20+
#include "base/time/time.h"
2021
#include "base/values.h"
2122
#include "printing/backend/print_backend.h"
2223
#include "printing/backend/print_backend_consts.h"
@@ -31,6 +32,10 @@ namespace printing {
3132
// This section contains helper code for PPD parsing for semantic capabilities.
3233
namespace {
3334

35+
// Timeout for establishing a CUPS connection. It is expected that cupsd is
36+
// able to start and respond on all systems within this duration.
37+
constexpr base::TimeDelta kCupsTimeout = base::TimeDelta::FromSeconds(5);
38+
3439
constexpr char kColorDevice[] = "ColorDevice";
3540
constexpr char kColorModel[] = "ColorModel";
3641
constexpr char kColorMode[] = "ColorMode";
@@ -524,7 +529,8 @@ const int kDefaultIPPServerPort = 631;
524529
// Helper wrapper around http_t structure, with connection and cleanup
525530
// functionality.
526531
HttpConnectionCUPS::HttpConnectionCUPS(const GURL& print_server_url,
527-
http_encryption_t encryption)
532+
http_encryption_t encryption,
533+
bool blocking)
528534
: http_(nullptr) {
529535
// If we have an empty url, use default print server.
530536
if (print_server_url.is_empty())
@@ -533,8 +539,11 @@ HttpConnectionCUPS::HttpConnectionCUPS(const GURL& print_server_url,
533539
int port = print_server_url.IntPort();
534540
if (port == url::PORT_UNSPECIFIED)
535541
port = kDefaultIPPServerPort;
542+
http_ =
543+
httpConnect2(print_server_url.host().c_str(), port, /*addrlist=*/nullptr,
544+
AF_UNSPEC, encryption, blocking ? 1 : 0,
545+
kCupsTimeout.InMilliseconds(), /*cancel=*/nullptr);
536546

537-
http_ = httpConnectEncrypt(print_server_url.host().c_str(), port, encryption);
538547
if (!http_) {
539548
LOG(ERROR) << "CP_CUPS: Failed connecting to print server: "
540549
<< print_server_url;
@@ -546,10 +555,6 @@ HttpConnectionCUPS::~HttpConnectionCUPS() {
546555
httpClose(http_);
547556
}
548557

549-
void HttpConnectionCUPS::SetBlocking(bool blocking) {
550-
httpBlocking(http_, blocking ? 1 : 0);
551-
}
552-
553558
http_t* HttpConnectionCUPS::http() {
554559
return http_;
555560
}

printing/backend/cups_helper.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ struct PrinterSemanticCapsAndDefaults;
2323
class PRINTING_EXPORT HttpConnectionCUPS {
2424
public:
2525
HttpConnectionCUPS(const GURL& print_server_url,
26-
http_encryption_t encryption);
26+
http_encryption_t encryption,
27+
bool blocking);
2728
~HttpConnectionCUPS();
2829

29-
void SetBlocking(bool blocking);
30-
3130
http_t* http();
3231

3332
private:

printing/backend/print_backend_cups.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@ int PrintBackendCUPS::GetDests(cups_dest_t** dests) {
238238
if (print_server_url_.is_empty())
239239
return cupsGetDests2(CUPS_HTTP_DEFAULT, dests);
240240

241-
HttpConnectionCUPS http(print_server_url_, cups_encryption_);
242-
http.SetBlocking(blocking_);
241+
HttpConnectionCUPS http(print_server_url_, cups_encryption_, blocking_);
243242

244243
// This call must be made in the same scope as |http| because its destructor
245244
// closes the connection.
@@ -265,8 +264,7 @@ base::FilePath PrintBackendCUPS::GetPPD(const char* name) {
265264
// connection will timeout after 10 seconds of no data period. And it will
266265
// return the same way as if data was completely and successfully
267266
// downloaded.
268-
HttpConnectionCUPS http(print_server_url_, cups_encryption_);
269-
http.SetBlocking(blocking_);
267+
HttpConnectionCUPS http(print_server_url_, cups_encryption_, blocking_);
270268
ppd_file_path = cupsGetPPD2(http.http(), name);
271269
// Check if the get full PPD, since non-blocking call may simply return
272270
// normally after timeout expired.
@@ -302,8 +300,7 @@ PrintBackendCUPS::ScopedDestination PrintBackendCUPS::GetNamedDest(
302300
// Use default (local) print server.
303301
dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, printer_name.c_str(), nullptr);
304302
} else {
305-
HttpConnectionCUPS http(print_server_url_, cups_encryption_);
306-
http.SetBlocking(blocking_);
303+
HttpConnectionCUPS http(print_server_url_, cups_encryption_, blocking_);
307304
dest = cupsGetNamedDest(http.http(), printer_name.c_str(), nullptr);
308305
}
309306
return ScopedDestination(dest);

0 commit comments

Comments
 (0)