summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgene@google.com <gene@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-13 23:38:42 +0000
committergene@google.com <gene@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-13 23:38:42 +0000
commitc35a309c6faaaf6002fb8bb553a69e759c5ad1d3 (patch)
tree24e23f631583bde7ff09394011673032d42a900e
parent2331b71eeed6dc1a1dfc1d0656c0ec7e7d314fcb (diff)
downloadchromium_src-c35a309c6faaaf6002fb8bb553a69e759c5ad1d3.zip
chromium_src-c35a309c6faaaf6002fb8bb553a69e759c5ad1d3.tar.gz
chromium_src-c35a309c6faaaf6002fb8bb553a69e759c5ad1d3.tar.bz2
Added 'dry run' tag to the print job, to test proxy health without wasting paper/ink.
BUG=none TEST=Make sure 'dry run' jobs does not get printed. Review URL: http://codereview.chromium.org/5736004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69071 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/service/cloud_print/cloud_print_consts.cc3
-rw-r--r--chrome/service/cloud_print/cloud_print_consts.h3
-rw-r--r--chrome/service/cloud_print/cloud_print_helpers.cc8
-rw-r--r--chrome/service/cloud_print/cloud_print_helpers.h2
-rw-r--r--chrome/service/cloud_print/cloud_print_proxy_backend.cc2
-rw-r--r--chrome/service/cloud_print/print_system.h1
-rw-r--r--chrome/service/cloud_print/print_system_cups.cc49
-rw-r--r--chrome/service/cloud_print/print_system_win.cc2
-rw-r--r--chrome/service/cloud_print/printer_job_handler.cc12
-rw-r--r--chrome/service/cloud_print/printer_job_handler.h3
10 files changed, 76 insertions, 9 deletions
diff --git a/chrome/service/cloud_print/cloud_print_consts.cc b/chrome/service/cloud_print/cloud_print_consts.cc
index 7ca87ea..ece7e33 100644
--- a/chrome/service/cloud_print/cloud_print_consts.cc
+++ b/chrome/service/cloud_print/cloud_print_consts.cc
@@ -25,9 +25,10 @@ const char kFileUrlValue[] = "fileUrl";
const char kJobListValue[] = "jobs";
const char kTitleValue[] = "title";
const char kPrinterCapsHashValue[] = "capsHash";
-const char kPrinterTagsValue[] = "tags";
+const char kTagsValue[] = "tags";
const char kProxyTagPrefix[] = "__cp__";
const char kTagsHashTagName[] = "__cp__tagshash";
+const char kTagDryRunFlag[] = "__cp__dry_run";
const char kDefaultCloudPrintServerUrl[] = "https://www.google.com/cloudprint";
diff --git a/chrome/service/cloud_print/cloud_print_consts.h b/chrome/service/cloud_print/cloud_print_consts.h
index 6c150b7..a0bdc48 100644
--- a/chrome/service/cloud_print/cloud_print_consts.h
+++ b/chrome/service/cloud_print/cloud_print_consts.h
@@ -27,9 +27,10 @@ extern const char kFileUrlValue[];
extern const char kJobListValue[];
extern const char kTitleValue[];
extern const char kPrinterCapsHashValue[];
-extern const char kPrinterTagsValue[];
+extern const char kTagsValue[];
extern const char kProxyTagPrefix[];
extern const char kTagsHashTagName[];
+extern const char kTagDryRunFlag[];
extern const char kDefaultCloudPrintServerUrl[];
extern const char kGaiaUrl[];
extern const char kCloudPrintGaiaServiceId[];
diff --git a/chrome/service/cloud_print/cloud_print_helpers.cc b/chrome/service/cloud_print/cloud_print_helpers.cc
index 865e05d..ada2f6c 100644
--- a/chrome/service/cloud_print/cloud_print_helpers.cc
+++ b/chrome/service/cloud_print/cloud_print_helpers.cc
@@ -231,3 +231,11 @@ void CloudPrintHelpers::GenerateMultipartPostDataForPrinterTags(
std::string(), post_data);
}
+bool CloudPrintHelpers::IsDryRunJob(const std::vector<std::string>& tags) {
+ std::vector<std::string>::const_iterator it;
+ for (it = tags.begin(); it != tags.end(); ++it) {
+ if (*it == kTagDryRunFlag)
+ return true;
+ }
+ return false;
+}
diff --git a/chrome/service/cloud_print/cloud_print_helpers.h b/chrome/service/cloud_print/cloud_print_helpers.h
index 7061452..afc98c2 100644
--- a/chrome/service/cloud_print/cloud_print_helpers.h
+++ b/chrome/service/cloud_print/cloud_print_helpers.h
@@ -57,6 +57,8 @@ class CloudPrintHelpers {
const std::string& mime_boundary,
std::string* post_data);
+ // Returns true is tags indicate a dry run (test) job.
+ static bool IsDryRunJob(const std::vector<std::string>& tags);
private:
CloudPrintHelpers() {
}
diff --git a/chrome/service/cloud_print/cloud_print_proxy_backend.cc b/chrome/service/cloud_print/cloud_print_proxy_backend.cc
index dbb374f..1fa5814 100644
--- a/chrome/service/cloud_print/cloud_print_proxy_backend.cc
+++ b/chrome/service/cloud_print/cloud_print_proxy_backend.cc
@@ -637,7 +637,7 @@ void CloudPrintProxyBackend::Core::InitJobHandlerForPrinter(
printer_data->GetString(kPrinterCapsHashValue,
&printer_info_cloud.caps_hash);
ListValue* tags_list = NULL;
- printer_data->GetList(kPrinterTagsValue, &tags_list);
+ printer_data->GetList(kTagsValue, &tags_list);
if (tags_list) {
for (size_t index = 0; index < tags_list->GetSize(); index++) {
std::string tag;
diff --git a/chrome/service/cloud_print/print_system.h b/chrome/service/cloud_print/print_system.h
index 5a98f2c..620004c 100644
--- a/chrome/service/cloud_print/print_system.h
+++ b/chrome/service/cloud_print/print_system.h
@@ -126,6 +126,7 @@ class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> {
const std::string& print_data_mime_type,
const std::string& printer_name,
const std::string& job_title,
+ const std::vector<std::string>& tags,
JobSpooler::Delegate* delegate) = 0;
};
diff --git a/chrome/service/cloud_print/print_system_cups.cc b/chrome/service/cloud_print/print_system_cups.cc
index a985d79..2bd149d 100644
--- a/chrome/service/cloud_print/print_system_cups.cc
+++ b/chrome/service/cloud_print/print_system_cups.cc
@@ -26,6 +26,8 @@
#include "base/task.h"
#include "base/values.h"
#include "base/utf_string_conversions.h"
+#include "chrome/service/cloud_print/cloud_print_consts.h"
+#include "chrome/service/cloud_print/cloud_print_helpers.h"
#include "googleurl/src/gurl.h"
#include "printing/backend/cups_helper.h"
#include "printing/backend/print_backend.h"
@@ -46,6 +48,10 @@ const int kCheckForPrinterUpdatesMs = 6*60*60*1000;
// Job update timeput
const int kJobUpdateTimeoutMs = 5000;
+// Job id for dry run (it should not affect CUPS job ids, since 0 job-id is
+// invalid in CUPS.
+const int kDryRunJobId = 0;
+
} // namespace
namespace cloud_print {
@@ -93,7 +99,9 @@ class PrintSystemCUPS : public PrintSystem {
const FilePath& print_data_file_path,
const std::string& print_data_mime_type,
const std::string& printer_name,
- const std::string& job_title);
+ const std::string& job_title,
+ const std::vector<std::string>& tags,
+ bool* dry_run);
bool GetPrinterInfo(const std::string& printer_name,
printing::PrinterBasicInfo* info);
bool ParsePrintTicket(const std::string& print_ticket,
@@ -310,21 +318,25 @@ class JobSpoolerCUPS : public PrintSystem::JobSpooler {
const std::string& print_data_mime_type,
const std::string& printer_name,
const std::string& job_title,
+ const std::vector<std::string>& tags,
JobSpooler::Delegate* delegate) {
DCHECK(delegate);
+ bool dry_run = false;
int job_id = print_system_->SpoolPrintJob(
print_ticket, print_data_file_path, print_data_mime_type,
- printer_name, job_title);
+ printer_name, job_title, tags, &dry_run);
MessageLoop::current()->PostTask(FROM_HERE,
NewRunnableFunction(
&JobSpoolerCUPS::NotifyDelegate,
delegate,
- job_id));
+ job_id,
+ dry_run));
return true;
}
- static void NotifyDelegate(JobSpooler::Delegate* delegate, int job_id) {
- if (job_id)
+ static void NotifyDelegate(JobSpooler::Delegate* delegate,
+ int job_id, bool dry_run) {
+ if (dry_run || job_id)
delegate->OnJobSpoolSucceeded(job_id);
else
delegate->OnJobSpoolFailed();
@@ -493,6 +505,21 @@ bool PrintSystemCUPS::GetJobDetails(const std::string& printer_name,
int num_jobs = GetJobs(&jobs, server_info->url,
short_printer_name.c_str(), 1, -1);
+
+ // Check if the request is for dummy dry run job.
+ // We check this after calling GetJobs API to see if this printer is actually
+ // accessible through CUPS.
+ if (job_id == kDryRunJobId) {
+ if (num_jobs >= 0) {
+ job_details->status = PRINT_JOB_STATUS_COMPLETED;
+ VLOG(1) << "CP_CUPS: Dry run job succeeded for: " << printer_name;
+ } else {
+ job_details->status = PRINT_JOB_STATUS_ERROR;
+ VLOG(1) << "CP_CUPS: Dry run job faield for: " << printer_name;
+ }
+ return true;
+ }
+
bool found = false;
for (int i = 0; i < num_jobs; i++) {
if (jobs[i].id == job_id) {
@@ -615,7 +642,9 @@ PlatformJobId PrintSystemCUPS::SpoolPrintJob(
const FilePath& print_data_file_path,
const std::string& print_data_mime_type,
const std::string& printer_name,
- const std::string& job_title) {
+ const std::string& job_title,
+ const std::vector<std::string>& tags,
+ bool* dry_run) {
DCHECK(initialized_);
VLOG(1) << "CP_CUPS: Spooling print job for: " << printer_name;
@@ -632,8 +661,16 @@ PlatformJobId PrintSystemCUPS::SpoolPrintJob(
bool res = ParsePrintTicket(print_ticket, &options);
DCHECK(res); // If print ticket is invalid we still print using defaults.
+ // Check if this is a dry run (test) job.
+ *dry_run = CloudPrintHelpers::IsDryRunJob(tags);
+ if (*dry_run) {
+ VLOG(1) << "CP_CUPS: Dry run job spooled.";
+ return kDryRunJobId;
+ }
+
std::vector<cups_option_t> cups_options;
std::map<std::string, std::string>::iterator it;
+
for (it = options.begin(); it != options.end(); ++it) {
cups_option_t opt;
opt.name = const_cast<char*>(it->first.c_str());
diff --git a/chrome/service/cloud_print/print_system_win.cc b/chrome/service/cloud_print/print_system_win.cc
index c1b3491..571b677 100644
--- a/chrome/service/cloud_print/print_system_win.cc
+++ b/chrome/service/cloud_print/print_system_win.cc
@@ -348,7 +348,9 @@ class PrintSystemWin : public PrintSystem {
const std::string& print_data_mime_type,
const std::string& printer_name,
const std::string& job_title,
+ const std::vector<std::string>& tags,
JobSpooler::Delegate* delegate) {
+ // TODO(gene): add tags handling.
return core_->Spool(print_ticket, print_data_file_path,
print_data_mime_type, printer_name, job_title,
delegate);
diff --git a/chrome/service/cloud_print/printer_job_handler.cc b/chrome/service/cloud_print/printer_job_handler.cc
index d285594..8448536 100644
--- a/chrome/service/cloud_print/printer_job_handler.cc
+++ b/chrome/service/cloud_print/printer_job_handler.cc
@@ -350,6 +350,17 @@ PrinterJobHandler::HandleJobMetadataResponse(
std::string print_ticket_url;
job_data->GetString(kTicketUrlValue, &print_ticket_url);
job_data->GetString(kFileUrlValue, &print_data_url_);
+
+ // Get tags for print job.
+ job_details_.tags_.clear();
+ ListValue* tags = NULL;
+ if (job_data->GetList(kTagsValue, &tags)) {
+ for (size_t i = 0; i < tags->GetSize(); i++) {
+ std::string value;
+ if (tags->GetString(i, &value))
+ job_details_.tags_.push_back(value);
+ }
+ }
SetNextDataHandler(&PrinterJobHandler::HandlePrintTicketResponse);
request_ = new CloudPrintURLFetcher;
request_->StartGetRequest(GURL(print_ticket_url.c_str()),
@@ -567,6 +578,7 @@ void PrinterJobHandler::DoPrint(const JobDetails& job_details,
job_details.print_data_mime_type_,
printer_name,
job_details.job_title_,
+ job_details.tags_,
this)) {
OnJobSpoolFailed();
}
diff --git a/chrome/service/cloud_print/printer_job_handler.h b/chrome/service/cloud_print/printer_job_handler.h
index 2b43545..4a55fb0 100644
--- a/chrome/service/cloud_print/printer_job_handler.h
+++ b/chrome/service/cloud_print/printer_job_handler.h
@@ -8,6 +8,7 @@
#include <list>
#include <string>
+#include <vector>
#include "base/file_path.h"
#include "base/ref_counted.h"
@@ -77,12 +78,14 @@ class PrinterJobHandler : public base::RefCountedThreadSafe<PrinterJobHandler>,
std::string print_ticket_;
FilePath print_data_file_path_;
std::string print_data_mime_type_;
+ std::vector<std::string> tags_;
void Clear() {
job_id_.clear();
job_title_.clear();
print_ticket_.clear();
print_data_mime_type_.clear();
print_data_file_path_ = FilePath();
+ tags_.clear();
}
};