diff options
author | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-25 19:16:11 +0000 |
---|---|---|
committer | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-25 19:16:11 +0000 |
commit | 547d51289c28eb9594d7c733be4628d7bf025f1c (patch) | |
tree | 83637af73d024cdfec97b2e3822c78f0727196a2 /chrome/service | |
parent | 97a045f8e6f03e26006e2bef81a384dd126bee4d (diff) | |
download | chromium_src-547d51289c28eb9594d7c733be4628d7bf025f1c.zip chromium_src-547d51289c28eb9594d7c733be4628d7bf025f1c.tar.gz chromium_src-547d51289c28eb9594d7c733be4628d7bf025f1c.tar.bz2 |
Single GenerateProxyId and added printer tags with version info.
GenerateProxyId has same code on all platforms.
Added tags:
__cp__chrome_version
__cp__system_name
__cp__system_version.
BUG=none
Review URL: https://chromiumcodereview.appspot.com/10982017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@158629 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/service')
-rw-r--r-- | chrome/service/cloud_print/cloud_print_connector.cc | 7 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_consts.cc | 7 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_consts.h | 4 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_helpers.cc | 72 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_helpers.h | 14 | ||||
-rw-r--r-- | chrome/service/cloud_print/print_system.cc | 7 | ||||
-rw-r--r-- | chrome/service/cloud_print/print_system_cups.cc | 9 | ||||
-rw-r--r-- | chrome/service/cloud_print/print_system_dummy.cc | 6 | ||||
-rw-r--r-- | chrome/service/cloud_print/print_system_win.cc | 13 | ||||
-rw-r--r-- | chrome/service/cloud_print/printer_job_handler.cc | 9 |
10 files changed, 80 insertions, 68 deletions
diff --git a/chrome/service/cloud_print/cloud_print_connector.cc b/chrome/service/cloud_print/cloud_print_connector.cc index b20d8cb..0688fe4 100644 --- a/chrome/service/cloud_print/cloud_print_connector.cc +++ b/chrome/service/cloud_print/cloud_print_connector.cc @@ -534,11 +534,8 @@ void CloudPrintConnector::OnReceivePrinterCaps( cloud_print::AddMultipartValueForUpload(kPrinterStatusValue, base::StringPrintf("%d", info.printer_status), mime_boundary, std::string(), &post_data); - // Add printer options as tags. - CloudPrintHelpers::GenerateMultipartPostDataForPrinterTags(info.options, - mime_boundary, - &post_data); - + post_data += CloudPrintHelpers::GetPostDataForPrinterTags(info, + mime_boundary); cloud_print::AddMultipartValueForUpload(kPrinterCapsValue, caps_and_defaults.printer_capabilities, mime_boundary, caps_and_defaults.caps_mime_type, &post_data); diff --git a/chrome/service/cloud_print/cloud_print_consts.cc b/chrome/service/cloud_print/cloud_print_consts.cc index ae4c167..5c83d17 100644 --- a/chrome/service/cloud_print/cloud_print_consts.cc +++ b/chrome/service/cloud_print/cloud_print_consts.cc @@ -31,6 +31,13 @@ const char kOAuthCodeValue[] = "authorization_code"; const char kProxyTagPrefix[] = "__cp__"; const char kTagsHashTagName[] = "__cp__tagshash"; const char kTagDryRunFlag[] = "__cp__dry_run"; +// Don't need prefixes. They will be added on submit. +const char kChromeVersionTagName[] = "chrome_version"; +const char kSystemNameTagName[] = "system_name"; +const char kSystemVersionTagName[] = "system_version"; + +extern const char kChromeVersionTagName[]; +extern const char kOsTagName[]; const char kCloudPrintGaiaServiceId[] = "cloudprint"; const char kProxyAuthUserAgent[] = "ChromiumBrowser"; diff --git a/chrome/service/cloud_print/cloud_print_consts.h b/chrome/service/cloud_print/cloud_print_consts.h index 401e9bb..2d9254e 100644 --- a/chrome/service/cloud_print/cloud_print_consts.h +++ b/chrome/service/cloud_print/cloud_print_consts.h @@ -33,6 +33,10 @@ extern const char kOAuthCodeValue[]; extern const char kProxyTagPrefix[]; extern const char kTagsHashTagName[]; extern const char kTagDryRunFlag[]; +extern const char kChromeVersionTagName[]; +extern const char kSystemNameTagName[]; +extern const char kSystemVersionTagName[]; + extern const char kCloudPrintGaiaServiceId[]; extern const char kProxyAuthUserAgent[]; extern const char kCloudPrintPushNotificationsSource[]; diff --git a/chrome/service/cloud_print/cloud_print_helpers.cc b/chrome/service/cloud_print/cloud_print_helpers.cc index 0f60c47..485bac3 100644 --- a/chrome/service/cloud_print/cloud_print_helpers.cc +++ b/chrome/service/cloud_print/cloud_print_helpers.cc @@ -9,12 +9,41 @@ #include "base/rand_util.h" #include "base/string_util.h" #include "base/stringprintf.h" +#include "base/sys_info.h" #include "base/utf_string_conversions.h" +#include "chrome/common/chrome_version_info.h" #include "chrome/common/cloud_print/cloud_print_helpers.h" #include "chrome/service/cloud_print/cloud_print_consts.h" #include "chrome/service/cloud_print/cloud_print_token_store.h" #include "chrome/service/service_process.h" +namespace { + +typedef std::map<std::string, std::string> PrinterTags; + +void GetPrinterTags(const printing::PrinterBasicInfo& printer, + PrinterTags* printer_tags) { + *printer_tags = printer.options; + chrome::VersionInfo version_info; + DCHECK(version_info.is_valid()); + (*printer_tags)[kChromeVersionTagName] = version_info.CreateVersionString(); + using base::SysInfo; + (*printer_tags)[kSystemNameTagName] = SysInfo::OperatingSystemName(); + (*printer_tags)[kSystemVersionTagName] = SysInfo::OperatingSystemVersion(); +} + +std::string HashPrinterTags(const PrinterTags& strings) { + std::string values_list; + PrinterTags::const_iterator it; + for (it = strings.begin(); it != strings.end(); ++it) { + values_list.append(it->first); + values_list.append(it->second); + } + return base::MD5String(values_list); +} + +} // namespace + std::string StringFromJobStatus(cloud_print::PrintJobStatus status) { std::string ret; switch (status) { @@ -159,53 +188,48 @@ GURL CloudPrintHelpers::GetUrlForGetAuthCode(const GURL& cloud_print_server_url, return cloud_print_server_url.ReplaceComponents(replacements); } -std::string CloudPrintHelpers::GenerateHashOfStringMap( - const std::map<std::string, std::string>& string_map) { +std::string CloudPrintHelpers::GetHashOfPrinterTags( + const printing::PrinterBasicInfo& printer) { + PrinterTags printer_tags; + GetPrinterTags(printer, &printer_tags); std::string values_list; - std::map<std::string, std::string>::const_iterator it; - for (it = string_map.begin(); it != string_map.end(); ++it) { + for (PrinterTags::const_iterator it = printer_tags.begin(); + it != printer_tags.end(); ++it) { values_list.append(it->first); values_list.append(it->second); } return base::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) { +std::string CloudPrintHelpers::GetPostDataForPrinterTags( + const printing::PrinterBasicInfo& printer, + const std::string& mime_boundary) { + PrinterTags printer_tags; + GetPrinterTags(printer, &printer_tags); + std::string post_data; + for (PrinterTags::const_iterator 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; cloud_print::AddMultipartValueForUpload(kPrinterTagValue, msg, - mime_boundary, std::string(), post_data); + mime_boundary, std::string(), &post_data); } - std::string tags_hash = base::MD5String(tags_list); std::string tags_hash_msg(kTagsHashTagName); tags_hash_msg += "="; - tags_hash_msg += tags_hash; + tags_hash_msg += HashPrinterTags(printer_tags); cloud_print::AddMultipartValueForUpload(kPrinterTagValue, tags_hash_msg, - mime_boundary, std::string(), post_data); + mime_boundary, std::string(), + &post_data); + return post_data; } bool CloudPrintHelpers::IsDryRunJob(const std::vector<std::string>& tags) { diff --git a/chrome/service/cloud_print/cloud_print_helpers.h b/chrome/service/cloud_print/cloud_print_helpers.h index 743a537..e3bb5b6 100644 --- a/chrome/service/cloud_print/cloud_print_helpers.h +++ b/chrome/service/cloud_print/cloud_print_helpers.h @@ -43,13 +43,13 @@ class CloudPrintHelpers { const std::string& oauth_client_id, const std::string& proxy_id); - // 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); + // Returns an MD5 hash for printer tags. + static std::string GetHashOfPrinterTags( + const printing::PrinterBasicInfo& printer); + // Returns an post data for printer tags. + static std::string GetPostDataForPrinterTags( + const printing::PrinterBasicInfo& printer_info, + const std::string& mime_boundary); // Returns true is tags indicate a dry run (test) job. static bool IsDryRunJob(const std::vector<std::string>& tags); diff --git a/chrome/service/cloud_print/print_system.cc b/chrome/service/cloud_print/print_system.cc index f15d6b8..ac94c80 100644 --- a/chrome/service/cloud_print/print_system.cc +++ b/chrome/service/cloud_print/print_system.cc @@ -4,6 +4,8 @@ #include "chrome/service/cloud_print/print_system.h" +#include "base/guid.h" + namespace cloud_print { PrintJobDetails::PrintJobDetails() @@ -29,4 +31,9 @@ PrintSystem::JobSpooler::~JobSpooler() {} PrintSystem::~PrintSystem() {} +std::string PrintSystem::GenerateProxyId() { + return base::GenerateGUID(); +} + } // namespace cloud_print + diff --git a/chrome/service/cloud_print/print_system_cups.cc b/chrome/service/cloud_print/print_system_cups.cc index 5f0ce60b..f1c3fa3 100644 --- a/chrome/service/cloud_print/print_system_cups.cc +++ b/chrome/service/cloud_print/print_system_cups.cc @@ -727,15 +727,6 @@ std::string PrintSystemCUPS::GetSupportedMimeTypes() { return supported_mime_types_; } -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 - // this in the future. - std::string id("CP_PROXY_"); - id += base::Uint64ToString(base::RandUint64()); - return id; -} - scoped_refptr<PrintSystem> PrintSystem::CreateInstance( const DictionaryValue* print_system_settings) { return new PrintSystemCUPS(print_system_settings); diff --git a/chrome/service/cloud_print/print_system_dummy.cc b/chrome/service/cloud_print/print_system_dummy.cc index 1db2286..c7a3b50 100644 --- a/chrome/service/cloud_print/print_system_dummy.cc +++ b/chrome/service/cloud_print/print_system_dummy.cc @@ -12,11 +12,6 @@ namespace cloud_print { -std::string PrintSystem::GenerateProxyId() { - NOTREACHED(); - return std::string(); -} - scoped_refptr<PrintSystem> PrintSystem::CreateInstance( const base::DictionaryValue* print_system_settings) { NOTREACHED(); @@ -25,3 +20,4 @@ scoped_refptr<PrintSystem> PrintSystem::CreateInstance( } // namespace cloud_print #endif // CP_PRINT_SYSTEM_AVAILABLE + diff --git a/chrome/service/cloud_print/print_system_win.cc b/chrome/service/cloud_print/print_system_win.cc index 7cdf06f..6e92465 100644 --- a/chrome/service/cloud_print/print_system_win.cc +++ b/chrome/service/cloud_print/print_system_win.cc @@ -890,19 +890,6 @@ std::string PrintSystemWin::GetSupportedMimeTypes() { } -std::string PrintSystem::GenerateProxyId() { - GUID proxy_id = {0}; - HRESULT hr = UuidCreate(&proxy_id); - DCHECK(SUCCEEDED(hr)); - wchar_t* proxy_id_as_string = NULL; - UuidToString(&proxy_id, reinterpret_cast<RPC_WSTR *>(&proxy_id_as_string)); - DCHECK(proxy_id_as_string); - std::string ret; - WideToUTF8(proxy_id_as_string, wcslen(proxy_id_as_string), &ret); - RpcStringFree(reinterpret_cast<RPC_WSTR *>(&proxy_id_as_string)); - return ret; -} - scoped_refptr<PrintSystem> PrintSystem::CreateInstance( const base::DictionaryValue* print_system_settings) { return new PrintSystemWin; diff --git a/chrome/service/cloud_print/printer_job_handler.cc b/chrome/service/cloud_print/printer_job_handler.cc index 98b4e9d..0f08948 100644 --- a/chrome/service/cloud_print/printer_job_handler.cc +++ b/chrome/service/cloud_print/printer_job_handler.cc @@ -620,13 +620,12 @@ void PrinterJobHandler::OnReceivePrinterCaps( << ", printer name: " << printer_name; } - std::string tags_hash = - CloudPrintHelpers::GenerateHashOfStringMap(printer_info.options); + std::string tags_hash = CloudPrintHelpers::GetHashOfPrinterTags(printer_info); 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. + post_data += CloudPrintHelpers::GetPostDataForPrinterTags(printer_info, + mime_boundary); + // Remove all the existing proxy tags. std::string cp_tag_wildcard(kProxyTagPrefix); cp_tag_wildcard += ".*"; cloud_print::AddMultipartValueForUpload(kPrinterRemoveTagValue, |