Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1952)

Unified Diff: chrome/service/cloud_print/print_system_cups.cc

Issue 3051006: Used the service utility process host to render PDFs in a sandbox for the Win... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: CUPS tweaks Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/service/cloud_print/print_system.h ('k') | chrome/service/cloud_print/print_system_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/service/cloud_print/print_system_cups.cc
===================================================================
--- chrome/service/cloud_print/print_system_cups.cc (revision 53070)
+++ chrome/service/cloud_print/print_system_cups.cc (working copy)
@@ -124,6 +124,7 @@
public:
explicit PrintSystemCUPS(const GURL& print_server_url);
+ // PrintSystem implementation.
virtual void EnumeratePrinters(PrinterList* printer_list);
virtual bool GetPrinterCapsAndDefaults(const std::string& printer_name,
@@ -132,19 +133,13 @@
virtual bool ValidatePrintTicket(const std::string& printer_name,
const std::string& print_ticket_data);
- virtual bool SpoolPrintJob(const std::string& print_ticket,
- const FilePath& print_data_file_path,
- const std::string& print_data_mime_type,
- const std::string& printer_name,
- const std::string& job_title,
- PlatformJobId* job_id_ret);
-
virtual bool GetJobDetails(const std::string& printer_name,
PlatformJobId job_id,
PrintJobDetails *job_details);
virtual bool IsValidPrinter(const std::string& printer_name);
+
// TODO(gene): Add implementation for CUPS print server watcher.
class PrintServerWatcherCUPS
: public PrintSystem::PrintServerWatcher {
@@ -212,11 +207,53 @@
DISALLOW_COPY_AND_ASSIGN(PrinterWatcherCUPS);
};
+ class JobSpoolerCUPS : public PrintSystem::JobSpooler {
+ public:
+ explicit JobSpoolerCUPS(PrintSystemCUPS* print_system)
+ : print_system_(print_system) {
+ DCHECK(print_system_.get());
+ }
+ // PrintSystem::JobSpooler implementation.
+ virtual bool Spool(const std::string& print_ticket,
+ const FilePath& print_data_file_path,
+ const std::string& print_data_mime_type,
+ const std::string& printer_name,
+ const std::string& job_title,
+ JobSpooler::Delegate* delegate) {
+ DCHECK(delegate);
+ int job_id = print_system_->SpoolPrintJob(
+ print_ticket, print_data_file_path, print_data_mime_type,
+ printer_name, job_title);
+ MessageLoop::current()->PostTask(FROM_HERE,
+ NewRunnableFunction(
+ &JobSpoolerCUPS::NotifyDelegate,
+ delegate,
+ job_id));
+ return true;
+ }
+
+ static void NotifyDelegate(JobSpooler::Delegate* delegate, int job_id) {
+ if (job_id)
+ delegate->OnJobSpoolSucceeded(job_id);
+ else
+ delegate->OnJobSpoolFailed();
+ }
+ private:
+ scoped_refptr<PrintSystemCUPS> print_system_;
+ DISALLOW_COPY_AND_ASSIGN(JobSpoolerCUPS);
+ };
+
virtual PrintSystem::PrintServerWatcher* CreatePrintServerWatcher();
virtual PrintSystem::PrinterWatcher* CreatePrinterWatcher(
const std::string& printer_name);
+ virtual PrintSystem::JobSpooler* CreateJobSpooler();
// Helper functions.
+ PlatformJobId SpoolPrintJob(const std::string& print_ticket,
+ const FilePath& print_data_file_path,
+ const std::string& print_data_mime_type,
+ const std::string& printer_name,
+ const std::string& job_title);
bool GetPrinterInfo(const std::string& printer_name, PrinterBasicInfo* info);
bool ParsePrintTicket(const std::string& print_ticket,
std::map<std::string, std::string>* options);
@@ -228,10 +265,10 @@
// in the <functions>2(), it does not work in CUPS prior to 1.4.
int GetDests(cups_dest_t** dests);
FilePath GetPPD(const char* name);
+ int GetJobs(cups_job_t** jobs, const char* name,
+ int myjobs, int whichjobs);
int PrintFile(const char* name, const char* filename, const char* title,
int num_options, cups_option_t* options);
- int GetJobs(cups_job_t** jobs, const char* name,
- int myjobs, int whichjobs);
GURL print_server_url_;
};
@@ -336,47 +373,6 @@
return true;
}
-bool PrintSystemCUPS::SpoolPrintJob(const std::string& print_ticket,
- const FilePath& print_data_file_path,
- const std::string& print_data_mime_type,
- const std::string& printer_name,
- const std::string& job_title,
- PlatformJobId* job_id_ret) {
- DCHECK(job_id_ret);
-
- LOG(INFO) << "CP_CUPS: Spooling print job for: " << printer_name;
-
- // We need to store options as char* string for the duration of the
- // cupsPrintFile2 call. We'll use map here to store options, since
- // Dictionary value from JSON parser returns wchat_t.
- std::map<std::string, std::string> options;
- bool res = ParsePrintTicket(print_ticket, &options);
- DCHECK(res); // If print ticket is invalid we still print using defaults.
-
- 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());
- opt.value = const_cast<char*>(it->second.c_str());
- cups_options.push_back(opt);
- }
-
- int job_id = PrintFile(printer_name.c_str(),
- print_data_file_path.value().c_str(),
- job_title.c_str(),
- cups_options.size(),
- &(cups_options[0]));
-
- LOG(INFO) << "CP_CUPS: Job spooled, id: " << job_id;
-
- if (job_id == 0)
- return false;
-
- *job_id_ret = job_id;
- return true;
-}
-
bool PrintSystemCUPS::GetJobDetails(const std::string& printer_name,
PlatformJobId job_id,
PrintJobDetails *job_details) {
@@ -462,6 +458,10 @@
return new PrinterWatcherCUPS(this, printer_name);
}
+PrintSystem::JobSpooler* PrintSystemCUPS::CreateJobSpooler() {
+ return new JobSpoolerCUPS(this);
+}
+
std::string PrintSystem::GenerateProxyId() {
// TODO(gene): This code should generate a unique id for proxy. ID should be
// unique for this user. Rand may return the same number. We'll need to change
@@ -534,4 +534,39 @@
}
}
+PlatformJobId PrintSystemCUPS::SpoolPrintJob(
+ const std::string& print_ticket,
+ const FilePath& print_data_file_path,
+ const std::string& print_data_mime_type,
+ const std::string& printer_name,
+ const std::string& job_title) {
+ LOG(INFO) << "CP_CUPS: Spooling print job for: " << printer_name;
+
+ // We need to store options as char* string for the duration of the
+ // cupsPrintFile2 call. We'll use map here to store options, since
+ // Dictionary value from JSON parser returns wchat_t.
+ std::map<std::string, std::string> options;
+ bool res = ParsePrintTicket(print_ticket, &options);
+ DCHECK(res); // If print ticket is invalid we still print using defaults.
+
+ 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());
+ opt.value = const_cast<char*>(it->second.c_str());
+ cups_options.push_back(opt);
+ }
+
+ int job_id = PrintFile(printer_name.c_str(),
+ print_data_file_path.value().c_str(),
+ job_title.c_str(),
+ cups_options.size(),
+ &(cups_options[0]));
+
+ LOG(INFO) << "CP_CUPS: Job spooled, id: " << job_id;
+
+ return job_id;
+}
+
} // namespace cloud_print
« no previous file with comments | « chrome/service/cloud_print/print_system.h ('k') | chrome/service/cloud_print/print_system_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698