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

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

Issue 5947002: As the first step in an effort to improve robustness of the cloud print proxy... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Review comments Created 10 years 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 69859)
+++ chrome/service/cloud_print/print_system_cups.cc (working copy)
@@ -76,9 +76,9 @@
virtual void EnumeratePrinters(printing::PrinterList* printer_list);
- virtual bool GetPrinterCapsAndDefaults(
+ virtual void GetPrinterCapsAndDefaults(
const std::string& printer_name,
- printing::PrinterCapsAndDefaults* printer_info);
+ PrinterCapsAndDefaultsCallback* callback);
virtual bool IsValidPrinter(const std::string& printer_name);
@@ -107,6 +107,11 @@
bool ParsePrintTicket(const std::string& print_ticket,
std::map<std::string, std::string>* options);
+ // Synchronous version of GetPrinterCapsAndDefaults.
+ bool GetPrinterCapsAndDefaults(
+ const std::string& printer_name,
+ printing::PrinterCapsAndDefaults* printer_info);
+
int GetUpdateTimeoutMs() const {
return update_timeout_;
}
@@ -133,6 +138,13 @@
PrintServerInfoCUPS* FindServerByFullName(
const std::string& full_printer_name, std::string* short_printer_name);
+ // Helper method to invoke a PrinterCapsAndDefaultsCallback.
+ static void RunCapsCallback(
+ PrinterCapsAndDefaultsCallback* callback,
+ bool succeeded,
+ const std::string& printer_name,
+ const printing::PrinterCapsAndDefaults& printer_info);
+
// PrintServerList contains information about all print servers and backends
// this proxy is connected to.
typedef std::list<PrintServerInfoCUPS> PrintServerList;
@@ -430,31 +442,18 @@
VLOG(1) << "CUPS: Total " << printer_list->size() << " printers enumerated.";
}
-bool PrintSystemCUPS::GetPrinterCapsAndDefaults(
+void PrintSystemCUPS::GetPrinterCapsAndDefaults(
const std::string& printer_name,
- printing::PrinterCapsAndDefaults* printer_info) {
- DCHECK(initialized_);
- std::string short_printer_name;
- PrintServerInfoCUPS* server_info =
- FindServerByFullName(printer_name, &short_printer_name);
- if (!server_info)
- return false;
-
- PrintServerInfoCUPS::CapsMap::iterator caps_it =
- server_info->caps_cache.find(printer_name);
- if (caps_it != server_info->caps_cache.end()) {
- *printer_info = caps_it->second;
- return true;
- }
-
- // TODO(gene): Retry multiple times in case of error.
- if (!server_info->backend->GetPrinterCapsAndDefaults(short_printer_name,
- printer_info) ) {
- return false;
- }
-
- server_info->caps_cache[printer_name] = *printer_info;
- return true;
+ PrinterCapsAndDefaultsCallback* callback) {
+ printing::PrinterCapsAndDefaults printer_info;
+ bool succeeded = GetPrinterCapsAndDefaults(printer_name, &printer_info);
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ NewRunnableFunction(&PrintSystemCUPS::RunCapsCallback,
+ callback,
+ succeeded,
+ printer_name,
+ printer_info));
}
bool PrintSystemCUPS::IsValidPrinter(const std::string& printer_name) {
@@ -492,6 +491,33 @@
return true;
}
+bool PrintSystemCUPS::GetPrinterCapsAndDefaults(
+ const std::string& printer_name,
+ printing::PrinterCapsAndDefaults* printer_info) {
+ DCHECK(initialized_);
+ std::string short_printer_name;
+ PrintServerInfoCUPS* server_info =
+ FindServerByFullName(printer_name, &short_printer_name);
+ if (!server_info)
+ return false;
+
+ PrintServerInfoCUPS::CapsMap::iterator caps_it =
+ server_info->caps_cache.find(printer_name);
+ if (caps_it != server_info->caps_cache.end()) {
+ *printer_info = caps_it->second;
+ return true;
+ }
+
+ // TODO(gene): Retry multiple times in case of error.
+ if (!server_info->backend->GetPrinterCapsAndDefaults(short_printer_name,
+ printer_info) ) {
+ return false;
+ }
+
+ server_info->caps_cache[printer_name] = *printer_info;
+ return true;
+}
+
bool PrintSystemCUPS::GetJobDetails(const std::string& printer_name,
PlatformJobId job_id,
PrintJobDetails *job_details) {
@@ -737,4 +763,13 @@
return NULL;
}
+void PrintSystemCUPS::RunCapsCallback(
+ PrinterCapsAndDefaultsCallback* callback,
+ bool succeeded,
+ const std::string& printer_name,
+ const printing::PrinterCapsAndDefaults& printer_info) {
+ callback->Run(succeeded, printer_name, printer_info);
+ delete callback;
+}
+
} // 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