Skip to content

Commit

Permalink
Making CUPS calls non-blocking.
Browse files Browse the repository at this point in the history
BUG=none
TEST=Verify proxy is not blocked on CUPS calls.

Review URL: http://codereview.chromium.org/5846001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69357 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
gene@google.com committed Dec 16, 2010
1 parent cded31b commit 9c6ca60
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
9 changes: 7 additions & 2 deletions chrome/service/cloud_print/print_system_cups.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
#include "googleurl/src/gurl.h"
#include "printing/backend/cups_helper.h"
#include "printing/backend/print_backend.h"
#include "printing/backend/print_backend_consts.h"

namespace {
static const char kCUPSPrinterInfoOpt[] = "printer-info";
static const char kCUPSPrinterStateOpt[] = "printer-state";
static const char kCUPSPrintServerURLs[] = "print_server_urls";
static const char kCUPSUpdateTimeoutMs[] = "update_timeout_ms";
static const char kCUPSPrintBackendServerURL[] = "print_server_url";

// Default port for IPP print servers.
static const int kDefaultIPPServerPort = 631;
Expand Down Expand Up @@ -380,7 +380,10 @@ void PrintSystemCUPS::AddPrintServer(const std::string& url) {

// Get Print backend for the specific print server.
DictionaryValue backend_settings;
backend_settings.SetString(kCUPSPrintBackendServerURL, url);
backend_settings.SetString(kCUPSPrintServerURL, url);

// Make CUPS requests non-blocking.
backend_settings.SetString(kCUPSBlocking, kValueFalse);

PrintServerInfoCUPS print_server;
print_server.backend =
Expand Down Expand Up @@ -622,6 +625,7 @@ int PrintSystemCUPS::PrintFile(const GURL& url, const char* name,
return cupsPrintFile(name, filename, title, num_options, options);
} else {
printing::HttpConnectionCUPS http(url);
http.SetBlocking(false);
return cupsPrintFile2(http.http(), name, filename,
title, num_options, options);
}
Expand All @@ -633,6 +637,7 @@ int PrintSystemCUPS::GetJobs(cups_job_t** jobs, const GURL& url,
return cupsGetJobs(jobs, name, myjobs, whichjobs);
} else {
printing::HttpConnectionCUPS http(url);
http.SetBlocking(false);
return cupsGetJobs2(http.http(), jobs, name, myjobs, whichjobs);
}
}
Expand Down
4 changes: 4 additions & 0 deletions printing/backend/print_backend_consts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@

const char kLocationTagName[] = "location";
const char kDriverNameTagName[] = "drivername";
const char kCUPSPrintServerURL[] = "print_server_url";
const char kCUPSBlocking[] = "cups_blocking";
const char kValueTrue[] = "true";
const char kValueFalse[] = "false";
4 changes: 4 additions & 0 deletions printing/backend/print_backend_consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@

extern const char kLocationTagName[];
extern const char kDriverNameTagName[];
extern const char kCUPSPrintServerURL[];
extern const char kCUPSBlocking[];
extern const char kValueTrue[];
extern const char kValueFalse[];

#endif // PRINTING_BACKEND_PRINT_BACKEND_CONSTS_H_
19 changes: 12 additions & 7 deletions printing/backend/print_backend_cups.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "base/values.h"
#include "googleurl/src/gurl.h"
#include "printing/backend/cups_helper.h"
#include "printing/backend/print_backend_consts.h"

#if !defined(OS_MACOSX)
GCRY_THREAD_OPTION_PTHREAD_IMPL;
Expand Down Expand Up @@ -76,11 +77,10 @@ namespace printing {

static const char kCUPSPrinterInfoOpt[] = "printer-info";
static const char kCUPSPrinterStateOpt[] = "printer-state";
static const char kCUPSPrintServerURL[] = "print_server_url";

class PrintBackendCUPS : public PrintBackend {
public:
explicit PrintBackendCUPS(const GURL& print_server_url);
PrintBackendCUPS(const GURL& print_server_url, bool blocking);
virtual ~PrintBackendCUPS() {}

// PrintBackend implementation.
Expand All @@ -100,10 +100,11 @@ class PrintBackendCUPS : public PrintBackend {
FilePath GetPPD(const char* name);

GURL print_server_url_;
bool blocking_;
};

PrintBackendCUPS::PrintBackendCUPS(const GURL& print_server_url)
: print_server_url_(print_server_url) {
PrintBackendCUPS::PrintBackendCUPS(const GURL& print_server_url, bool blocking)
: print_server_url_(print_server_url), blocking_(blocking) {
}

void PrintBackendCUPS::EnumeratePrinters(PrinterList* printer_list) {
Expand Down Expand Up @@ -194,20 +195,24 @@ scoped_refptr<PrintBackend> PrintBackend::CreateInstance(
g_gcrypt_initializer.Get();
#endif

std::string print_server_url_str;
std::string print_server_url_str, cups_blocking;
if (print_backend_settings) {
print_backend_settings->GetString(kCUPSPrintServerURL,
&print_server_url_str);

print_backend_settings->GetString(kCUPSBlocking,
&cups_blocking);
}
GURL print_server_url(print_server_url_str.c_str());
return new PrintBackendCUPS(print_server_url);
return new PrintBackendCUPS(print_server_url, cups_blocking == kValueTrue);
}

int PrintBackendCUPS::GetDests(cups_dest_t** dests) {
if (print_server_url_.is_empty()) { // Use default (local) print server.
return cupsGetDests(dests);
} else {
HttpConnectionCUPS http(print_server_url_);
http.SetBlocking(blocking_);
return cupsGetDests2(http.http(), dests);
}
}
Expand All @@ -233,7 +238,7 @@ FilePath PrintBackendCUPS::GetPPD(const char* name) {
// To distinguish error case from the normal return, will check result file
// size agains content length.
HttpConnectionCUPS http(print_server_url_);
http.SetBlocking(false);
http.SetBlocking(blocking_);
ppd_file_path = cupsGetPPD2(http.http(), name);
// Check if the get full PPD, since non-blocking call may simply return
// normally after timeout expired.
Expand Down

0 comments on commit 9c6ca60

Please sign in to comment.