summaryrefslogtreecommitdiffstats
path: root/chrome/service/cloud_print/printer_job_handler.cc
diff options
context:
space:
mode:
authorsanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-22 00:01:55 +0000
committersanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-22 00:01:55 +0000
commit574c7bb72cdc18bc52b69a10aad1287c85a57c70 (patch)
treeb52524b1ad81c3311603d421af4b3587a22320c8 /chrome/service/cloud_print/printer_job_handler.cc
parent3ab6796d3645a13a56a2fc311fc36c66d31089d6 (diff)
downloadchromium_src-574c7bb72cdc18bc52b69a10aad1287c85a57c70.zip
chromium_src-574c7bb72cdc18bc52b69a10aad1287c85a57c70.tar.gz
chromium_src-574c7bb72cdc18bc52b69a10aad1287c85a57c70.tar.bz2
As the first step in an effort to improve robustness of the cloud print proxy, we fetch printer capabilities and defaults in a child process so that printer driver crashes do not crash the entire proxy.
BUG=None TEST=Registration of printers, printer update in Cloud Print Proxy. Review URL: http://codereview.chromium.org/5947002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69899 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/service/cloud_print/printer_job_handler.cc')
-rw-r--r--chrome/service/cloud_print/printer_job_handler.cc46
1 files changed, 35 insertions, 11 deletions
diff --git a/chrome/service/cloud_print/printer_job_handler.cc b/chrome/service/cloud_print/printer_job_handler.cc
index 5c772ef..6013411 100644
--- a/chrome/service/cloud_print/printer_job_handler.cc
+++ b/chrome/service/cloud_print/printer_job_handler.cc
@@ -160,31 +160,54 @@ bool PrinterJobHandler::UpdatePrinterInfo() {
<< printer_info_cloud_.printer_id;
// We need to update the parts of the printer info that have changed
// (could be printer name, description, status or capabilities).
+ // First asynchronously fetch the capabilities.
printing::PrinterBasicInfo printer_info;
printer_watcher_->GetCurrentPrinterInfo(&printer_info);
- printing::PrinterCapsAndDefaults printer_caps;
+ cloud_print::PrintSystem::PrinterCapsAndDefaultsCallback* callback =
+ NewCallback(this,
+ &PrinterJobHandler::OnReceivePrinterCaps);
+ // Asnchronously fetch the printer caps and defaults. The story will
+ // continue in OnReceivePrinterCaps.
+ print_system_->GetPrinterCapsAndDefaults(
+ printer_info.printer_name.c_str(), callback);
+ // While we are waiting for the data, pretend we have work to do and return
+ // true.
+ return true;
+}
+
+void PrinterJobHandler::OnReceivePrinterCaps(
+ bool succeeded,
+ const std::string& printer_name,
+ const printing::PrinterCapsAndDefaults& caps_and_defaults) {
+ printing::PrinterBasicInfo printer_info;
+ printer_watcher_->GetCurrentPrinterInfo(&printer_info);
+
std::string post_data;
std::string mime_boundary;
CloudPrintHelpers::CreateMimeBoundaryForUpload(&mime_boundary);
- if (print_system_->GetPrinterCapsAndDefaults(
- printer_info.printer_name, &printer_caps)) {
- std::string caps_hash = MD5String(printer_caps.printer_capabilities);
+
+ if (succeeded) {
+ std::string caps_hash = MD5String(caps_and_defaults.printer_capabilities);
if (caps_hash != printer_info_cloud_.caps_hash) {
// Hashes don't match, we need to upload new capabilities (the defaults
// go for free along with the capabilities)
printer_info_cloud_.caps_hash = caps_hash;
CloudPrintHelpers::AddMultipartValueForUpload(
- kPrinterCapsValue, printer_caps.printer_capabilities,
- mime_boundary, printer_caps.caps_mime_type, &post_data);
+ kPrinterCapsValue, caps_and_defaults.printer_capabilities,
+ mime_boundary, caps_and_defaults.caps_mime_type, &post_data);
CloudPrintHelpers::AddMultipartValueForUpload(
- kPrinterDefaultsValue, printer_caps.printer_defaults,
- mime_boundary, printer_caps.defaults_mime_type,
+ kPrinterDefaultsValue, caps_and_defaults.printer_defaults,
+ mime_boundary, caps_and_defaults.defaults_mime_type,
&post_data);
CloudPrintHelpers::AddMultipartValueForUpload(
kPrinterCapsHashValue, caps_hash, mime_boundary, std::string(),
&post_data);
}
+ } else {
+ LOG(ERROR) << "Failed to get printer caps and defaults for printer: "
+ << printer_name;
}
+
std::string tags_hash =
CloudPrintHelpers::GenerateHashOfStringMap(printer_info.options);
if (tags_hash != printer_info_cloud_.tags_hash) {
@@ -216,7 +239,6 @@ bool PrinterJobHandler::UpdatePrinterInfo() {
mime_boundary, std::string(), &post_data);
}
printer_info_ = printer_info;
- bool ret = false;
if (!post_data.empty()) {
// Terminate the request body
post_data.append("--" + mime_boundary + "--\r\n");
@@ -228,9 +250,11 @@ bool PrinterJobHandler::UpdatePrinterInfo() {
CloudPrintHelpers::GetUrlForPrinterUpdate(
cloud_print_server_url_, printer_info_cloud_.printer_id),
this, auth_token_, kCloudPrintAPIMaxRetryCount, mime_type, post_data);
- ret = true;
+ } else {
+ // We are done here. Go to the Stop state
+ MessageLoop::current()->PostTask(
+ FROM_HERE, NewRunnableMethod(this, &PrinterJobHandler::Stop));
}
- return ret;
}
// CloudPrintURLFetcher::Delegate implementation.