summaryrefslogtreecommitdiffstats
path: root/chrome/service
diff options
context:
space:
mode:
authorsanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-07 20:31:53 +0000
committersanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-07 20:31:53 +0000
commit32af68ef3bd97d5c1517f3509bceeb7857a40503 (patch)
treefd2837f14bf7eaaa9f485655a94bafe7edfe71df /chrome/service
parentfd3b62921c710c5a245b64a2fb978127dcc0113d (diff)
downloadchromium_src-32af68ef3bd97d5c1517f3509bceeb7857a40503.zip
chromium_src-32af68ef3bd97d5c1517f3509bceeb7857a40503.tar.gz
chromium_src-32af68ef3bd97d5c1517f3509bceeb7857a40503.tar.bz2
This CL contains the following changes:
Added "location" and "drivername" tags for Windows printers. Saved a hash of all tags with the printer. Checked for this during printer update and reuploaded new tags if tags have changed. All proxy generated tags have a special __cp__ prefix. BUG=None. TEST=Test with changed printer tags. The proxy should make an update request with the new tags. Review URL: http://codereview.chromium.org/3342015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58746 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/service')
-rw-r--r--chrome/service/cloud_print/cloud_print_consts.cc7
-rw-r--r--chrome/service/cloud_print/cloud_print_consts.h7
-rw-r--r--chrome/service/cloud_print/cloud_print_helpers.cc50
-rw-r--r--chrome/service/cloud_print/cloud_print_helpers.h8
-rw-r--r--chrome/service/cloud_print/cloud_print_proxy_backend.cc53
-rw-r--r--chrome/service/cloud_print/print_system_win.cc18
-rw-r--r--chrome/service/cloud_print/printer_job_handler.cc94
-rw-r--r--chrome/service/cloud_print/printer_job_handler.h12
8 files changed, 186 insertions, 63 deletions
diff --git a/chrome/service/cloud_print/cloud_print_consts.cc b/chrome/service/cloud_print/cloud_print_consts.cc
index 2099ba6..d248a10 100644
--- a/chrome/service/cloud_print/cloud_print_consts.cc
+++ b/chrome/service/cloud_print/cloud_print_consts.cc
@@ -13,6 +13,7 @@ const char kPrinterCapsValue[] = "capabilities";
const char kPrinterDefaultsValue[] = "defaults";
const char kPrinterStatusValue[] = "status";
const char kPrinterTagValue[] = "tag";
+const char kPrinterRemoveTagValue[] = "remove_tag";
// Values in the respone JSON from the cloud print server
const char kPrinterListValue[] = "printers";
@@ -24,6 +25,12 @@ const char kFileUrlValue[] = "fileUrl";
const char kJobListValue[] = "jobs";
const char kTitleValue[] = "title";
const char kPrinterCapsHashValue[] = "capsHash";
+const char kPrinterTagsValue[] = "tags";
+const char kProxyTagPrefix[] = "__cp__";
+const char kTagsHashTagName[] = "__cp__tagshash";
+const char kLocationTagName[] = "location";
+const char kDriverNameTagName[] = "drivername";
+
const char kDefaultCloudPrintServerUrl[] = "https://www.google.com/cloudprint";
const char kCloudPrintTalkServiceUrl[] = "http://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 517687f..33381dc 100644
--- a/chrome/service/cloud_print/cloud_print_consts.h
+++ b/chrome/service/cloud_print/cloud_print_consts.h
@@ -16,6 +16,7 @@ extern const char kPrinterCapsValue[];
extern const char kPrinterDefaultsValue[];
extern const char kPrinterStatusValue[];
extern const char kPrinterTagValue[];
+extern const char kPrinterRemoveTagValue[];
// Values in the respone JSON from the cloud print server
extern const char kPrinterListValue[];
extern const char kSuccessValue[];
@@ -26,7 +27,11 @@ extern const char kFileUrlValue[];
extern const char kJobListValue[];
extern const char kTitleValue[];
extern const char kPrinterCapsHashValue[];
-
+extern const char kPrinterTagsValue[];
+extern const char kProxyTagPrefix[];
+extern const char kTagsHashTagName[];
+extern const char kLocationTagName[];
+extern const char kDriverNameTagName[];
extern const char kDefaultCloudPrintServerUrl[];
extern const char kCloudPrintTalkServiceUrl[];
extern const char kGaiaUrl[];
diff --git a/chrome/service/cloud_print/cloud_print_helpers.cc b/chrome/service/cloud_print/cloud_print_helpers.cc
index f50e0ad..d101f0e 100644
--- a/chrome/service/cloud_print/cloud_print_helpers.cc
+++ b/chrome/service/cloud_print/cloud_print_helpers.cc
@@ -5,6 +5,7 @@
#include "chrome/service/cloud_print/cloud_print_helpers.h"
#include "base/json/json_reader.h"
+#include "base/md5.h"
#include "base/rand_util.h"
#include "base/scoped_ptr.h"
#include "base/string_util.h"
@@ -209,3 +210,52 @@ void CloudPrintHelpers::CreateMimeBoundaryForUpload(std::string* out) {
SStringPrintf(out, "---------------------------%08X%08X", r1, r2);
}
+std::string CloudPrintHelpers::GenerateHashOfStringMap(
+ const std::map<std::string, std::string>& string_map) {
+ std::string values_list;
+ std::map<std::string, std::string>::const_iterator it;
+ for (it = string_map.begin(); it != string_map.end(); ++it) {
+ values_list.append(it->first);
+ values_list.append(it->second);
+ }
+ return MD5String(values_list);
+}
+
+void CloudPrintHelpers::GenerateMultipartPostDataForPrinterTags(
+ const std::map<std::string, std::string>& printer_tags,
+ const std::string& mime_boundary,
+ std::string* post_data) {
+ // We do not use the GenerateHashOfStringMap to compute the hash because that
+ // method iterates through the map again. Since we are already iterating here
+ // we just compute it on the fly.
+ // Also, in some cases, the code that calls this has already computed the
+ // hash. We could take in the precomputed hash as an argument but that just
+ // makes the code more complicated.
+ std::string tags_list;
+ std::map<std::string, std::string>::const_iterator it;
+ for (it = printer_tags.begin(); it != printer_tags.end(); ++it) {
+ // TODO(gene) Escape '=' char from name. Warning for now.
+ if (it->first.find('=') != std::string::npos) {
+ LOG(WARNING) <<
+ "CP_PROXY: Printer option name contains '=' character";
+ NOTREACHED();
+ }
+ tags_list.append(it->first);
+ tags_list.append(it->second);
+
+ // All our tags have a special prefix to identify them as such.
+ std::string msg(kProxyTagPrefix);
+ msg += it->first;
+ msg += "=";
+ msg += it->second;
+ AddMultipartValueForUpload(kPrinterTagValue, msg, mime_boundary,
+ std::string(), post_data);
+ }
+ std::string tags_hash = MD5String(tags_list);
+ std::string tags_hash_msg(kTagsHashTagName);
+ tags_hash_msg += "=";
+ tags_hash_msg += tags_hash;
+ AddMultipartValueForUpload(kPrinterTagValue, tags_hash_msg, mime_boundary,
+ std::string(), post_data);
+}
+
diff --git a/chrome/service/cloud_print/cloud_print_helpers.h b/chrome/service/cloud_print/cloud_print_helpers.h
index 93ccb44..c0bd61d 100644
--- a/chrome/service/cloud_print/cloud_print_helpers.h
+++ b/chrome/service/cloud_print/cloud_print_helpers.h
@@ -6,6 +6,7 @@
#define CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_
#pragma once
+#include <map>
#include <string>
#include "chrome/service/cloud_print/print_system.h"
@@ -68,6 +69,13 @@ class CloudPrintHelpers {
std::string* post_data);
// Create a MIME boundary marker (27 '-' characters followed by 16 hex digits).
static void CreateMimeBoundaryForUpload(std::string *out);
+ // Generates an MD5 hash of the contents of a string map.
+ static std::string GenerateHashOfStringMap(
+ const std::map<std::string, std::string>& string_map);
+ static void GenerateMultipartPostDataForPrinterTags(
+ const std::map<std::string, std::string>& printer_tags,
+ const std::string& mime_boundary,
+ std::string* post_data);
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 a0aa700..b0e621f 100644
--- a/chrome/service/cloud_print/cloud_print_proxy_backend.cc
+++ b/chrome/service/cloud_print/cloud_print_proxy_backend.cc
@@ -417,19 +417,10 @@ void CloudPrintProxyBackend::Core::RegisterNextPrinter() {
kPrinterStatusValue, StringPrintf("%d", info.printer_status),
mime_boundary, std::string(), &post_data);
// Add printer options as tags.
- std::map<std::string, std::string>::const_iterator it;
- for (it = info.options.begin(); it != info.options.end(); ++it) {
- // TODO(gene) Escape '=' char from name. Warning for now.
- if (it->first.find('=') != std::string::npos) {
- LOG(WARNING) << "CP_PROXY: CUPS option name contains '=' character";
- NOTREACHED();
- }
- std::string msg(it->first);
- msg += "=";
- msg += it->second;
- CloudPrintHelpers::AddMultipartValueForUpload(
- kPrinterTagValue, msg, mime_boundary, std::string(), &post_data);
- }
+ CloudPrintHelpers::GenerateMultipartPostDataForPrinterTags(info.options,
+ mime_boundary,
+ &post_data);
+
CloudPrintHelpers::AddMultipartValueForUpload(
kPrinterCapsValue, last_uploaded_printer_info_.printer_capabilities,
mime_boundary, last_uploaded_printer_info_.caps_mime_type,
@@ -547,11 +538,13 @@ void CloudPrintProxyBackend::Core::HandlePrinterListResponse(
void CloudPrintProxyBackend::Core::InitJobHandlerForPrinter(
DictionaryValue* printer_data) {
DCHECK(printer_data);
- std::string printer_id;
- printer_data->GetString(kIdValue, &printer_id);
- DCHECK(!printer_id.empty());
- LOG(INFO) << "CP_PROXY: Init job handler for printer id: " << printer_id;
- JobHandlerMap::iterator index = job_handler_map_.find(printer_id);
+ PrinterJobHandler::PrinterInfoFromCloud printer_info_cloud;
+ printer_data->GetString(kIdValue, &printer_info_cloud.printer_id);
+ DCHECK(!printer_info_cloud.printer_id.empty());
+ LOG(INFO) << "CP_PROXY: Init job handler for printer id: " <<
+ printer_info_cloud.printer_id;
+ JobHandlerMap::iterator index = job_handler_map_.find(
+ printer_info_cloud.printer_id);
// We might already have a job handler for this printer
if (index == job_handler_map_.end()) {
cloud_print::PrinterBasicInfo printer_info;
@@ -561,13 +554,29 @@ void CloudPrintProxyBackend::Core::InitJobHandlerForPrinter(
&printer_info.printer_description);
printer_data->GetInteger(kPrinterStatusValue,
&printer_info.printer_status);
- std::string caps_hash;
- printer_data->GetString(kPrinterCapsHashValue, &caps_hash);
+ printer_data->GetString(kPrinterCapsHashValue,
+ &printer_info_cloud.caps_hash);
+ ListValue* tags_list = NULL;
+ printer_data->GetList(kPrinterTagsValue, &tags_list);
+ if (tags_list) {
+ for (size_t index = 0; index < tags_list->GetSize(); index++) {
+ std::string tag;
+ tags_list->GetString(index, &tag);
+ if (StartsWithASCII(tag, kTagsHashTagName, false)) {
+ std::vector<std::string> tag_parts;
+ SplitStringDontTrim(tag, '=', &tag_parts);
+ DCHECK(tag_parts.size() == 2);
+ if (tag_parts.size() == 2) {
+ printer_info_cloud.tags_hash = tag_parts[1];
+ }
+ }
+ }
+ }
scoped_refptr<PrinterJobHandler> job_handler;
- job_handler = new PrinterJobHandler(printer_info, printer_id, caps_hash,
+ job_handler = new PrinterJobHandler(printer_info, printer_info_cloud,
auth_token_, cloud_print_server_url_,
print_system_.get(), this);
- job_handler_map_[printer_id] = job_handler;
+ job_handler_map_[printer_info_cloud.printer_id] = job_handler;
job_handler->Initialize();
}
}
diff --git a/chrome/service/cloud_print/print_system_win.cc b/chrome/service/cloud_print/print_system_win.cc
index da16fa2..a62d167 100644
--- a/chrome/service/cloud_print/print_system_win.cc
+++ b/chrome/service/cloud_print/print_system_win.cc
@@ -19,6 +19,7 @@
#include "base/scoped_handle_win.h"
#include "base/scoped_ptr.h"
#include "base/utf_string_conversions.h"
+#include "chrome/service/cloud_print/cloud_print_consts.h"
#include "chrome/service/service_process.h"
#include "chrome/service/service_utility_process_host.h"
#include "gfx/rect.h"
@@ -221,8 +222,15 @@ class PrintSystemWatcherWin
PRINTER_INFO_2* printer_info_win =
reinterpret_cast<PRINTER_INFO_2*>(printer_info_buffer.get());
printer_info->printer_name = WideToUTF8(printer_info_win->pPrinterName);
- printer_info->printer_description =
- WideToUTF8(printer_info_win->pComment);
+ if (printer_info_win->pComment)
+ printer_info->printer_description =
+ WideToUTF8(printer_info_win->pComment);
+ if (printer_info_win->pLocation)
+ printer_info->options[kLocationTagName] =
+ WideToUTF8(printer_info_win->pLocation);
+ if (printer_info_win->pDriverName)
+ printer_info->options[kDriverNameTagName] =
+ WideToUTF8(printer_info_win->pDriverName);
printer_info->printer_status = printer_info_win->Status;
ret = true;
}
@@ -534,6 +542,12 @@ void PrintSystemWin::EnumeratePrinters(PrinterList* printer_list) {
if (printer_info[index].pComment)
info.printer_description = WideToUTF8(printer_info[index].pComment);
info.printer_status = printer_info[index].Status;
+ if (printer_info[index].pLocation)
+ info.options[kLocationTagName] =
+ WideToUTF8(printer_info[index].pLocation);
+ if (printer_info[index].pDriverName)
+ info.options[kDriverNameTagName] =
+ WideToUTF8(printer_info[index].pDriverName);
printer_list->push_back(info);
}
}
diff --git a/chrome/service/cloud_print/printer_job_handler.cc b/chrome/service/cloud_print/printer_job_handler.cc
index 8abb152..36cc67e 100644
--- a/chrome/service/cloud_print/printer_job_handler.cc
+++ b/chrome/service/cloud_print/printer_job_handler.cc
@@ -18,17 +18,15 @@
PrinterJobHandler::PrinterJobHandler(
const cloud_print::PrinterBasicInfo& printer_info,
- const std::string& printer_id,
- const std::string& caps_hash,
+ const PrinterInfoFromCloud& printer_info_cloud,
const std::string& auth_token,
const GURL& cloud_print_server_url,
cloud_print::PrintSystem* print_system,
Delegate* delegate)
: print_system_(print_system),
printer_info_(printer_info),
- printer_id_(printer_id),
+ printer_info_cloud_(printer_info_cloud),
auth_token_(auth_token),
- last_caps_hash_(caps_hash),
cloud_print_server_url_(cloud_print_server_url),
delegate_(delegate),
local_job_id_(-1),
@@ -71,8 +69,9 @@ void PrinterJobHandler::Reset() {
}
void PrinterJobHandler::Start() {
- LOG(INFO) << "CP_PROXY: Start printer job handler, id: " << printer_id_ <<
- ", task in progress: " << task_in_progress_;
+ LOG(INFO) << "CP_PROXY: Start printer job handler, id: " <<
+ printer_info_cloud_.printer_id << ", task in progress: " <<
+ task_in_progress_;
if (task_in_progress_) {
// Multiple Starts can get posted because of multiple notifications
// We want to ignore the other ones that happen when a task is in progress.
@@ -86,8 +85,8 @@ void PrinterJobHandler::Start() {
printer_delete_pending_ = false;
task_in_progress_ = true;
MakeServerRequest(
- CloudPrintHelpers::GetUrlForPrinterDelete(cloud_print_server_url_,
- printer_id_),
+ CloudPrintHelpers::GetUrlForPrinterDelete(
+ cloud_print_server_url_, printer_info_cloud_.printer_id),
&PrinterJobHandler::HandlePrinterDeleteResponse,
&PrinterJobHandler::Stop);
}
@@ -101,7 +100,7 @@ void PrinterJobHandler::Start() {
// We need to fetch any pending jobs for this printer
MakeServerRequest(
CloudPrintHelpers::GetUrlForJobFetch(
- cloud_print_server_url_, printer_id_),
+ cloud_print_server_url_, printer_info_cloud_.printer_id),
&PrinterJobHandler::HandleJobMetadataResponse,
&PrinterJobHandler::Stop);
}
@@ -110,7 +109,8 @@ void PrinterJobHandler::Start() {
}
void PrinterJobHandler::Stop() {
- LOG(INFO) << "CP_PROXY: Stop printer job handler, id: " << printer_id_;
+ LOG(INFO) << "CP_PROXY: Stop printer job handler, id: " <<
+ printer_info_cloud_.printer_id;
task_in_progress_ = false;
Reset();
if (HavePendingTasks()) {
@@ -120,8 +120,9 @@ void PrinterJobHandler::Stop() {
}
void PrinterJobHandler::NotifyJobAvailable() {
- LOG(INFO) << "CP_PROXY: Notify job available, id: " << printer_id_ <<
- ", task in progress: " << task_in_progress_;
+ LOG(INFO) << "CP_PROXY: Notify job available, id: " <<
+ printer_info_cloud_.printer_id << ", task in progress: " <<
+ task_in_progress_;
server_job_available_ = true;
if (!task_in_progress_) {
MessageLoop::current()->PostTask(
@@ -130,7 +131,8 @@ void PrinterJobHandler::NotifyJobAvailable() {
}
bool PrinterJobHandler::UpdatePrinterInfo() {
- LOG(INFO) << "CP_PROXY: Update printer info, id: " << printer_id_;
+ LOG(INFO) << "CP_PROXY: Update printer info, id: " <<
+ 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).
cloud_print::PrinterBasicInfo printer_info;
@@ -138,14 +140,14 @@ bool PrinterJobHandler::UpdatePrinterInfo() {
cloud_print::PrinterCapsAndDefaults printer_caps;
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);
- CloudPrintHelpers::CreateMimeBoundaryForUpload(&mime_boundary);
- if (caps_hash != last_caps_hash_) {
+ 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)
- last_caps_hash_ = caps_hash;
+ printer_info_cloud_.caps_hash = caps_hash;
CloudPrintHelpers::AddMultipartValueForUpload(
kPrinterCapsValue, printer_caps.printer_capabilities,
mime_boundary, printer_caps.caps_mime_type, &post_data);
@@ -158,6 +160,20 @@ bool PrinterJobHandler::UpdatePrinterInfo() {
&post_data);
}
}
+ std::string tags_hash =
+ CloudPrintHelpers::GenerateHashOfStringMap(printer_info.options);
+ if (tags_hash != printer_info_cloud_.tags_hash) {
+ printer_info_cloud_.tags_hash = tags_hash;
+ CloudPrintHelpers::GenerateMultipartPostDataForPrinterTags(
+ printer_info.options, mime_boundary, &post_data);
+ // Remove all the exising proxy tags.
+ std::string cp_tag_wildcard(kProxyTagPrefix);
+ cp_tag_wildcard += ".*";
+ CloudPrintHelpers::AddMultipartValueForUpload(
+ kPrinterRemoveTagValue, cp_tag_wildcard, mime_boundary, std::string(),
+ &post_data);
+ }
+
if (printer_info.printer_name != printer_info_.printer_name) {
CloudPrintHelpers::AddMultipartValueForUpload(kPrinterNameValue,
printer_info.printer_name,
@@ -183,7 +199,8 @@ bool PrinterJobHandler::UpdatePrinterInfo() {
mime_type += mime_boundary;
request_.reset(
new URLFetcher(CloudPrintHelpers::GetUrlForPrinterUpdate(
- cloud_print_server_url_, printer_id_),
+ cloud_print_server_url_,
+ printer_info_cloud_.printer_id),
URLFetcher::POST, this));
CloudPrintHelpers::PrepCloudPrintRequest(request_.get(), auth_token_);
request_->set_upload_data(mime_type, post_data);
@@ -264,7 +281,8 @@ bool PrinterJobHandler::HandlePrinterUpdateResponse(
int response_code, const ResponseCookies& cookies,
const std::string& data) {
bool ret = false;
- LOG(INFO) << "CP_PROXY: Handle printer update response, id: " << printer_id_;
+ LOG(INFO) << "CP_PROXY: Handle printer update response, id: " <<
+ printer_info_cloud_.printer_id;
// If there was a network error or a non-200 response (which, for our purposes
// is the same as a network error), we want to retry.
if (status.is_success() && (response_code == 200)) {
@@ -292,7 +310,8 @@ bool PrinterJobHandler::HandlePrinterDeleteResponse(
int response_code, const ResponseCookies& cookies,
const std::string& data) {
bool ret = false;
- LOG(INFO) << "CP_PROXY: Handler printer delete response, id: " << printer_id_;
+ LOG(INFO) << "CP_PROXY: Handler printer delete response, id: " <<
+ printer_info_cloud_.printer_id;
// If there was a network error or a non-200 response (which, for our purposes
// is the same as a network error), we want to retry.
if (status.is_success() && (response_code == 200)) {
@@ -319,7 +338,8 @@ bool PrinterJobHandler::HandleJobMetadataResponse(
const URLFetcher* source, const GURL& url, const URLRequestStatus& status,
int response_code, const ResponseCookies& cookies,
const std::string& data) {
- LOG(INFO) << "CP_PROXY: Handle job metadata response, id: " << printer_id_;
+ LOG(INFO) << "CP_PROXY: Handle job metadata response, id: " <<
+ printer_info_cloud_.printer_id;
// If there was a network error or a non-200 response (which, for our purposes
// is the same as a network error), we want to retry.
if (!status.is_success() || (response_code != 200)) {
@@ -368,7 +388,8 @@ bool PrinterJobHandler::HandlePrintTicketResponse(
const URLFetcher* source, const GURL& url, const URLRequestStatus& status,
int response_code, const ResponseCookies& cookies,
const std::string& data) {
- LOG(INFO) << "CP_PROXY: Handle print ticket response, id: " << printer_id_;
+ LOG(INFO) << "CP_PROXY: Handle print ticket response, id: " <<
+ printer_info_cloud_.printer_id;
// If there was a network error or a non-200 response (which, for our purposes
// is the same as a network error), we want to retry.
if (!status.is_success() || (response_code != 200)) {
@@ -396,7 +417,8 @@ bool PrinterJobHandler::HandlePrintDataResponse(const URLFetcher* source,
int response_code,
const ResponseCookies& cookies,
const std::string& data) {
- LOG(INFO) << "CP_PROXY: Handle print data response, id: " << printer_id_;
+ LOG(INFO) << "CP_PROXY: Handle print data response, id: " <<
+ printer_info_cloud_.printer_id;
// If there was a network error or a non-200 response (which, for our purposes
// is the same as a network error), we want to retry.
if (!status.is_success() || (response_code != 200)) {
@@ -425,7 +447,8 @@ bool PrinterJobHandler::HandlePrintDataResponse(const URLFetcher* source,
}
void PrinterJobHandler::StartPrinting() {
- LOG(INFO) << "CP_PROXY: Start printing, id: " << printer_id_;
+ LOG(INFO) << "CP_PROXY: Start printing, id: " <<
+ printer_info_cloud_.printer_id;
// We are done with the request object for now.
request_.reset();
if (!shutting_down_) {
@@ -441,15 +464,15 @@ void PrinterJobHandler::StartPrinting() {
}
void PrinterJobHandler::JobFailed(PrintJobError error) {
- LOG(INFO) << "CP_PROXY: Job failed, id: " << printer_id_;
+ LOG(INFO) << "CP_PROXY: Job failed, id: " << printer_info_cloud_.printer_id;
if (!shutting_down_) {
UpdateJobStatus(cloud_print::PRINT_JOB_STATUS_ERROR, error);
}
}
void PrinterJobHandler::JobSpooled(cloud_print::PlatformJobId local_job_id) {
- LOG(INFO) << "CP_PROXY: Job spooled, printer id: " << printer_id_ <<
- ", job id: " << local_job_id;
+ LOG(INFO) << "CP_PROXY: Job spooled, printer id: " <<
+ printer_info_cloud_.printer_id << ", job id: " << local_job_id;
if (!shutting_down_) {
local_job_id_ = local_job_id;
UpdateJobStatus(cloud_print::PRINT_JOB_STATUS_IN_PROGRESS, SUCCESS);
@@ -458,7 +481,8 @@ void PrinterJobHandler::JobSpooled(cloud_print::PlatformJobId local_job_id) {
}
void PrinterJobHandler::Shutdown() {
- LOG(INFO) << "CP_PROXY: Printer job handler shutdown, id: " << printer_id_;
+ LOG(INFO) << "CP_PROXY: Printer job handler shutdown, id: " <<
+ printer_info_cloud_.printer_id;
Reset();
shutting_down_ = true;
while (!job_status_updater_list_.empty()) {
@@ -467,13 +491,14 @@ void PrinterJobHandler::Shutdown() {
job_status_updater_list_.front()->Stop();
}
if (delegate_) {
- delegate_->OnPrinterJobHandlerShutdown(this, printer_id_);
+ delegate_->OnPrinterJobHandlerShutdown(this,
+ printer_info_cloud_.printer_id);
}
}
void PrinterJobHandler::HandleServerError(const GURL& url) {
- LOG(INFO) << "CP_PROXY: Handle server error, printer id: " << printer_id_ <<
- ", url: " << url;
+ LOG(INFO) << "CP_PROXY: Handle server error, printer id: " <<
+ printer_info_cloud_.printer_id << ", url: " << url;
Task* task_to_retry = NewRunnableMethod(this,
&PrinterJobHandler::FetchURL, url);
Task* task_on_give_up = NewRunnableMethod(this, next_failure_handler_);
@@ -484,7 +509,8 @@ void PrinterJobHandler::HandleServerError(const GURL& url) {
void PrinterJobHandler::UpdateJobStatus(cloud_print::PrintJobStatus status,
PrintJobError error) {
- LOG(INFO) << "CP_PROXY: Update job status, id: " << printer_id_;
+ LOG(INFO) << "CP_PROXY: Update job status, id: " <<
+ printer_info_cloud_.printer_id;
if (!shutting_down_) {
if (!job_details_.job_id_.empty()) {
LOG(INFO) << "CP_PROXY: Updating status, jod id: " <<
@@ -513,7 +539,7 @@ bool PrinterJobHandler::HandleSuccessStatusUpdateResponse(
int response_code, const ResponseCookies& cookies,
const std::string& data) {
LOG(INFO) << "CP_PROXY: Handle success status update response, id: " <<
- printer_id_;
+ printer_info_cloud_.printer_id;
// If there was a network error or a non-200 response (which, for our purposes
// is the same as a network error), we want to retry.
if (!status.is_success() || (response_code != 200)) {
@@ -545,7 +571,7 @@ bool PrinterJobHandler::HandleFailureStatusUpdateResponse(
int response_code, const ResponseCookies& cookies,
const std::string& data) {
LOG(INFO) << "CP_PROXY: Handle failure status update response, id: " <<
- printer_id_;
+ printer_info_cloud_.printer_id;
// If there was a network error or a non-200 response (which, for our purposes
// is the same as a network error), we want to retry.
if (!status.is_success() || (response_code != 200)) {
@@ -560,7 +586,7 @@ void PrinterJobHandler::MakeServerRequest(const GURL& url,
ResponseHandler response_handler,
FailureHandler failure_handler) {
LOG(INFO) << "CP_PROXY: Printer job handle, make server request, id: " <<
- printer_id_ << ", url: " << url;
+ printer_info_cloud_.printer_id << ", url: " << url;
if (!shutting_down_) {
server_error_count_ = 0;
// Set up the next response handler
diff --git a/chrome/service/cloud_print/printer_job_handler.h b/chrome/service/cloud_print/printer_job_handler.h
index 08d4d76..ea7e9ec 100644
--- a/chrome/service/cloud_print/printer_job_handler.h
+++ b/chrome/service/cloud_print/printer_job_handler.h
@@ -96,10 +96,15 @@ class PrinterJobHandler : public base::RefCountedThreadSafe<PrinterJobHandler>,
virtual ~Delegate() {}
};
+ struct PrinterInfoFromCloud {
+ std::string printer_id;
+ std::string caps_hash;
+ std::string tags_hash;
+ };
+
// Begin public interface
PrinterJobHandler(const cloud_print::PrinterBasicInfo& printer_info,
- const std::string& printer_id,
- const std::string& caps_hash,
+ const PrinterInfoFromCloud& printer_info_from_server,
const std::string& auth_token,
const GURL& cloud_print_server_url,
cloud_print::PrintSystem* print_system,
@@ -225,9 +230,8 @@ class PrinterJobHandler : public base::RefCountedThreadSafe<PrinterJobHandler>,
scoped_ptr<URLFetcher> request_;
scoped_refptr<cloud_print::PrintSystem> print_system_;
cloud_print::PrinterBasicInfo printer_info_;
- std::string printer_id_;
+ PrinterInfoFromCloud printer_info_cloud_;
std::string auth_token_;
- std::string last_caps_hash_;
GURL cloud_print_server_url_;
std::string print_data_url_;
JobDetails job_details_;