summaryrefslogtreecommitdiffstats
path: root/chrome/service
diff options
context:
space:
mode:
authorscottbyer@chromium.org <scottbyer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-27 18:09:00 +0000
committerscottbyer@chromium.org <scottbyer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-27 18:09:00 +0000
commit8da4a2de8addafaff6fcaf86b2d4d9a26ee48962 (patch)
tree6833a2ba7415ef1ca6347ddda41915b4dd76e6b7 /chrome/service
parentafe05a2814e8c6a533c49596697af5e619435efd (diff)
downloadchromium_src-8da4a2de8addafaff6fcaf86b2d4d9a26ee48962.zip
chromium_src-8da4a2de8addafaff6fcaf86b2d4d9a26ee48962.tar.gz
chromium_src-8da4a2de8addafaff6fcaf86b2d4d9a26ee48962.tar.bz2
On behalf of gene@chromium.org. Added CUPS options to the printer information. Options get uploaded to the cloud print server.
Also added some logging for cups proxy. BUG=none TEST=Run linux CP proxy and verify that CUPS options gets uploaded to the cloud print server. Review URL: http://codereview.chromium.org/2232002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48406 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/service')
-rw-r--r--chrome/service/cloud_print/cloud_print_consts.cc1
-rw-r--r--chrome/service/cloud_print/cloud_print_consts.h1
-rw-r--r--chrome/service/cloud_print/cloud_print_proxy_backend.cc14
-rw-r--r--chrome/service/cloud_print/printer_info.h2
-rw-r--r--chrome/service/cloud_print/printer_info_cups.cc28
5 files changed, 42 insertions, 4 deletions
diff --git a/chrome/service/cloud_print/cloud_print_consts.cc b/chrome/service/cloud_print/cloud_print_consts.cc
index 0c56336..b64f13a 100644
--- a/chrome/service/cloud_print/cloud_print_consts.cc
+++ b/chrome/service/cloud_print/cloud_print_consts.cc
@@ -12,6 +12,7 @@ const char kPrinterDescValue[] = "description";
const char kPrinterCapsValue[] = "capabilities";
const char kPrinterDefaultsValue[] = "defaults";
const char kPrinterStatusValue[] = "status";
+const char kPrinterTagValue[] = "tag";
// Values in the respone JSON from the cloud print server
const wchar_t kPrinterListValue[] = L"printers";
diff --git a/chrome/service/cloud_print/cloud_print_consts.h b/chrome/service/cloud_print/cloud_print_consts.h
index abce347..0b687be 100644
--- a/chrome/service/cloud_print/cloud_print_consts.h
+++ b/chrome/service/cloud_print/cloud_print_consts.h
@@ -14,6 +14,7 @@ extern const char kPrinterDescValue[];
extern const char kPrinterCapsValue[];
extern const char kPrinterDefaultsValue[];
extern const char kPrinterStatusValue[];
+extern const char kPrinterTagValue[];
// Values in the respone JSON from the cloud print server
extern const wchar_t kPrinterListValue[];
extern const wchar_t kSuccessValue[];
diff --git a/chrome/service/cloud_print/cloud_print_proxy_backend.cc b/chrome/service/cloud_print/cloud_print_proxy_backend.cc
index eb6f3f1..1b0989a 100644
--- a/chrome/service/cloud_print/cloud_print_proxy_backend.cc
+++ b/chrome/service/cloud_print/cloud_print_proxy_backend.cc
@@ -376,6 +376,20 @@ void CloudPrintProxyBackend::Core::RegisterNextPrinter() {
CloudPrintHelpers::AddMultipartValueForUpload(
kPrinterStatusValue, StringPrintf("%d", info.printer_status),
mime_boundary, std::string(), &post_data);
+ // Add printer options as tags.
+ std::map<std::string, std::string>::const_iterator it;
+ for (it = info.options.begin(); it != info.options.end(); ++it) {
+ // TODO(gene) Escape '=' char from name. Warning for now.
+ if (it->first.find('=') != std::string::npos) {
+ LOG(WARNING) << "CUPS option name contains '=' character";
+ NOTREACHED();
+ }
+ std::string msg(it->first);
+ msg += "=";
+ msg += it->second;
+ CloudPrintHelpers::AddMultipartValueForUpload(
+ kPrinterTagValue, msg, mime_boundary, std::string(), &post_data);
+ }
CloudPrintHelpers::AddMultipartValueForUpload(
kPrinterCapsValue, last_uploaded_printer_info_.printer_capabilities,
mime_boundary, last_uploaded_printer_info_.caps_mime_type,
diff --git a/chrome/service/cloud_print/printer_info.h b/chrome/service/cloud_print/printer_info.h
index 912e6bf..4823037 100644
--- a/chrome/service/cloud_print/printer_info.h
+++ b/chrome/service/cloud_print/printer_info.h
@@ -5,6 +5,7 @@
#ifndef CHROME_SERVICE_CLOUD_PRINT_PRINTER_INFO_H_
#define CHROME_SERVICE_CLOUD_PRINT_PRINTER_INFO_H_
+#include <map>
#include <string>
#include <vector>
@@ -19,6 +20,7 @@ struct PrinterBasicInfo {
std::string printer_name;
std::string printer_description;
int printer_status;
+ std::map<std::string, std::string> options;
PrinterBasicInfo() : printer_status(0) {
}
};
diff --git a/chrome/service/cloud_print/printer_info_cups.cc b/chrome/service/cloud_print/printer_info_cups.cc
index f947064..38be60b 100644
--- a/chrome/service/cloud_print/printer_info_cups.cc
+++ b/chrome/service/cloud_print/printer_info_cups.cc
@@ -32,30 +32,42 @@ void EnumeratePrinters(PrinterList* printer_list) {
cups_dest_t* destinations = NULL;
int num_dests = cupsGetDests(&destinations);
- for (int i = 0; i < num_dests; i++) {
+ for (int printer_index = 0; printer_index < num_dests; printer_index++) {
+ const cups_dest_t& printer = destinations[printer_index];
+
PrinterBasicInfo printer_info;
- printer_info.printer_name = destinations[i].name;
+ printer_info.printer_name = printer.name;
const char* info = cupsGetOption(kCUPSPrinterInfoOpt,
- destinations[i].num_options, destinations[i].options);
+ printer.num_options, printer.options);
if (info != NULL)
printer_info.printer_description = info;
const char* state = cupsGetOption(kCUPSPrinterStateOpt,
- destinations[i].num_options, destinations[i].options);
+ printer.num_options, printer.options);
if (state != NULL)
StringToInt(state, &printer_info.printer_status);
+ // Store printer options.
+ for (int opt_index = 0; opt_index < printer.num_options; opt_index++) {
+ printer_info.options[printer.options[opt_index].name] =
+ printer.options[opt_index].value;
+ }
+
printer_list->push_back(printer_info);
}
cupsFreeDests(num_dests, destinations);
+
+ DLOG(INFO) << "Enumerated " << printer_list->size() << " printers.";
}
bool GetPrinterCapsAndDefaults(const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) {
DCHECK(printer_info);
+ DLOG(INFO) << "Getting Caps and Defaults for: " << printer_name;
+
static Lock ppd_lock;
// cupsGetPPD returns a filename stored in a static buffer in CUPS.
// Protect this code with lock.
@@ -126,6 +138,8 @@ bool SpoolPrintJob(const std::string& print_ticket,
PlatformJobId* job_id_ret) {
DCHECK(job_id_ret);
+ DLOG(INFO) << "Spooling print job for: " << printer_name;
+
// We need to store options as char* string for the duration of the
// cupsPrintFile call. We'll use map here to store options, since
// Dictionary value from JSON parser returns wchat_t.
@@ -159,6 +173,10 @@ bool GetJobDetails(const std::string& printer_name,
PlatformJobId job_id,
PrintJobDetails *job_details) {
DCHECK(job_details);
+
+ DLOG(INFO) << "Getting job details for: " << printer_name <<
+ " job_id: " << job_id;
+
cups_job_t* jobs = NULL;
int num_jobs = cupsGetJobs(&jobs, printer_name.c_str(), 1, -1);
@@ -197,6 +215,8 @@ bool GetJobDetails(const std::string& printer_name,
bool GetPrinterInfo(const std::string& printer_name, PrinterBasicInfo* info) {
DCHECK(info);
+ DLOG(INFO) << "Getting printer info for: " << printer_name;
+
// This is not very efficient way to get specific printer info. CUPS 1.4
// supports cupsGetNamedDest() function. However, CUPS 1.4 is not available
// everywhere (for example, it supported from Mac OS 10.6 only).