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

Unified Diff: chrome/service/cloud_print/printer_job_handler.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/printer_job_handler.h ('k') | chrome/service/service_child_process_host.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/service/cloud_print/printer_job_handler.cc
===================================================================
--- chrome/service/cloud_print/printer_job_handler.cc (revision 69859)
+++ chrome/service/cloud_print/printer_job_handler.cc (working copy)
@@ -160,31 +160,54 @@
<< 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 @@
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 @@
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.
« no previous file with comments | « chrome/service/cloud_print/printer_job_handler.h ('k') | chrome/service/service_child_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698