summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chrome_to_mobile_service.cc1
-rw-r--r--chrome/chrome.gyp2
-rw-r--r--chrome/chrome_common.gypi2
-rw-r--r--chrome/chrome_tests_unit.gypi1
-rw-r--r--chrome/common/cloud_print/cloud_print_constants.cc (renamed from chrome/service/cloud_print/cloud_print_consts.cc)50
-rw-r--r--chrome/common/cloud_print/cloud_print_constants.h (renamed from chrome/service/cloud_print/cloud_print_consts.h)59
-rw-r--r--chrome/common/cloud_print/cloud_print_helpers.cc178
-rw-r--r--chrome/common/cloud_print/cloud_print_helpers.h46
-rw-r--r--chrome/common/cloud_print/cloud_print_helpers_unittest.cc132
-rw-r--r--chrome/service/cloud_print/cloud_print_auth.cc14
-rw-r--r--chrome/service/cloud_print/cloud_print_auth.h4
-rw-r--r--chrome/service/cloud_print/cloud_print_connector.cc62
-rw-r--r--chrome/service/cloud_print/cloud_print_connector.h12
-rw-r--r--chrome/service/cloud_print/cloud_print_helpers.cc217
-rw-r--r--chrome/service/cloud_print/cloud_print_helpers.h66
-rw-r--r--chrome/service/cloud_print/cloud_print_helpers_unittest.cc162
-rw-r--r--chrome/service/cloud_print/cloud_print_proxy.cc8
-rw-r--r--chrome/service/cloud_print/cloud_print_proxy.h6
-rw-r--r--chrome/service/cloud_print/cloud_print_proxy_backend.cc5
-rw-r--r--chrome/service/cloud_print/cloud_print_proxy_backend.h4
-rw-r--r--chrome/service/cloud_print/cloud_print_token_store.cc4
-rw-r--r--chrome/service/cloud_print/cloud_print_token_store.h7
-rw-r--r--chrome/service/cloud_print/cloud_print_token_store_unittest.cc3
-rw-r--r--chrome/service/cloud_print/cloud_print_url_fetcher.cc9
-rw-r--r--chrome/service/cloud_print/cloud_print_url_fetcher.h4
-rw-r--r--chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc4
-rw-r--r--chrome/service/cloud_print/cloud_print_wipeout.cc15
-rw-r--r--chrome/service/cloud_print/cloud_print_wipeout.h4
-rw-r--r--chrome/service/cloud_print/connector_settings.cc8
-rw-r--r--chrome/service/cloud_print/connector_settings.h4
-rw-r--r--chrome/service/cloud_print/connector_settings_unittest.cc6
-rw-r--r--chrome/service/cloud_print/job_status_updater.cc28
-rw-r--r--chrome/service/cloud_print/job_status_updater.h14
-rw-r--r--chrome/service/cloud_print/print_system_cups.cc4
-rw-r--r--chrome/service/cloud_print/printer_job_handler.cc55
-rw-r--r--chrome/service/cloud_print/printer_job_handler.h29
-rw-r--r--chrome/service/service_process.cc4
-rw-r--r--chrome/service/service_process.h6
38 files changed, 741 insertions, 498 deletions
diff --git a/chrome/browser/chrome_to_mobile_service.cc b/chrome/browser/chrome_to_mobile_service.cc
index ed42086..de59074 100644
--- a/chrome/browser/chrome_to_mobile_service.cc
+++ b/chrome/browser/chrome_to_mobile_service.cc
@@ -28,6 +28,7 @@
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/cloud_print/cloud_print_constants.h"
#include "chrome/common/cloud_print/cloud_print_helpers.h"
#include "chrome/common/extensions/feature_switch.h"
#include "chrome/common/pref_names.h"
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index d3af49e..c256b08 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -317,8 +317,6 @@
'service/cloud_print/cloud_print_auth.h',
'service/cloud_print/cloud_print_connector.cc',
'service/cloud_print/cloud_print_connector.h',
- 'service/cloud_print/cloud_print_consts.cc',
- 'service/cloud_print/cloud_print_consts.h',
'service/cloud_print/cloud_print_helpers.cc',
'service/cloud_print/cloud_print_helpers.h',
'service/cloud_print/cloud_print_proxy.cc',
diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi
index 97876a3..84d26ef 100644
--- a/chrome/chrome_common.gypi
+++ b/chrome/chrome_common.gypi
@@ -98,6 +98,8 @@
'common/chrome_version_info.h',
'common/cloud_print/cloud_print_class_mac.h',
'common/cloud_print/cloud_print_class_mac.mm',
+ 'common/cloud_print/cloud_print_constants.cc',
+ 'common/cloud_print/cloud_print_constants.h',
'common/cloud_print/cloud_print_helpers.cc',
'common/cloud_print/cloud_print_helpers.h',
'common/cloud_print/cloud_print_proxy_info.cc',
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index 8fe8f20..7f54a94 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -1440,6 +1440,7 @@
'common/cancelable_task_tracker_unittest.cc',
'common/child_process_logging_mac_unittest.mm',
'common/chrome_paths_unittest.cc',
+ 'common/cloud_print/cloud_print_helpers_unittest.cc',
'common/common_param_traits_unittest.cc',
'common/chrome_content_client_unittest.cc',
'common/content_settings_helper_unittest.cc',
diff --git a/chrome/service/cloud_print/cloud_print_consts.cc b/chrome/common/cloud_print/cloud_print_constants.cc
index 5c83d17..7abb89c 100644
--- a/chrome/service/cloud_print/cloud_print_consts.cc
+++ b/chrome/common/cloud_print/cloud_print_constants.cc
@@ -1,10 +1,16 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Constant defines used in the cloud print proxy code
+#include "chrome/common/cloud_print/cloud_print_constants.h"
-#include "chrome/service/cloud_print/cloud_print_consts.h"
+namespace cloud_print {
+
+const char kCloudPrintUserAgent[] = "GoogleCloudPrintProxy";
+const char kChromeCloudPrintProxyHeader[] = "X-CloudPrint-Proxy: Chrome";
+const char kCloudPrintGaiaServiceId[] = "cloudprint";
+const char kProxyAuthUserAgent[] = "ChromiumBrowser";
+const char kCloudPrintPushNotificationsSource[] = "cloudprint.google.com";
const char kProxyIdValue[] = "proxy";
const char kPrinterNameValue[] = "printer";
@@ -16,48 +22,38 @@ const char kPrinterTagValue[] = "tag";
const char kPrinterRemoveTagValue[] = "remove_tag";
const char kMessageTextValue[] = "message";
-// Values in the respone JSON from the cloud print server
+const char kPrintSystemFailedMessageId[] = "printsystemfail";
+const char kGetPrinterCapsFailedMessageId[] = "getprncapsfail";
+const char kEnumPrintersFailedMessageId[] = "enumfail";
+const char kZombiePrinterMessageId[] = "zombieprinter";
+
+const char kSuccessValue[] = "success";
const char kNameValue[] = "name";
const char kIdValue[] = "id";
const char kTicketUrlValue[] = "ticketUrl";
const char kFileUrlValue[] = "fileUrl";
+const char kPrinterListValue[] = "printers";
const char kJobListValue[] = "jobs";
const char kTitleValue[] = "title";
const char kPrinterCapsHashValue[] = "capsHash";
const char kTagsValue[] = "tags";
const char kXMPPJidValue[] = "xmpp_jid";
const char kOAuthCodeValue[] = "authorization_code";
+const char kCreateTimeValue[] = "createTime";
+const char kPrinterTypeValue[] = "type";
-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 kCloudPrintServiceProxyTagPrefix[] = "__cp__";
+const char kCloudPrintServiceTagsHashTagName[] = "__cp__tagshash";
+const char kCloudPrintServiceTagDryRunFlag[] = "__cp__dry_run";
-const char kCloudPrintGaiaServiceId[] = "cloudprint";
-const char kProxyAuthUserAgent[] = "ChromiumBrowser";
-const char kCloudPrintPushNotificationsSource[] = "cloudprint.google.com";
-
-// The string to be appended to the user-agent for cloudprint requests.
-const char kCloudPrintUserAgent[] = "GoogleCloudPrintProxy";
-
-// Reasons for fetching print jobs.
-// Job fetch on proxy startup.
const char kJobFetchReasonStartup[] = "startup";
-// Job fetch because we are polling.
const char kJobFetchReasonPoll[] = "poll";
-// Job fetch on being notified by the server.
const char kJobFetchReasonNotified[] = "notified";
-// Job fetch after a successful print to query for more jobs.
const char kJobFetchReasonQueryMore[] = "querymore";
-// Short message ids for diagnostic messages sent to the server.
-const char kPrintSystemFailedMessageId[] = "printsystemfail";
-const char kGetPrinterCapsFailedMessageId[] = "getprncapsfail";
-const char kEnumPrintersFailedMessageId[] = "enumfail";
-const char kZombiePrinterMessageId[] = "zombieprinter";
+} // namespace cloud_print
+
diff --git a/chrome/service/cloud_print/cloud_print_consts.h b/chrome/common/cloud_print/cloud_print_constants.h
index b5fb24c..4f218e1 100644
--- a/chrome/service/cloud_print/cloud_print_consts.h
+++ b/chrome/common/cloud_print/cloud_print_constants.h
@@ -1,13 +1,26 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_CONSTS_H_
-#define CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_CONSTS_H_
+#ifndef CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_CONSTANTS_H_
+#define CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_CONSTANTS_H_
#include "base/basictypes.h"
-// Constant defines used in the cloud print proxy code
+namespace cloud_print {
+
+// The string to be appended to the user-agent for cloud print requests.
+extern const char kCloudPrintUserAgent[];
+// The proxy header required by cloud print server.
+extern const char kChromeCloudPrintProxyHeader[];
+// The service id of cloud print used in gaia authentication.
+extern const char kCloudPrintGaiaServiceId[];
+// The user agent string used in gaia authentication.
+extern const char kProxyAuthUserAgent[];
+// The source of cloud print notifications.
+extern const char kCloudPrintPushNotificationsSource[];
+
+// Values used to register or update a printer with the cloud print service.
extern const char kProxyIdValue[];
extern const char kPrinterNameValue[];
extern const char kPrinterDescValue[];
@@ -18,37 +31,47 @@ extern const char kPrinterTagValue[];
extern const char kPrinterRemoveTagValue[];
extern const char kMessageTextValue[];
-// Values in the respone JSON from the cloud print server
+// Value of "code" parameter in cloud print "/message" requests.
+extern const char kPrintSystemFailedMessageId[];
+extern const char kGetPrinterCapsFailedMessageId[];
+extern const char kEnumPrintersFailedMessageId[];
+extern const char kZombiePrinterMessageId[];
+
+// Values in the respone JSON from the cloud print server.
+extern const char kSuccessValue[];
extern const char kNameValue[];
extern const char kIdValue[];
extern const char kTicketUrlValue[];
extern const char kFileUrlValue[];
+extern const char kPrinterListValue[];
extern const char kJobListValue[];
extern const char kTitleValue[];
extern const char kPrinterCapsHashValue[];
extern const char kTagsValue[];
extern const char kXMPPJidValue[];
extern const char kOAuthCodeValue[];
+extern const char kCreateTimeValue[];
+extern const char kPrinterTypeValue[];
-extern const char kProxyTagPrefix[];
-extern const char kTagsHashTagName[];
-extern const char kTagDryRunFlag[];
+// Printer tag names. Don't need prefixes. They will be added on submit.
extern const char kChromeVersionTagName[];
extern const char kSystemNameTagName[];
extern const char kSystemVersionTagName[];
-extern const char kCloudPrintGaiaServiceId[];
-extern const char kProxyAuthUserAgent[];
-extern const char kCloudPrintPushNotificationsSource[];
-extern const char kCloudPrintUserAgent[];
+// Tags for cloud print service.
+extern const char kCloudPrintServiceProxyTagPrefix[];
+extern const char kCloudPrintServiceTagsHashTagName[];
+extern const char kCloudPrintServiceTagDryRunFlag[];
+
+// Reasons for fetching print jobs.
+// Job fetch on proxy startup.
extern const char kJobFetchReasonStartup[];
+// Job fetch because we are polling.
extern const char kJobFetchReasonPoll[];
+// Job fetch on being notified by the server.
extern const char kJobFetchReasonNotified[];
+// Job fetch after a successful print to query for more jobs.
extern const char kJobFetchReasonQueryMore[];
-extern const char kPrintSystemFailedMessageId[];
-extern const char kGetPrinterCapsFailedMessageId[];
-extern const char kEnumPrintersFailedMessageId[];
-extern const char kZombiePrinterMessageId[];
// Max retry count for job data fetch requests.
const int kJobDataMaxRetryCount = 5;
@@ -77,5 +100,7 @@ const int kMaxFailedXmppPings = 2;
// we try and refresh it.
const int kTokenRefreshGracePeriodSecs = 5*60; // 5 minutes in seconds
-#endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_CONSTS_H_
+} // namespace cloud_print
+
+#endif // CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_CONSTANTS_H_
diff --git a/chrome/common/cloud_print/cloud_print_helpers.cc b/chrome/common/cloud_print/cloud_print_helpers.cc
index dbe7544..7a25c08 100644
--- a/chrome/common/cloud_print/cloud_print_helpers.cc
+++ b/chrome/common/cloud_print/cloud_print_helpers.cc
@@ -6,19 +6,47 @@
#include "base/json/json_reader.h"
#include "base/logging.h"
+#include "base/md5.h"
#include "base/memory/scoped_ptr.h"
#include "base/rand_util.h"
#include "base/stringprintf.h"
+#include "base/sys_info.h"
#include "base/values.h"
+#include "chrome/common/chrome_version_info.h"
+#include "chrome/common/cloud_print/cloud_print_constants.h"
#include "googleurl/src/gurl.h"
namespace cloud_print {
-const char kPrinterListValue[] = "printers";
-const char kSuccessValue[] = "success";
+namespace {
-// Certain cloud print requests require Chrome's X-CloudPrint-Proxy header.
-const char kChromeCloudPrintProxyHeader[] = "X-CloudPrint-Proxy: Chrome";
+// Returns printer tags generated from |printer_tags| and the default tags
+// required by cloud print server.
+PrinterTags PreparePrinterTags(const PrinterTags& printer_tags) {
+ PrinterTags printer_tags_out = printer_tags;
+ chrome::VersionInfo version_info;
+ DCHECK(version_info.is_valid());
+ printer_tags_out[kChromeVersionTagName] =
+ version_info.CreateVersionString();
+ printer_tags_out[kSystemNameTagName] =
+ base::SysInfo::OperatingSystemName();
+ printer_tags_out[kSystemVersionTagName] =
+ base::SysInfo::OperatingSystemVersion();
+ return printer_tags_out;
+}
+
+// Returns the hash of |printer_tags|.
+std::string HashPrinterTags(const PrinterTags& printer_tags) {
+ std::string values_list;
+ PrinterTags::const_iterator it;
+ for (it = printer_tags.begin(); it != printer_tags.end(); ++it) {
+ values_list.append(it->first);
+ values_list.append(it->second);
+ }
+ return base::MD5String(values_list);
+}
+
+} // namespace
std::string AppendPathToUrl(const GURL& url, const std::string& path) {
DCHECK_NE(path[0], '/');
@@ -43,6 +71,105 @@ GURL GetUrlForSubmit(const GURL& cloud_print_server_url) {
return cloud_print_server_url.ReplaceComponents(replacements);
}
+GURL GetUrlForPrinterList(const GURL& cloud_print_server_url,
+ const std::string& proxy_id) {
+ std::string path(AppendPathToUrl(cloud_print_server_url, "list"));
+ GURL::Replacements replacements;
+ replacements.SetPathStr(path);
+ std::string query = StringPrintf("proxy=%s", proxy_id.c_str());
+ replacements.SetQueryStr(query);
+ return cloud_print_server_url.ReplaceComponents(replacements);
+}
+
+GURL GetUrlForPrinterRegistration(const GURL& cloud_print_server_url) {
+ std::string path(AppendPathToUrl(cloud_print_server_url, "register"));
+ GURL::Replacements replacements;
+ replacements.SetPathStr(path);
+ return cloud_print_server_url.ReplaceComponents(replacements);
+}
+
+GURL GetUrlForPrinterUpdate(const GURL& cloud_print_server_url,
+ const std::string& printer_id) {
+ std::string path(AppendPathToUrl(cloud_print_server_url, "update"));
+ GURL::Replacements replacements;
+ replacements.SetPathStr(path);
+ std::string query = StringPrintf("printerid=%s", printer_id.c_str());
+ replacements.SetQueryStr(query);
+ return cloud_print_server_url.ReplaceComponents(replacements);
+}
+
+GURL GetUrlForPrinterDelete(const GURL& cloud_print_server_url,
+ const std::string& printer_id,
+ const std::string& reason) {
+ std::string path(AppendPathToUrl(cloud_print_server_url, "delete"));
+ GURL::Replacements replacements;
+ replacements.SetPathStr(path);
+ std::string query = StringPrintf(
+ "printerid=%s&reason=%s", printer_id.c_str(), reason.c_str());
+ replacements.SetQueryStr(query);
+ return cloud_print_server_url.ReplaceComponents(replacements);
+}
+
+GURL GetUrlForJobFetch(const GURL& cloud_print_server_url,
+ const std::string& printer_id,
+ const std::string& reason) {
+ std::string path(AppendPathToUrl(cloud_print_server_url, "fetch"));
+ GURL::Replacements replacements;
+ replacements.SetPathStr(path);
+ std::string query = StringPrintf(
+ "printerid=%s&deb=%s", printer_id.c_str(), reason.c_str());
+ replacements.SetQueryStr(query);
+ return cloud_print_server_url.ReplaceComponents(replacements);
+}
+
+
+GURL GetUrlForJobDelete(const GURL& cloud_print_server_url,
+ const std::string& job_id) {
+ std::string path(AppendPathToUrl(cloud_print_server_url, "deletejob"));
+ GURL::Replacements replacements;
+ replacements.SetPathStr(path);
+ std::string query = StringPrintf("jobid=%s", job_id.c_str());
+ replacements.SetQueryStr(query);
+ return cloud_print_server_url.ReplaceComponents(replacements);
+}
+
+GURL GetUrlForJobStatusUpdate(const GURL& cloud_print_server_url,
+ const std::string& job_id,
+ const std::string& status_string) {
+ std::string path(AppendPathToUrl(cloud_print_server_url, "control"));
+ GURL::Replacements replacements;
+ replacements.SetPathStr(path);
+ std::string query = StringPrintf(
+ "jobid=%s&status=%s", job_id.c_str(), status_string.c_str());
+ replacements.SetQueryStr(query);
+ return cloud_print_server_url.ReplaceComponents(replacements);
+}
+
+GURL GetUrlForUserMessage(const GURL& cloud_print_server_url,
+ const std::string& message_id) {
+ std::string path(AppendPathToUrl(cloud_print_server_url, "message"));
+ GURL::Replacements replacements;
+ replacements.SetPathStr(path);
+ std::string query = StringPrintf("code=%s", message_id.c_str());
+ replacements.SetQueryStr(query);
+ return cloud_print_server_url.ReplaceComponents(replacements);
+}
+
+GURL GetUrlForGetAuthCode(const GURL& cloud_print_server_url,
+ const std::string& oauth_client_id,
+ const std::string& proxy_id) {
+ // We use the internal API "createrobot" instead of "getauthcode". This API
+ // will add the robot as owner to all the existing printers for this user.
+ std::string path(AppendPathToUrl(cloud_print_server_url, "createrobot"));
+ GURL::Replacements replacements;
+ replacements.SetPathStr(path);
+ std::string query = StringPrintf("oauth_client_id=%s&proxy=%s",
+ oauth_client_id.c_str(),
+ proxy_id.c_str());
+ replacements.SetQueryStr(query);
+ return cloud_print_server_url.ReplaceComponents(replacements);
+}
+
bool ParseResponseJSON(const std::string& response_data,
bool* succeeded,
DictionaryValue** response_dict) {
@@ -56,7 +183,7 @@ bool ParseResponseJSON(const std::string& response_data,
scoped_ptr<DictionaryValue> response_dict_local(
static_cast<DictionaryValue*>(message_value.release()));
if (succeeded &&
- !response_dict_local->GetBoolean(cloud_print::kSuccessValue, succeeded))
+ !response_dict_local->GetBoolean(kSuccessValue, succeeded))
*succeeded = false;
if (response_dict)
*response_dict = response_dict_local.release();
@@ -83,6 +210,10 @@ void AddMultipartValueForUpload(const std::string& value_name,
post_data->append(StringPrintf("\r\n%s\r\n", value.c_str()));
}
+std::string GetMultipartMimeType(const std::string& mime_boundary) {
+ return std::string("multipart/form-data; boundary=") + mime_boundary;
+}
+
// Create a MIME boundary marker (27 '-' characters followed by 16 hex digits).
void CreateMimeBoundaryForUpload(std::string* out) {
int r1 = base::RandInt(0, kint32max);
@@ -90,4 +221,41 @@ void CreateMimeBoundaryForUpload(std::string* out) {
base::SStringPrintf(out, "---------------------------%08X%08X", r1, r2);
}
+std::string GetHashOfPrinterTags(const PrinterTags& printer_tags) {
+ return HashPrinterTags(PreparePrinterTags(printer_tags));
+}
+
+std::string GetPostDataForPrinterTags(
+ const PrinterTags& printer_tags,
+ const std::string& mime_boundary,
+ const std::string& proxy_tag_prefix,
+ const std::string& tags_hash_tag_name) {
+ PrinterTags printer_tags_prepared = PreparePrinterTags(printer_tags);
+ std::string post_data;
+ for (PrinterTags::const_iterator it = printer_tags_prepared.begin();
+ it != printer_tags_prepared.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();
+ }
+ // All our tags have a special prefix to identify them as such.
+ std::string msg = StringPrintf("%s%s=%s",
+ proxy_tag_prefix.c_str(), it->first.c_str(), it->second.c_str());
+ AddMultipartValueForUpload(kPrinterTagValue, msg, mime_boundary,
+ std::string(), &post_data);
+ }
+ std::string tags_hash_msg = StringPrintf("%s=%s",
+ tags_hash_tag_name.c_str(),
+ HashPrinterTags(printer_tags_prepared).c_str());
+ AddMultipartValueForUpload(kPrinterTagValue, tags_hash_msg, mime_boundary,
+ std::string(), &post_data);
+ return post_data;
+}
+
+std::string GetCloudPrintAuthHeader(const std::string& auth_token) {
+ return StringPrintf("Authorization: OAuth %s", auth_token.c_str());
+}
+
} // namespace cloud_print
diff --git a/chrome/common/cloud_print/cloud_print_helpers.h b/chrome/common/cloud_print/cloud_print_helpers.h
index 1b4a15e..abbf092 100644
--- a/chrome/common/cloud_print/cloud_print_helpers.h
+++ b/chrome/common/cloud_print/cloud_print_helpers.h
@@ -5,7 +5,9 @@
#ifndef CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_
#define CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_
+#include <map>
#include <string>
+#include <vector>
class GURL;
@@ -16,11 +18,8 @@ class DictionaryValue;
// Helper consts and methods for both cloud print and chrome browser.
namespace cloud_print {
-// Values in the respone JSON from the cloud print server
-extern const char kPrinterListValue[];
-extern const char kSuccessValue[];
-
-extern const char kChromeCloudPrintProxyHeader[];
+// A map representing printer tags.
+typedef std::map<std::string, std::string> PrinterTags;
// Appends a relative path to the url making sure to append a '/' if the
// URL's path does not end with a slash. It is assumed that |path| does not
@@ -32,6 +31,27 @@ std::string AppendPathToUrl(const GURL& url, const std::string& path);
GURL GetUrlForSearch(const GURL& cloud_print_server_url);
GURL GetUrlForSubmit(const GURL& cloud_print_server_url);
+GURL GetUrlForPrinterList(const GURL& cloud_print_server_url,
+ const std::string& proxy_id);
+GURL GetUrlForPrinterRegistration(const GURL& cloud_print_server_url);
+GURL GetUrlForPrinterUpdate(const GURL& cloud_print_server_url,
+ const std::string& printer_id);
+GURL GetUrlForPrinterDelete(const GURL& cloud_print_server_url,
+ const std::string& printer_id,
+ const std::string& reason);
+GURL GetUrlForJobFetch(const GURL& cloud_print_server_url,
+ const std::string& printer_id,
+ const std::string& reason);
+GURL GetUrlForJobDelete(const GURL& cloud_print_server_url,
+ const std::string& job_id);
+GURL GetUrlForJobStatusUpdate(const GURL& cloud_print_server_url,
+ const std::string& job_id,
+ const std::string& status_string);
+GURL GetUrlForUserMessage(const GURL& cloud_print_server_url,
+ const std::string& message_id);
+GURL GetUrlForGetAuthCode(const GURL& cloud_print_server_url,
+ const std::string& oauth_client_id,
+ const std::string& proxy_id);
// Parses the response data for any cloud print server request. The method
// returns false if there was an error in parsing the JSON. The succeeded
@@ -48,9 +68,25 @@ void AddMultipartValueForUpload(const std::string& value_name,
const std::string& content_type,
std::string* post_data);
+// Returns the MIME type of multipart with |mime_boundary|.
+std::string GetMultipartMimeType(const std::string& mime_boundary);
+
// Create a MIME boundary marker (27 '-' characters followed by 16 hex digits).
void CreateMimeBoundaryForUpload(std::string *out);
+// Returns an MD5 hash for |printer_tags| and the default required tags.
+std::string GetHashOfPrinterTags(const PrinterTags& printer_tags);
+
+// Returns the post data for |printer_tags| and the default required tags.
+std::string GetPostDataForPrinterTags(
+ const PrinterTags& printer_tags,
+ const std::string& mime_boundary,
+ const std::string& proxy_tag_prefix,
+ const std::string& tags_hash_tag_name);
+
+// Get the cloud print auth header from |auth_token|.
+std::string GetCloudPrintAuthHeader(const std::string& auth_token);
+
} // namespace cloud_print
#endif // CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_
diff --git a/chrome/common/cloud_print/cloud_print_helpers_unittest.cc b/chrome/common/cloud_print/cloud_print_helpers_unittest.cc
new file mode 100644
index 0000000..cc0f995
--- /dev/null
+++ b/chrome/common/cloud_print/cloud_print_helpers_unittest.cc
@@ -0,0 +1,132 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/cloud_print/cloud_print_helpers.h"
+
+#include "base/md5.h"
+#include "base/stringprintf.h"
+#include "base/sys_info.h"
+#include "chrome/common/chrome_version_info.h"
+#include "googleurl/src/gurl.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace cloud_print {
+
+namespace {
+
+void CheckURLs(const GURL& server_base_url) {
+ std::string expected_url_base = server_base_url.spec();
+ if (expected_url_base[expected_url_base.length() - 1] != '/')
+ expected_url_base += "/";
+
+ EXPECT_EQ(base::StringPrintf("%ssearch", expected_url_base.c_str()),
+ GetUrlForSearch(server_base_url).spec());
+
+ EXPECT_EQ(base::StringPrintf("%ssubmit", expected_url_base.c_str()),
+ GetUrlForSubmit(server_base_url).spec());
+
+ EXPECT_EQ(base::StringPrintf("%slist?proxy=demoproxy",
+ expected_url_base.c_str()),
+ GetUrlForPrinterList(
+ server_base_url, std::string("demoproxy")).spec());
+
+ EXPECT_EQ(base::StringPrintf("%sregister", expected_url_base.c_str()),
+ GetUrlForPrinterRegistration(server_base_url).spec());
+
+ EXPECT_EQ(base::StringPrintf("%supdate?printerid=printeridfoo",
+ expected_url_base.c_str()),
+ GetUrlForPrinterUpdate(server_base_url, "printeridfoo").spec());
+
+ EXPECT_EQ(base::StringPrintf("%sdelete?printerid=printeridbar&reason=deleted",
+ expected_url_base.c_str()),
+ GetUrlForPrinterDelete(
+ server_base_url, "printeridbar", "deleted").spec());
+
+ EXPECT_EQ(base::StringPrintf("%sfetch?printerid=myprinter&deb=nogoodreason",
+ expected_url_base.c_str()),
+ GetUrlForJobFetch(
+ server_base_url, "myprinter", "nogoodreason").spec());
+
+ EXPECT_EQ(base::StringPrintf("%sdeletejob?jobid=myprinter",
+ expected_url_base.c_str()),
+ GetUrlForJobDelete(server_base_url, "myprinter").spec());
+
+ EXPECT_EQ(base::StringPrintf("%scontrol?jobid=myprinter&status=s1",
+ expected_url_base.c_str()),
+ GetUrlForJobStatusUpdate(
+ server_base_url, "myprinter", "s1").spec());
+
+ EXPECT_EQ(base::StringPrintf("%smessage?code=testmsg",
+ expected_url_base.c_str()),
+ GetUrlForUserMessage(server_base_url, "testmsg").spec());
+
+ EXPECT_EQ(base::StringPrintf(
+ "%screaterobot?oauth_client_id=democlientid&proxy=demoproxy",
+ expected_url_base.c_str()),
+ GetUrlForGetAuthCode(
+ server_base_url, "democlientid", "demoproxy").spec());
+}
+
+} // namespace
+
+TEST(CloudPrintHelpersTest, GetURLs) {
+ CheckURLs(GURL("https://www.google.com/cloudprint"));
+ CheckURLs(GURL("https://www.google.com/cloudprint/"));
+ CheckURLs(GURL("http://www.myprinterserver.com"));
+ CheckURLs(GURL("http://www.myprinterserver.com/"));
+}
+
+TEST(CloudPrintHelpersTest, GetHashOfPrinterTags) {
+ PrinterTags printer_tags;
+ printer_tags["tag1"] = std::string("value1");
+ printer_tags["tag2"] = std::string("value2");
+
+ chrome::VersionInfo version_info;
+ std::string expected_list_string = StringPrintf(
+ "chrome_version%ssystem_name%ssystem_version%stag1value1tag2value2",
+ version_info.CreateVersionString().c_str(),
+ base::SysInfo::OperatingSystemName().c_str(),
+ base::SysInfo::OperatingSystemVersion().c_str());
+ EXPECT_EQ(base::MD5String(expected_list_string),
+ GetHashOfPrinterTags(printer_tags));
+}
+
+TEST(CloudPrintHelpersTest, GetPostDataForPrinterTags) {
+ PrinterTags printer_tags;
+ printer_tags["tag1"] = std::string("value1");
+ printer_tags["tag2"] = std::string("value2");
+
+ chrome::VersionInfo version_info;
+ std::string expected = base::StringPrintf(
+ "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
+ "\r\n\r\n__test__chrome_version=%s\r\n"
+ "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
+ "\r\n\r\n__test__system_name=%s\r\n"
+ "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
+ "\r\n\r\n__test__system_version=%s\r\n"
+ "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
+ "\r\n\r\n__test__tag1=value1\r\n"
+ "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
+ "\r\n\r\n__test__tag2=value2\r\n"
+ "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
+ "\r\n\r\n__test__tagshash=%s\r\n",
+ version_info.CreateVersionString().c_str(),
+ base::SysInfo::OperatingSystemName().c_str(),
+ base::SysInfo::OperatingSystemVersion().c_str(),
+ GetHashOfPrinterTags(printer_tags).c_str());
+
+ EXPECT_EQ(expected, GetPostDataForPrinterTags(
+ printer_tags,
+ std::string("test_mime_boundary"),
+ std::string("__test__"),
+ std::string("__test__tagshash")));
+}
+
+TEST(CloudPrintHelpersTest, GetCloudPrintAuthHeader) {
+ std::string test_auth("testauth");
+ EXPECT_EQ("Authorization: OAuth testauth",
+ GetCloudPrintAuthHeader(test_auth));
+}
+
+} // namespace cloud_print
diff --git a/chrome/service/cloud_print/cloud_print_auth.cc b/chrome/service/cloud_print/cloud_print_auth.cc
index ab51c04..6c273bb 100644
--- a/chrome/service/cloud_print/cloud_print_auth.cc
+++ b/chrome/service/cloud_print/cloud_print_auth.cc
@@ -6,14 +6,16 @@
#include "base/bind.h"
#include "base/string_util.h"
-#include "chrome/service/cloud_print/cloud_print_consts.h"
-#include "chrome/service/cloud_print/cloud_print_helpers.h"
+#include "chrome/common/cloud_print/cloud_print_constants.h"
+#include "chrome/common/cloud_print/cloud_print_helpers.h"
#include "chrome/service/cloud_print/cloud_print_token_store.h"
#include "chrome/service/gaia/service_gaia_authenticator.h"
#include "chrome/service/net/service_url_request_context.h"
#include "chrome/service/service_process.h"
#include "google_apis/gaia/gaia_urls.h"
+namespace cloud_print {
+
CloudPrintAuth::CloudPrintAuth(
Client* client,
const GURL& cloud_print_server_url,
@@ -65,10 +67,9 @@ void CloudPrintAuth::AuthenticateWithToken(
client_login_token_ = cloud_print_token;
// We need to get the credentials of the robot here.
- GURL get_authcode_url =
- CloudPrintHelpers::GetUrlForGetAuthCode(cloud_print_server_url_,
- oauth_client_info_.client_id,
- proxy_id_);
+ GURL get_authcode_url = GetUrlForGetAuthCode(cloud_print_server_url_,
+ oauth_client_info_.client_id,
+ proxy_id_);
request_ = new CloudPrintURLFetcher;
request_->StartGetRequest(get_authcode_url,
this,
@@ -197,3 +198,4 @@ std::string CloudPrintAuth::GetAuthHeader() {
CloudPrintAuth::~CloudPrintAuth() {}
+} // namespace cloud_print
diff --git a/chrome/service/cloud_print/cloud_print_auth.h b/chrome/service/cloud_print/cloud_print_auth.h
index cefcbe3..1107694 100644
--- a/chrome/service/cloud_print/cloud_print_auth.h
+++ b/chrome/service/cloud_print/cloud_print_auth.h
@@ -12,6 +12,8 @@
#include "google_apis/gaia/gaia_oauth_client.h"
#include "googleurl/src/gurl.h"
+namespace cloud_print {
+
// CloudPrintAuth is a class to handle login, token refresh, and other
// authentication tasks for Cloud Print.
// CloudPrintAuth will create new robot account for this proxy if needed.
@@ -109,5 +111,7 @@ class CloudPrintAuth
DISALLOW_COPY_AND_ASSIGN(CloudPrintAuth);
};
+} // namespace cloud_print
+
#endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_AUTH_H_
diff --git a/chrome/service/cloud_print/cloud_print_connector.cc b/chrome/service/cloud_print/cloud_print_connector.cc
index fa927f3..8338f22 100644
--- a/chrome/service/cloud_print/cloud_print_connector.cc
+++ b/chrome/service/cloud_print/cloud_print_connector.cc
@@ -13,12 +13,14 @@
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
+#include "chrome/common/cloud_print/cloud_print_constants.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_helpers.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
+namespace cloud_print {
+
CloudPrintConnector::CloudPrintConnector(Client* client,
const ConnectorSettings& settings)
: client_(client),
@@ -29,13 +31,13 @@ CloudPrintConnector::CloudPrintConnector(Client* client,
bool CloudPrintConnector::InitPrintSystem() {
if (print_system_.get())
return true;
- print_system_ = cloud_print::PrintSystem::CreateInstance(
+ print_system_ = PrintSystem::CreateInstance(
settings_.print_system_settings());
if (!print_system_.get()) {
NOTREACHED();
return false; // No memory.
}
- cloud_print::PrintSystem::PrintSystemResult result = print_system_->Init();
+ PrintSystem::PrintSystemResult result = print_system_->Init();
if (!result.succeeded()) {
print_system_ = NULL;
// We could not initialize the print system. We need to notify the server.
@@ -164,7 +166,7 @@ CloudPrintURLFetcher::ResponseAction CloudPrintConnector::OnRequestAuthError() {
}
std::string CloudPrintConnector::GetAuthHeader() {
- return CloudPrintHelpers::GetCloudPrintAuthHeaderFromStore();
+ return GetCloudPrintAuthHeaderFromStore();
}
CloudPrintConnector::~CloudPrintConnector() {}
@@ -187,7 +189,7 @@ CloudPrintConnector::HandlePrinterListResponse(
// Get list of the printers from the print system.
printing::PrinterList local_printers;
- cloud_print::PrintSystem::PrintSystemResult result =
+ PrintSystem::PrintSystemResult result =
print_system_->EnumeratePrinters(&local_printers);
bool full_list = result.succeeded();
if (!full_list) {
@@ -202,8 +204,7 @@ CloudPrintConnector::HandlePrinterListResponse(
// Go through the list of the cloud printers and init print job handlers.
ListValue* printer_list = NULL;
// There may be no "printers" value in the JSON
- if (json_data->GetList(cloud_print::kPrinterListValue, &printer_list)
- && printer_list) {
+ if (json_data->GetList(kPrinterListValue, &printer_list) && printer_list) {
for (size_t index = 0; index < printer_list->GetSize(); index++) {
DictionaryValue* printer_data = NULL;
if (printer_list->GetDictionary(index, &printer_data)) {
@@ -273,7 +274,7 @@ CloudPrintConnector::HandleRegisterPrinterResponse(
if (succeeded) {
ListValue* printer_list = NULL;
// There should be a "printers" value in the JSON
- if (json_data->GetList(cloud_print::kPrinterListValue, &printer_list)) {
+ if (json_data->GetList(kPrinterListValue, &printer_list)) {
DictionaryValue* printer_data = NULL;
if (printer_list->GetDictionary(0, &printer_data))
InitJobHandlerForPrinter(printer_data);
@@ -308,12 +309,11 @@ void CloudPrintConnector::ReportUserMessage(const std::string& message_id,
// This is a fire and forget type of function.
// Result of this request will be ignored.
std::string mime_boundary;
- cloud_print::CreateMimeBoundaryForUpload(&mime_boundary);
- GURL url = CloudPrintHelpers::GetUrlForUserMessage(settings_.server_url(),
- message_id);
+ CreateMimeBoundaryForUpload(&mime_boundary);
+ GURL url = GetUrlForUserMessage(settings_.server_url(), message_id);
std::string post_data;
- cloud_print::AddMultipartValueForUpload(kMessageTextValue, failure_msg,
- mime_boundary, std::string(), &post_data);
+ AddMultipartValueForUpload(kMessageTextValue, failure_msg, mime_boundary,
+ std::string(), &post_data);
// Terminate the request body
post_data.append("--" + mime_boundary + "--\r\n");
std::string mime_type("multipart/form-data; boundary=");
@@ -366,7 +366,7 @@ void CloudPrintConnector::InitJobHandlerForPrinter(
for (size_t index = 0; index < tags_list->GetSize(); index++) {
std::string tag;
if (tags_list->GetString(index, &tag) &&
- StartsWithASCII(tag, kTagsHashTagName, false)) {
+ StartsWithASCII(tag, kCloudPrintServiceTagsHashTagName, false)) {
std::vector<std::string> tag_parts;
base::SplitStringDontTrim(tag, '=', &tag_parts);
DCHECK_EQ(tag_parts.size(), 2U);
@@ -451,7 +451,7 @@ void CloudPrintConnector::ContinuePendingTaskProcessing() {
}
void CloudPrintConnector::OnPrintersAvailable() {
- GURL printer_list_url = CloudPrintHelpers::GetUrlForPrinterList(
+ GURL printer_list_url = GetUrlForPrinterList(
settings_.server_url(), settings_.proxy_id());
StartGetRequest(printer_list_url,
kCloudPrintRegisterMaxRetryCount,
@@ -488,7 +488,7 @@ void CloudPrintConnector::OnPrinterDelete(const std::string& printer_id) {
// TODO(gene): We probably should not try indefinitely here. Just once or
// twice should be enough.
// Bug: http://code.google.com/p/chromium/issues/detail?id=101850
- GURL url = CloudPrintHelpers::GetUrlForPrinterDelete(
+ GURL url = GetUrlForPrinterDelete(
settings_.server_url(), printer_id, "printer_deleted");
StartGetRequest(url,
kCloudPrintAPIMaxRetryCount,
@@ -523,29 +523,28 @@ void CloudPrintConnector::OnReceivePrinterCaps(
DCHECK(IsSamePrinter(info.printer_name, printer_name));
std::string mime_boundary;
- cloud_print::CreateMimeBoundaryForUpload(&mime_boundary);
+ CreateMimeBoundaryForUpload(&mime_boundary);
std::string post_data;
- cloud_print::AddMultipartValueForUpload(kProxyIdValue, settings_.proxy_id(),
- mime_boundary, std::string(), &post_data);
- cloud_print::AddMultipartValueForUpload(kPrinterNameValue, info.printer_name,
- mime_boundary, std::string(), &post_data);
- cloud_print::AddMultipartValueForUpload(kPrinterDescValue,
- info.printer_description, mime_boundary, std::string() , &post_data);
- cloud_print::AddMultipartValueForUpload(kPrinterStatusValue,
+ AddMultipartValueForUpload(kProxyIdValue,
+ settings_.proxy_id(), mime_boundary, std::string(), &post_data);
+ AddMultipartValueForUpload(kPrinterNameValue,
+ info.printer_name, mime_boundary, std::string(), &post_data);
+ AddMultipartValueForUpload(kPrinterDescValue,
+ info.printer_description, mime_boundary, std::string(), &post_data);
+ AddMultipartValueForUpload(kPrinterStatusValue,
base::StringPrintf("%d", info.printer_status),
mime_boundary, std::string(), &post_data);
- post_data += CloudPrintHelpers::GetPostDataForPrinterTags(info,
- mime_boundary);
- cloud_print::AddMultipartValueForUpload(kPrinterCapsValue,
+ post_data += GetPostDataForPrinterInfo(info, mime_boundary);
+ AddMultipartValueForUpload(kPrinterCapsValue,
caps_and_defaults.printer_capabilities, mime_boundary,
caps_and_defaults.caps_mime_type, &post_data);
- cloud_print::AddMultipartValueForUpload(kPrinterDefaultsValue,
+ AddMultipartValueForUpload(kPrinterDefaultsValue,
caps_and_defaults.printer_defaults, mime_boundary,
caps_and_defaults.defaults_mime_type, &post_data);
// Send a hash of the printer capabilities to the server. We will use this
// later to check if the capabilities have changed
- cloud_print::AddMultipartValueForUpload(kPrinterCapsHashValue,
+ AddMultipartValueForUpload(kPrinterCapsHashValue,
base::MD5String(caps_and_defaults.printer_capabilities),
mime_boundary, std::string(), &post_data);
@@ -554,8 +553,7 @@ void CloudPrintConnector::OnReceivePrinterCaps(
std::string mime_type("multipart/form-data; boundary=");
mime_type += mime_boundary;
- GURL post_url = CloudPrintHelpers::GetUrlForPrinterRegistration(
- settings_.server_url());
+ GURL post_url = GetUrlForPrinterRegistration(settings_.server_url());
StartPostRequest(post_url,
kCloudPrintAPIMaxRetryCount,
mime_type,
@@ -567,3 +565,5 @@ bool CloudPrintConnector::IsSamePrinter(const std::string& name1,
const std::string& name2) const {
return (0 == base::strcasecmp(name1.c_str(), name2.c_str()));
}
+
+} // namespace cloud_print
diff --git a/chrome/service/cloud_print/cloud_print_connector.h b/chrome/service/cloud_print/cloud_print_connector.h
index 748e225..ee80650 100644
--- a/chrome/service/cloud_print/cloud_print_connector.h
+++ b/chrome/service/cloud_print/cloud_print_connector.h
@@ -15,6 +15,8 @@
#include "chrome/service/cloud_print/print_system.h"
#include "chrome/service/cloud_print/printer_job_handler.h"
+namespace cloud_print {
+
// CloudPrintConnector handles top printer management tasks.
// - Matching local and cloud printers
// - Registration of local printers
@@ -24,7 +26,7 @@
// CloudPrintConnector will notify client over Client interface.
class CloudPrintConnector
: public base::RefCountedThreadSafe<CloudPrintConnector>,
- private cloud_print::PrintServerWatcherDelegate,
+ private PrintServerWatcherDelegate,
private PrinterJobHandlerDelegate,
private CloudPrintURLFetcherDelegate {
public:
@@ -78,7 +80,7 @@ class CloudPrintConnector
};
virtual ~CloudPrintConnector();
- // cloud_print::PrintServerWatcherDelegate implementation
+ // PrintServerWatcherDelegate implementation
virtual void OnPrinterAdded() OVERRIDE;
// PrinterJobHandler::Delegate implementation
virtual void OnPrinterDeleted(const std::string& printer_name) OVERRIDE;
@@ -162,9 +164,9 @@ class CloudPrintConnector
// Connector settings.
ConnectorSettings settings_;
// Pointer to current print system.
- scoped_refptr<cloud_print::PrintSystem> print_system_;
+ scoped_refptr<PrintSystem> print_system_;
// Watcher for print system updates.
- scoped_refptr<cloud_print::PrintSystem::PrintServerWatcher>
+ scoped_refptr<PrintSystem::PrintServerWatcher>
print_server_watcher_;
// A map of printer id to job handler.
typedef std::map<std::string, scoped_refptr<PrinterJobHandler> >
@@ -182,5 +184,7 @@ class CloudPrintConnector
DISALLOW_COPY_AND_ASSIGN(CloudPrintConnector);
};
+} // namespace cloud_print
+
#endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_CONNECTOR_H_
diff --git a/chrome/service/cloud_print/cloud_print_helpers.cc b/chrome/service/cloud_print/cloud_print_helpers.cc
index 485bac3..6c38a65 100644
--- a/chrome/service/cloud_print/cloud_print_helpers.cc
+++ b/chrome/service/cloud_print/cloud_print_helpers.cc
@@ -4,46 +4,14 @@
#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/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_constants.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) {
@@ -64,88 +32,23 @@ std::string StringFromJobStatus(cloud_print::PrintJobStatus status) {
return ret;
}
-GURL CloudPrintHelpers::GetUrlForPrinterRegistration(
- const GURL& cloud_print_server_url) {
- std::string path(
- cloud_print::AppendPathToUrl(cloud_print_server_url, "register"));
- GURL::Replacements replacements;
- replacements.SetPathStr(path);
- return cloud_print_server_url.ReplaceComponents(replacements);
-}
-
-GURL CloudPrintHelpers::GetUrlForPrinterUpdate(
- const GURL& cloud_print_server_url,
- const std::string& printer_id) {
- std::string path(
- cloud_print::AppendPathToUrl(cloud_print_server_url, "update"));
- GURL::Replacements replacements;
- replacements.SetPathStr(path);
- std::string query = StringPrintf("printerid=%s", printer_id.c_str());
- replacements.SetQueryStr(query);
- return cloud_print_server_url.ReplaceComponents(replacements);
-}
-
-GURL CloudPrintHelpers::GetUrlForPrinterDelete(
- const GURL& cloud_print_server_url,
- const std::string& printer_id,
- const std::string& reason) {
- std::string path(
- cloud_print::AppendPathToUrl(cloud_print_server_url, "delete"));
- GURL::Replacements replacements;
- replacements.SetPathStr(path);
- std::string query = StringPrintf("printerid=%s&reason=%s",
- printer_id.c_str(), reason.c_str());
- replacements.SetQueryStr(query);
- return cloud_print_server_url.ReplaceComponents(replacements);
-}
-
-GURL CloudPrintHelpers::GetUrlForPrinterList(const GURL& cloud_print_server_url,
- const std::string& proxy_id) {
- std::string path(
- cloud_print::AppendPathToUrl(cloud_print_server_url, "list"));
- GURL::Replacements replacements;
- replacements.SetPathStr(path);
- std::string query = StringPrintf("proxy=%s", proxy_id.c_str());
- replacements.SetQueryStr(query);
- return cloud_print_server_url.ReplaceComponents(replacements);
}
-GURL CloudPrintHelpers::GetUrlForJobFetch(const GURL& cloud_print_server_url,
- const std::string& printer_id,
- const std::string& reason) {
- std::string path(
- cloud_print::AppendPathToUrl(cloud_print_server_url, "fetch"));
- GURL::Replacements replacements;
- replacements.SetPathStr(path);
- std::string query = StringPrintf("printerid=%s&deb=%s",
- printer_id.c_str(),
- reason.c_str());
- replacements.SetQueryStr(query);
- return cloud_print_server_url.ReplaceComponents(replacements);
-}
+namespace cloud_print {
-GURL CloudPrintHelpers::GetUrlForJobStatusUpdate(
- const GURL& cloud_print_server_url,
- const std::string& job_id,
- cloud_print::PrintJobStatus status) {
- std::string status_string = StringFromJobStatus(status);
- std::string path(
- cloud_print::AppendPathToUrl(cloud_print_server_url, "control"));
- GURL::Replacements replacements;
- replacements.SetPathStr(path);
- std::string query = StringPrintf("jobid=%s&status=%s",
- job_id.c_str(), status_string.c_str());
- replacements.SetQueryStr(query);
- return cloud_print_server_url.ReplaceComponents(replacements);
+GURL GetUrlForJobStatusUpdate(const GURL& cloud_print_server_url,
+ const std::string& job_id,
+ PrintJobStatus status) {
+ return GetUrlForJobStatusUpdate(cloud_print_server_url,
+ job_id,
+ StringFromJobStatus(status));
}
-GURL CloudPrintHelpers::GetUrlForJobStatusUpdate(
- const GURL& cloud_print_server_url,
- const std::string& job_id,
- const cloud_print::PrintJobDetails& details) {
+GURL GetUrlForJobStatusUpdate(const GURL& cloud_print_server_url,
+ const std::string& job_id,
+ const PrintJobDetails& details) {
std::string status_string = StringFromJobStatus(details.status);
- std::string path(
- cloud_print::AppendPathToUrl(cloud_print_server_url, "control"));
+ std::string path(AppendPathToUrl(cloud_print_server_url, "control"));
GURL::Replacements replacements;
replacements.SetPathStr(path);
std::string query =
@@ -161,87 +64,27 @@ GURL CloudPrintHelpers::GetUrlForJobStatusUpdate(
return cloud_print_server_url.ReplaceComponents(replacements);
}
-GURL CloudPrintHelpers::GetUrlForUserMessage(const GURL& cloud_print_server_url,
- const std::string& message_id) {
- std::string path(
- cloud_print::AppendPathToUrl(cloud_print_server_url, "message"));
- GURL::Replacements replacements;
- replacements.SetPathStr(path);
- std::string query = StringPrintf("code=%s", message_id.c_str());
- replacements.SetQueryStr(query);
- return cloud_print_server_url.ReplaceComponents(replacements);
+std::string GetHashOfPrinterInfo(
+ const printing::PrinterBasicInfo& printer_info) {
+ return GetHashOfPrinterTags(printer_info.options);
}
-GURL CloudPrintHelpers::GetUrlForGetAuthCode(const GURL& cloud_print_server_url,
- const std::string& oauth_client_id,
- const std::string& proxy_id) {
- // We use the internal API "createrobot" instead of "getauthcode". This API
- // will add the robot as owner to all the existing printers for this user.
- std::string path(
- cloud_print::AppendPathToUrl(cloud_print_server_url, "createrobot"));
- GURL::Replacements replacements;
- replacements.SetPathStr(path);
- std::string query = StringPrintf("oauth_client_id=%s&proxy=%s",
- oauth_client_id.c_str(),
- proxy_id.c_str());
- replacements.SetQueryStr(query);
- return cloud_print_server_url.ReplaceComponents(replacements);
-}
-
-std::string CloudPrintHelpers::GetHashOfPrinterTags(
- const printing::PrinterBasicInfo& printer) {
- PrinterTags printer_tags;
- GetPrinterTags(printer, &printer_tags);
- std::string values_list;
- 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);
-}
-
-std::string CloudPrintHelpers::GetPostDataForPrinterTags(
- const printing::PrinterBasicInfo& printer,
+std::string GetPostDataForPrinterInfo(
+ const printing::PrinterBasicInfo& printer_info,
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();
- }
- // 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);
- }
- std::string tags_hash_msg(kTagsHashTagName);
- tags_hash_msg += "=";
- tags_hash_msg += HashPrinterTags(printer_tags);
- cloud_print::AddMultipartValueForUpload(kPrinterTagValue, tags_hash_msg,
- mime_boundary, std::string(),
- &post_data);
- return post_data;
+ return GetPostDataForPrinterTags(
+ printer_info.options,
+ mime_boundary,
+ kCloudPrintServiceProxyTagPrefix,
+ kCloudPrintServiceTagsHashTagName);
}
-bool CloudPrintHelpers::IsDryRunJob(const std::vector<std::string>& tags) {
- std::vector<std::string>::const_iterator it;
- for (it = tags.begin(); it != tags.end(); ++it) {
- if (*it == kTagDryRunFlag)
- return true;
- }
- return false;
+bool IsDryRunJob(const std::vector<std::string>& tags) {
+ return std::find(tags.begin(), tags.end(),
+ std::string(kCloudPrintServiceTagDryRunFlag)) != tags.end();
}
-std::string CloudPrintHelpers::GetCloudPrintAuthHeaderFromStore() {
+std::string GetCloudPrintAuthHeaderFromStore() {
CloudPrintTokenStore* token_store = CloudPrintTokenStore::current();
if (!token_store || token_store->token().empty()) {
// Using LOG here for critical errors. GCP connector may run in the headless
@@ -252,10 +95,4 @@ std::string CloudPrintHelpers::GetCloudPrintAuthHeaderFromStore() {
return GetCloudPrintAuthHeader(token_store->token());
}
-std::string CloudPrintHelpers::GetCloudPrintAuthHeader(
- const std::string& auth_token) {
- std::string header;
- header = "Authorization: OAuth ";
- header += auth_token;
- return header;
-}
+} // namespace cloud_print
diff --git a/chrome/service/cloud_print/cloud_print_helpers.h b/chrome/service/cloud_print/cloud_print_helpers.h
index e3bb5b6..54ff5e8 100644
--- a/chrome/service/cloud_print/cloud_print_helpers.h
+++ b/chrome/service/cloud_print/cloud_print_helpers.h
@@ -5,62 +5,38 @@
#ifndef CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_
#define CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_
-#include <map>
#include <string>
#include <vector>
#include "chrome/service/cloud_print/print_system.h"
#include "googleurl/src/gurl.h"
-namespace base {
-class DictionaryValue;
-}
+namespace cloud_print {
// Helper methods for the cloud print proxy code.
-class CloudPrintHelpers {
- public:
- static GURL GetUrlForPrinterRegistration(const GURL& cloud_print_server_url);
- static GURL GetUrlForPrinterUpdate(const GURL& cloud_print_server_url,
- const std::string& printer_id);
- static GURL GetUrlForPrinterDelete(const GURL& cloud_print_server_url,
- const std::string& printer_id,
- const std::string& reason);
- static GURL GetUrlForPrinterList(const GURL& cloud_print_server_url,
- const std::string& proxy_id);
- static GURL GetUrlForJobFetch(const GURL& cloud_print_server_url,
- const std::string& printer_id,
- const std::string& reason);
- static GURL GetUrlForJobStatusUpdate(const GURL& cloud_print_server_url,
- const std::string& job_id,
- cloud_print::PrintJobStatus status);
- static GURL GetUrlForJobStatusUpdate(
- const GURL& cloud_print_server_url,
- const std::string& job_id,
- const cloud_print::PrintJobDetails& details);
- static GURL GetUrlForUserMessage(const GURL& cloud_print_server_url,
- const std::string& message_id);
- static GURL GetUrlForGetAuthCode(const GURL& cloud_print_server_url,
- const std::string& oauth_client_id,
- const std::string& proxy_id);
+GURL GetUrlForJobStatusUpdate(const GURL& cloud_print_server_url,
+ const std::string& job_id,
+ PrintJobStatus status);
- // 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);
+GURL GetUrlForJobStatusUpdate(const GURL& cloud_print_server_url,
+ const std::string& job_id,
+ const PrintJobDetails& details);
- // Returns true is tags indicate a dry run (test) job.
- static bool IsDryRunJob(const std::vector<std::string>& tags);
+// Returns an MD5 hash for printer tags in the given |printer_info|.
+std::string GetHashOfPrinterInfo(
+ const printing::PrinterBasicInfo& printer_info);
- // Created CloudPrint auth header from the auth token stored in the store.
- static std::string GetCloudPrintAuthHeaderFromStore();
- // Created CloudPrint auth header from the auth token.
- static std::string GetCloudPrintAuthHeader(const std::string& auth_token);
+// Returns any post data for printer tags in the given |printer_info|.
+std::string GetPostDataForPrinterInfo(
+ const printing::PrinterBasicInfo& printer_info,
+ const std::string& mime_boundary);
- private:
- CloudPrintHelpers() {}
-};
+// Returns true if tags indicate a dry run (test) job.
+bool IsDryRunJob(const std::vector<std::string>& tags);
+
+// Created cloud print auth header from the auth token stored in the store.
+std::string GetCloudPrintAuthHeaderFromStore();
+
+} // namespace cloud_print
#endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_
diff --git a/chrome/service/cloud_print/cloud_print_helpers_unittest.cc b/chrome/service/cloud_print/cloud_print_helpers_unittest.cc
index 429b3f5..a4d7ca0 100644
--- a/chrome/service/cloud_print/cloud_print_helpers_unittest.cc
+++ b/chrome/service/cloud_print/cloud_print_helpers_unittest.cc
@@ -4,101 +4,101 @@
#include "chrome/service/cloud_print/cloud_print_helpers.h"
+#include "base/md5.h"
#include "base/stringprintf.h"
+#include "base/sys_info.h"
+#include "chrome/common/chrome_version_info.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace cloud_print {
+
namespace {
-void CheckURLs(const GURL& server_base_url) {
- GURL url = CloudPrintHelpers::GetUrlForPrinterRegistration(server_base_url);
+void CheckJobStatusURLs(const GURL& server_base_url) {
std::string expected_url_base = server_base_url.spec();
- if (expected_url_base[expected_url_base.length() - 1] != '/') {
+ if (expected_url_base[expected_url_base.length() - 1] != '/')
expected_url_base += "/";
- }
- std::string expected_url = base::StringPrintf("%sregister",
- expected_url_base.c_str());
- EXPECT_EQ(expected_url, url.spec());
-
- url = CloudPrintHelpers::GetUrlForPrinterUpdate(server_base_url,
- "printeridfoo");
- expected_url = base::StringPrintf("%supdate?printerid=printeridfoo",
- expected_url_base.c_str());
- EXPECT_EQ(expected_url, url.spec());
-
- url = CloudPrintHelpers::GetUrlForPrinterDelete(server_base_url,
- "printeridbar", "deleted");
- expected_url = base::StringPrintf(
- "%sdelete?printerid=printeridbar&reason=deleted",
- expected_url_base.c_str());
- EXPECT_EQ(expected_url, url.spec());
-
- url = CloudPrintHelpers::GetUrlForPrinterList(server_base_url, "demoproxy");
- expected_url = base::StringPrintf("%slist?proxy=demoproxy",
- expected_url_base.c_str());
- EXPECT_EQ(expected_url, url.spec());
-
- url = CloudPrintHelpers::GetUrlForJobFetch(server_base_url,
- "myprinter",
- "nogoodreason");
- expected_url = base::StringPrintf(
- "%sfetch?printerid=myprinter&deb=nogoodreason",
- expected_url_base.c_str());
- EXPECT_EQ(expected_url, url.spec());
-
- url = CloudPrintHelpers::GetUrlForJobStatusUpdate(
- server_base_url, "12345678", cloud_print::PRINT_JOB_STATUS_IN_PROGRESS);
- expected_url = base::StringPrintf(
- "%scontrol?jobid=12345678&status=IN_PROGRESS", expected_url_base.c_str());
- EXPECT_EQ(expected_url, url.spec());
-
- url = CloudPrintHelpers::GetUrlForJobStatusUpdate(
- server_base_url, "12345678", cloud_print::PRINT_JOB_STATUS_ERROR);
- expected_url = base::StringPrintf("%scontrol?jobid=12345678&status=ERROR",
- expected_url_base.c_str());
- EXPECT_EQ(expected_url, url.spec());
-
- url = CloudPrintHelpers::GetUrlForJobStatusUpdate(
- server_base_url, "12345678", cloud_print::PRINT_JOB_STATUS_COMPLETED);
- expected_url = base::StringPrintf("%scontrol?jobid=12345678&status=DONE",
- expected_url_base.c_str());
- EXPECT_EQ(expected_url, url.spec());
-
- cloud_print::PrintJobDetails details;
- details.status = cloud_print::PRINT_JOB_STATUS_IN_PROGRESS;
+
+ EXPECT_EQ(base::StringPrintf("%scontrol?jobid=87654321&status=ERROR",
+ expected_url_base.c_str()),
+ GetUrlForJobStatusUpdate(server_base_url, "87654321",
+ PRINT_JOB_STATUS_ERROR).spec());
+
+ PrintJobDetails details;
+ details.status = PRINT_JOB_STATUS_IN_PROGRESS;
details.platform_status_flags = 2;
details.status_message = "Out of Paper";
details.total_pages = 345;
details.pages_printed = 47;
- url = CloudPrintHelpers::GetUrlForJobStatusUpdate(server_base_url,
- "87654321", details);
- expected_url = base::StringPrintf(
- "%scontrol?jobid=87654321&status=IN_PROGRESS&code=2"
- "&message=Out%%20of%%20Paper&numpages=345&pagesprinted=47",
- expected_url_base.c_str());
- EXPECT_EQ(expected_url, url.spec());
-
- url = CloudPrintHelpers::GetUrlForUserMessage(server_base_url,
- "blahmessageid");
- expected_url = base::StringPrintf("%smessage?code=blahmessageid",
- expected_url_base.c_str());
- EXPECT_EQ(expected_url, url.spec());
-
- url = CloudPrintHelpers::GetUrlForGetAuthCode(
- server_base_url,
- "fooclientid.apps.googleusercontent.com",
- "test_proxy");
- expected_url = base::StringPrintf(
- "%screaterobot?oauth_client_id=fooclientid.apps.googleusercontent.com&"
- "proxy=test_proxy", expected_url_base.c_str());
- EXPECT_EQ(expected_url, url.spec());
+ EXPECT_EQ(base::StringPrintf(
+ "%scontrol?jobid=87654321&status=IN_PROGRESS&code=2"
+ "&message=Out%%20of%%20Paper&numpages=345&pagesprinted=47",
+ expected_url_base.c_str()),
+ GetUrlForJobStatusUpdate(
+ server_base_url, "87654321", details).spec());
}
} // namespace
-TEST(CloudPrintHelpersTest, URLGetters) {
- CheckURLs(GURL("https://www.google.com/cloudprint"));
- CheckURLs(GURL("https://www.google.com/cloudprint/"));
- CheckURLs(GURL("http://www.myprinterserver.com"));
- CheckURLs(GURL("http://www.myprinterserver.com/"));
+TEST(CloudPrintServiceHelpersTest, GetURLs) {
+ CheckJobStatusURLs(GURL("https://www.google.com/cloudprint"));
+ CheckJobStatusURLs(GURL("https://www.google.com/cloudprint/"));
+ CheckJobStatusURLs(GURL("http://www.myprinterserver.com"));
+ CheckJobStatusURLs(GURL("http://www.myprinterserver.com/"));
}
+TEST(CloudPrintServiceHelpersTest, GetHashOfPrinterInfo) {
+ printing::PrinterBasicInfo printer_info;
+ printer_info.options["tag1"] = std::string("value1");
+ printer_info.options["tag2"] = std::string("value2");
+
+ chrome::VersionInfo version_info;
+ std::string expected_list_string = StringPrintf(
+ "chrome_version%ssystem_name%ssystem_version%stag1value1tag2value2",
+ version_info.CreateVersionString().c_str(),
+ base::SysInfo::OperatingSystemName().c_str(),
+ base::SysInfo::OperatingSystemVersion().c_str());
+ EXPECT_EQ(base::MD5String(expected_list_string),
+ GetHashOfPrinterInfo(printer_info));
+}
+
+TEST(CloudPrintServiceHelpersTest, GetPostDataForPrinterInfo) {
+ printing::PrinterBasicInfo printer_info;
+ printer_info.options["tag1"] = std::string("value1");
+ printer_info.options["tag2"] = std::string("value2");
+
+ chrome::VersionInfo version_info;
+ std::string expected = base::StringPrintf(
+ "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
+ "\r\n\r\n__cp__chrome_version=%s\r\n"
+ "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
+ "\r\n\r\n__cp__system_name=%s\r\n"
+ "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
+ "\r\n\r\n__cp__system_version=%s\r\n"
+ "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
+ "\r\n\r\n__cp__tag1=value1\r\n"
+ "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
+ "\r\n\r\n__cp__tag2=value2\r\n"
+ "--test_mime_boundary\r\nContent-Disposition: form-data; name=\"tag\""
+ "\r\n\r\n__cp__tagshash=%s\r\n",
+ version_info.CreateVersionString().c_str(),
+ base::SysInfo::OperatingSystemName().c_str(),
+ base::SysInfo::OperatingSystemVersion().c_str(),
+ GetHashOfPrinterInfo(printer_info).c_str());
+
+ EXPECT_EQ(expected, GetPostDataForPrinterInfo(
+ printer_info, std::string("test_mime_boundary")));
+}
+
+TEST(CloudPrintServiceHelpersTest, IsDryRunJob) {
+ std::vector<std::string> tags_not_dry_run;
+ tags_not_dry_run.push_back("tag_1");
+ EXPECT_FALSE(IsDryRunJob(tags_not_dry_run));
+
+ std::vector<std::string> tags_dry_run;
+ tags_dry_run.push_back("__cp__dry_run");
+ EXPECT_TRUE(IsDryRunJob(tags_dry_run));
+}
+
+} // namespace cloud_print
+
diff --git a/chrome/service/cloud_print/cloud_print_proxy.cc b/chrome/service/cloud_print/cloud_print_proxy.cc
index d1c8cb8..b8a316c 100644
--- a/chrome/service/cloud_print/cloud_print_proxy.cc
+++ b/chrome/service/cloud_print/cloud_print_proxy.cc
@@ -10,9 +10,9 @@
#include "base/process_util.h"
#include "base/values.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/cloud_print/cloud_print_constants.h"
#include "chrome/common/cloud_print/cloud_print_proxy_info.h"
#include "chrome/common/pref_names.h"
-#include "chrome/service/cloud_print/cloud_print_consts.h"
#include "chrome/service/cloud_print/print_system.h"
#include "chrome/service/service_process.h"
#include "chrome/service/service_process_prefs.h"
@@ -65,6 +65,8 @@ void CheckCloudPrintProxyPolicyInBrowser() {
} // namespace
+namespace cloud_print {
+
CloudPrintProxy::CloudPrintProxy()
: service_prefs_(NULL),
client_(NULL),
@@ -200,7 +202,7 @@ void CloudPrintProxy::DisableForUser() {
ShutdownBackend();
}
-void CloudPrintProxy::GetProxyInfo(cloud_print::CloudPrintProxyInfo* info) {
+void CloudPrintProxy::GetProxyInfo(CloudPrintProxyInfo* info) {
info->enabled = enabled_;
info->email.clear();
if (enabled_)
@@ -283,3 +285,5 @@ void CloudPrintProxy::ShutdownBackend() {
backend_->Shutdown();
backend_.reset();
}
+
+} // namespace cloud_print
diff --git a/chrome/service/cloud_print/cloud_print_proxy.h b/chrome/service/cloud_print/cloud_print_proxy.h
index 67ab4e7..8c8fafe 100644
--- a/chrome/service/cloud_print/cloud_print_proxy.h
+++ b/chrome/service/cloud_print/cloud_print_proxy.h
@@ -18,8 +18,8 @@
class ServiceProcessPrefs;
namespace cloud_print {
+
struct CloudPrintProxyInfo;
-} // namespace cloud_print
// CloudPrintProxy is the layer between the service process UI thread
// and the cloud print proxy backend.
@@ -51,7 +51,7 @@ class CloudPrintProxy : public CloudPrintProxyFrontend,
void UnregisterPrintersAndDisableForUser();
void DisableForUser();
// Returns the proxy info.
- void GetProxyInfo(cloud_print::CloudPrintProxyInfo* info);
+ void GetProxyInfo(CloudPrintProxyInfo* info);
// Launches a browser to see if the proxy policy has been set.
void CheckCloudPrintProxyPolicy();
@@ -100,4 +100,6 @@ class CloudPrintProxy : public CloudPrintProxyFrontend,
DISALLOW_COPY_AND_ASSIGN(CloudPrintProxy);
};
+} // namespace cloud_print
+
#endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_PROXY_H_
diff --git a/chrome/service/cloud_print/cloud_print_proxy_backend.cc b/chrome/service/cloud_print/cloud_print_proxy_backend.cc
index 44df7b6..003a43b 100644
--- a/chrome/service/cloud_print/cloud_print_proxy_backend.cc
+++ b/chrome/service/cloud_print/cloud_print_proxy_backend.cc
@@ -14,9 +14,9 @@
#include "base/rand_util.h"
#include "base/values.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/cloud_print/cloud_print_constants.h"
#include "chrome/service/cloud_print/cloud_print_auth.h"
#include "chrome/service/cloud_print/cloud_print_connector.h"
-#include "chrome/service/cloud_print/cloud_print_consts.h"
#include "chrome/service/cloud_print/cloud_print_helpers.h"
#include "chrome/service/cloud_print/cloud_print_token_store.h"
#include "chrome/service/cloud_print/connector_settings.h"
@@ -32,6 +32,8 @@
#include "jingle/notifier/listener/push_client_observer.h"
#include "ui/base/l10n/l10n_util.h"
+namespace cloud_print {
+
// The real guts of CloudPrintProxyBackend, to keep the public client API clean.
class CloudPrintProxyBackend::Core
: public base::RefCountedThreadSafe<CloudPrintProxyBackend::Core>,
@@ -576,3 +578,4 @@ void CloudPrintProxyBackend::Core::OnPingResponse() {
VLOG(1) << "CP_CONNECTOR: Ping response received.";
}
+} // namespace cloud_print
diff --git a/chrome/service/cloud_print/cloud_print_proxy_backend.h b/chrome/service/cloud_print/cloud_print_proxy_backend.h
index a78ce3b..2da4315 100644
--- a/chrome/service/cloud_print/cloud_print_proxy_backend.h
+++ b/chrome/service/cloud_print/cloud_print_proxy_backend.h
@@ -20,6 +20,8 @@ namespace gaia {
struct OAuthClientInfo;
}
+namespace cloud_print {
+
// CloudPrintProxyFrontend is the interface used by CloudPrintProxyBackend to
// communicate with the entity that created it and, presumably, is interested in
// cloud print proxy related activity.
@@ -102,4 +104,6 @@ class CloudPrintProxyBackend {
DISALLOW_COPY_AND_ASSIGN(CloudPrintProxyBackend);
};
+} // namespace cloud_print
+
#endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_PROXY_BACKEND_H_
diff --git a/chrome/service/cloud_print/cloud_print_token_store.cc b/chrome/service/cloud_print/cloud_print_token_store.cc
index dacbf94..1fb39b0 100644
--- a/chrome/service/cloud_print/cloud_print_token_store.cc
+++ b/chrome/service/cloud_print/cloud_print_token_store.cc
@@ -7,6 +7,8 @@
#include "base/lazy_instance.h"
#include "base/threading/thread_local.h"
+namespace cloud_print {
+
// Keep the global CloudPrintTokenStore in a TLS slot so it is impossible to
// incorrectly from the wrong thread.
static base::LazyInstance<base::ThreadLocalPointer<CloudPrintTokenStore> >
@@ -28,3 +30,5 @@ void CloudPrintTokenStore::SetToken(const std::string& token) {
DCHECK(CalledOnValidThread());
token_ = token;
}
+
+} // namespace cloud_print
diff --git a/chrome/service/cloud_print/cloud_print_token_store.h b/chrome/service/cloud_print/cloud_print_token_store.h
index e657a9a..0a8e91a 100644
--- a/chrome/service/cloud_print/cloud_print_token_store.h
+++ b/chrome/service/cloud_print/cloud_print_token_store.h
@@ -6,12 +6,13 @@
#define CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_TOKEN_STORE_H_
#include <string>
+#include "base/logging.h"
+#include "base/threading/non_thread_safe.h"
// This class serves as the single repository for cloud print auth tokens. This
// is only used within the CloudPrintProxyCoreThread.
-#include "base/logging.h"
-#include "base/threading/non_thread_safe.h"
+namespace cloud_print {
class CloudPrintTokenStore : public base::NonThreadSafe {
public:
@@ -34,4 +35,6 @@ class CloudPrintTokenStore : public base::NonThreadSafe {
DISALLOW_COPY_AND_ASSIGN(CloudPrintTokenStore);
};
+} // namespace cloud_print
+
#endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_TOKEN_STORE_H_
diff --git a/chrome/service/cloud_print/cloud_print_token_store_unittest.cc b/chrome/service/cloud_print/cloud_print_token_store_unittest.cc
index 1dff537..b61e434 100644
--- a/chrome/service/cloud_print/cloud_print_token_store_unittest.cc
+++ b/chrome/service/cloud_print/cloud_print_token_store_unittest.cc
@@ -6,6 +6,8 @@
#include "testing/gtest/include/gtest/gtest.h"
+namespace cloud_print {
+
TEST(CloudPrintTokenStoreTest, Basic) {
EXPECT_EQ(NULL, CloudPrintTokenStore::current());
CloudPrintTokenStore* store = new CloudPrintTokenStore;
@@ -16,3 +18,4 @@ TEST(CloudPrintTokenStoreTest, Basic) {
EXPECT_EQ(NULL, CloudPrintTokenStore::current());
}
+} // namespace cloud_print
diff --git a/chrome/service/cloud_print/cloud_print_url_fetcher.cc b/chrome/service/cloud_print/cloud_print_url_fetcher.cc
index 77a37ce..da53bfbf 100644
--- a/chrome/service/cloud_print/cloud_print_url_fetcher.cc
+++ b/chrome/service/cloud_print/cloud_print_url_fetcher.cc
@@ -6,8 +6,8 @@
#include "base/stringprintf.h"
#include "base/values.h"
+#include "chrome/common/cloud_print/cloud_print_constants.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_helpers.h"
#include "chrome/service/cloud_print/cloud_print_token_store.h"
#include "chrome/service/net/service_url_request_context.h"
@@ -18,6 +18,7 @@
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_status.h"
+namespace cloud_print {
CloudPrintURLFetcher::ResponseAction
CloudPrintURLFetcher::Delegate::HandleRawResponse(
@@ -122,7 +123,7 @@ void CloudPrintURLFetcher::OnURLFetchComplete(
// to a non-cloudprint-server URL eg. for authentication).
bool succeeded = false;
DictionaryValue* response_dict = NULL;
- cloud_print::ParseResponseJSON(data, &succeeded, &response_dict);
+ ParseResponseJSON(data, &succeeded, &response_dict);
if (response_dict)
action = delegate_->HandleJSONData(source,
source->GetURL(),
@@ -193,7 +194,7 @@ void CloudPrintURLFetcher::SetupRequestHeaders() {
std::string headers = delegate_->GetAuthHeader();
if (!headers.empty())
headers += "\r\n";
- headers += cloud_print::kChromeCloudPrintProxyHeader;
+ headers += kChromeCloudPrintProxyHeader;
if (!additional_headers_.empty()) {
headers += "\r\n";
headers += additional_headers_;
@@ -212,3 +213,5 @@ net::URLRequestContextGetter* CloudPrintURLFetcher::GetRequestContextGetter() {
getter->set_user_agent(user_agent);
return getter;
}
+
+} // namespace cloud_print
diff --git a/chrome/service/cloud_print/cloud_print_url_fetcher.h b/chrome/service/cloud_print/cloud_print_url_fetcher.h
index d976f712..22ea4a4 100644
--- a/chrome/service/cloud_print/cloud_print_url_fetcher.h
+++ b/chrome/service/cloud_print/cloud_print_url_fetcher.h
@@ -23,6 +23,8 @@ class URLRequestContextGetter;
class URLRequestStatus;
} // namespace net
+namespace cloud_print {
+
// A wrapper around URLFetcher for CloudPrint. URLFetcher applies retry logic
// only on HTTP response codes >= 500. In the cloud print case, we want to
// retry on all network errors. In addition, we want to treat non-JSON responses
@@ -136,4 +138,6 @@ class CloudPrintURLFetcher
typedef CloudPrintURLFetcher::Delegate CloudPrintURLFetcherDelegate;
+} // namespace cloud_print
+
#endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_URL_FETCHER_H_
diff --git a/chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc b/chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc
index b311538..f7d5cc2 100644
--- a/chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc
+++ b/chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc
@@ -21,7 +21,7 @@
using base::Time;
using base::TimeDelta;
-namespace {
+namespace cloud_print {
const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data");
@@ -375,4 +375,4 @@ TEST_F(CloudPrintURLFetcherRetryBackoffTest, DISABLED_GiveUp) {
MessageLoop::current()->Run();
}
-} // namespace.
+} // namespace cloud_print
diff --git a/chrome/service/cloud_print/cloud_print_wipeout.cc b/chrome/service/cloud_print/cloud_print_wipeout.cc
index 4c18623..a6be0ef 100644
--- a/chrome/service/cloud_print/cloud_print_wipeout.cc
+++ b/chrome/service/cloud_print/cloud_print_wipeout.cc
@@ -4,11 +4,13 @@
#include "chrome/service/cloud_print/cloud_print_wipeout.h"
-#include "chrome/service/cloud_print/cloud_print_consts.h"
-#include "chrome/service/cloud_print/cloud_print_helpers.h"
+#include "chrome/common/cloud_print/cloud_print_constants.h"
+#include "chrome/common/cloud_print/cloud_print_helpers.h"
const int kMaxWipeoutAttempts = 3;
+namespace cloud_print {
+
CloudPrintWipeout::CloudPrintWipeout(Client* client,
const GURL& cloud_print_server_url)
: client_(client), cloud_print_server_url_(cloud_print_server_url) {
@@ -33,9 +35,9 @@ void CloudPrintWipeout::UnregisterNextPrinter() {
std::string printer_id = printer_ids_.front();
printer_ids_.pop_front();
- GURL url = CloudPrintHelpers::GetUrlForPrinterDelete(cloud_print_server_url_,
- printer_id,
- "connector_disabled");
+ GURL url = GetUrlForPrinterDelete(cloud_print_server_url_,
+ printer_id,
+ "connector_disabled");
request_ = new CloudPrintURLFetcher;
request_->StartGetRequest(url, this, kMaxWipeoutAttempts, std::string());
}
@@ -61,6 +63,7 @@ CloudPrintURLFetcher::ResponseAction CloudPrintWipeout::OnRequestAuthError() {
}
std::string CloudPrintWipeout::GetAuthHeader() {
- return CloudPrintHelpers::GetCloudPrintAuthHeader(auth_token_);
+ return GetCloudPrintAuthHeader(auth_token_);
}
+} // namespace cloud_print
diff --git a/chrome/service/cloud_print/cloud_print_wipeout.h b/chrome/service/cloud_print/cloud_print_wipeout.h
index 7a72d46..9cd3494 100644
--- a/chrome/service/cloud_print/cloud_print_wipeout.h
+++ b/chrome/service/cloud_print/cloud_print_wipeout.h
@@ -12,6 +12,8 @@
#include "chrome/service/cloud_print/cloud_print_url_fetcher.h"
#include "googleurl/src/gurl.h"
+namespace cloud_print {
+
// CloudPrintWipeout unregisters list of printers from the cloudprint service.
class CloudPrintWipeout : public CloudPrintURLFetcherDelegate {
public:
@@ -55,5 +57,7 @@ class CloudPrintWipeout : public CloudPrintURLFetcherDelegate {
DISALLOW_COPY_AND_ASSIGN(CloudPrintWipeout);
};
+} // namespace cloud_print
+
#endif // CHROME_SERVICE_CLOUD_PRINT_CLOUD_PRINT_WIPEOUT_H_
diff --git a/chrome/service/cloud_print/connector_settings.cc b/chrome/service/cloud_print/connector_settings.cc
index ccfc6e1..2b43b15 100644
--- a/chrome/service/cloud_print/connector_settings.cc
+++ b/chrome/service/cloud_print/connector_settings.cc
@@ -5,8 +5,8 @@
#include "chrome/service/cloud_print/connector_settings.h"
#include "base/values.h"
+#include "chrome/common/cloud_print/cloud_print_constants.h"
#include "chrome/common/pref_names.h"
-#include "chrome/service/cloud_print/cloud_print_consts.h"
#include "chrome/service/cloud_print/print_system.h"
#include "chrome/service/service_process_prefs.h"
@@ -17,6 +17,8 @@ const char kDeleteOnEnumFail[] = "delete_on_enum_fail";
} // namespace
+namespace cloud_print {
+
ConnectorSettings::ConnectorSettings()
: delete_on_enum_fail_(false),
connect_new_printers_(true),
@@ -32,7 +34,7 @@ void ConnectorSettings::InitFrom(ServiceProcessPrefs* prefs) {
proxy_id_ = prefs->GetString(prefs::kCloudPrintProxyId, "");
if (proxy_id_.empty()) {
- proxy_id_ = cloud_print::PrintSystem::GenerateProxyId();
+ proxy_id_ = PrintSystem::GenerateProxyId();
prefs->SetString(prefs::kCloudPrintProxyId, proxy_id_);
prefs->WritePrefs();
}
@@ -100,3 +102,5 @@ void ConnectorSettings::SetXmppPingTimeoutSec(int timeout) {
xmpp_ping_timeout_sec_ = kMinimumXmppPingTimeoutSecs;
}
}
+
+} // namespace cloud_print
diff --git a/chrome/service/cloud_print/connector_settings.h b/chrome/service/cloud_print/connector_settings.h
index 4c9b086..94aa841 100644
--- a/chrome/service/cloud_print/connector_settings.h
+++ b/chrome/service/cloud_print/connector_settings.h
@@ -17,6 +17,8 @@ namespace base {
class DictionaryValue;
}
+namespace cloud_print {
+
class ConnectorSettings {
public:
ConnectorSettings();
@@ -92,5 +94,7 @@ class ConnectorSettings {
DISALLOW_COPY_AND_ASSIGN(ConnectorSettings);
};
+} // namespace cloud_print
+
#endif // CHROME_SERVICE_CLOUD_PRINT_CONNECTOR_SETTINGS_H_
diff --git a/chrome/service/cloud_print/connector_settings_unittest.cc b/chrome/service/cloud_print/connector_settings_unittest.cc
index a2bd869..d3d889f 100644
--- a/chrome/service/cloud_print/connector_settings_unittest.cc
+++ b/chrome/service/cloud_print/connector_settings_unittest.cc
@@ -11,12 +11,14 @@
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
#include "base/values.h"
-#include "chrome/service/cloud_print/cloud_print_consts.h"
+#include "chrome/common/cloud_print/cloud_print_constants.h"
#include "chrome/service/service_process_prefs.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace cloud_print {
+
const char kServiceStateContent[] =
"{"
" 'cloud_print': {"
@@ -143,3 +145,5 @@ TEST_F(ConnectorSettingsTest, SettersTest) {
settings.SetXmppPingTimeoutSec(1);
EXPECT_EQ(settings.xmpp_ping_timeout_sec(), kMinimumXmppPingTimeoutSecs);
}
+
+} // namespace cloud_print
diff --git a/chrome/service/cloud_print/job_status_updater.cc b/chrome/service/cloud_print/job_status_updater.cc
index 00dcdbc..d28ae1f 100644
--- a/chrome/service/cloud_print/job_status_updater.cc
+++ b/chrome/service/cloud_print/job_status_updater.cc
@@ -9,16 +9,18 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
-#include "chrome/service/cloud_print/cloud_print_consts.h"
+#include "chrome/common/cloud_print/cloud_print_constants.h"
#include "chrome/service/cloud_print/cloud_print_helpers.h"
#include "googleurl/src/gurl.h"
+namespace cloud_print {
+
JobStatusUpdater::JobStatusUpdater(const std::string& printer_name,
- const std::string& job_id,
- cloud_print::PlatformJobId& local_job_id,
- const GURL& cloud_print_server_url,
- cloud_print::PrintSystem* print_system,
- Delegate* delegate)
+ const std::string& job_id,
+ PlatformJobId& local_job_id,
+ const GURL& cloud_print_server_url,
+ PrintSystem* print_system,
+ Delegate* delegate)
: printer_name_(printer_name), job_id_(job_id),
local_job_id_(local_job_id),
cloud_print_server_url_(cloud_print_server_url),
@@ -36,10 +38,10 @@ void JobStatusUpdater::UpdateStatus() {
// If the job has already been completed, we just need to update the server
// with that status. The *only* reason we would come back here in that case
// is if our last server update attempt failed.
- if (last_job_details_.status == cloud_print::PRINT_JOB_STATUS_COMPLETED) {
+ if (last_job_details_.status == PRINT_JOB_STATUS_COMPLETED) {
need_update = true;
} else {
- cloud_print::PrintJobDetails details;
+ PrintJobDetails details;
if (print_system_->GetJobDetails(printer_name_, local_job_id_,
&details)) {
if (details != last_job_details_) {
@@ -51,14 +53,14 @@ void JobStatusUpdater::UpdateStatus() {
// longer exists in the OS queue. We are going to assume it is done in
// this case.
last_job_details_.Clear();
- last_job_details_.status = cloud_print::PRINT_JOB_STATUS_COMPLETED;
+ last_job_details_.status = PRINT_JOB_STATUS_COMPLETED;
need_update = true;
}
}
if (need_update) {
request_ = new CloudPrintURLFetcher;
request_->StartGetRequest(
- CloudPrintHelpers::GetUrlForJobStatusUpdate(
+ GetUrlForJobStatusUpdate(
cloud_print_server_url_, job_id_, last_job_details_),
this,
kCloudPrintAPIMaxRetryCount,
@@ -80,7 +82,7 @@ CloudPrintURLFetcher::ResponseAction JobStatusUpdater::HandleJSONData(
const GURL& url,
DictionaryValue* json_data,
bool succeeded) {
- if (last_job_details_.status == cloud_print::PRINT_JOB_STATUS_COMPLETED) {
+ if (last_job_details_.status == PRINT_JOB_STATUS_COMPLETED) {
MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(&JobStatusUpdater::Stop, this));
}
@@ -98,7 +100,9 @@ CloudPrintURLFetcher::ResponseAction JobStatusUpdater::OnRequestAuthError() {
}
std::string JobStatusUpdater::GetAuthHeader() {
- return CloudPrintHelpers::GetCloudPrintAuthHeaderFromStore();
+ return GetCloudPrintAuthHeaderFromStore();
}
JobStatusUpdater::~JobStatusUpdater() {}
+
+} // namespace cloud_print
diff --git a/chrome/service/cloud_print/job_status_updater.h b/chrome/service/cloud_print/job_status_updater.h
index ef2767d..af808d8 100644
--- a/chrome/service/cloud_print/job_status_updater.h
+++ b/chrome/service/cloud_print/job_status_updater.h
@@ -15,6 +15,8 @@
#include "googleurl/src/gurl.h"
#include "net/url_request/url_request_status.h"
+namespace cloud_print {
+
// Periodically monitors the status of a local print job and updates the
// cloud print server accordingly. When the job has been completed this
// object releases the reference to itself which should cause it to
@@ -33,9 +35,9 @@ class JobStatusUpdater : public base::RefCountedThreadSafe<JobStatusUpdater>,
JobStatusUpdater(const std::string& printer_name,
const std::string& job_id,
- cloud_print::PlatformJobId& local_job_id,
+ PlatformJobId& local_job_id,
const GURL& cloud_print_server_url,
- cloud_print::PrintSystem* print_system,
+ PrintSystem* print_system,
Delegate* delegate);
// Checks the status of the local print job and sends an update.
@@ -57,11 +59,11 @@ class JobStatusUpdater : public base::RefCountedThreadSafe<JobStatusUpdater>,
std::string printer_name_;
std::string job_id_;
- cloud_print::PlatformJobId local_job_id_;
- cloud_print::PrintJobDetails last_job_details_;
+ PlatformJobId local_job_id_;
+ PrintJobDetails last_job_details_;
scoped_refptr<CloudPrintURLFetcher> request_;
GURL cloud_print_server_url_;
- scoped_refptr<cloud_print::PrintSystem> print_system_;
+ scoped_refptr<PrintSystem> print_system_;
Delegate* delegate_;
// A flag that is set to true in Stop() and will ensure the next scheduled
// task will do nothing.
@@ -75,4 +77,6 @@ class JobStatusUpdater : public base::RefCountedThreadSafe<JobStatusUpdater>,
// the workaround was not needed for my machine).
typedef JobStatusUpdater::Delegate JobStatusUpdaterDelegate;
+} // namespace cloud_print
+
#endif // CHROME_SERVICE_CLOUD_PRINT_JOB_STATUS_UPDATER_H_
diff --git a/chrome/service/cloud_print/print_system_cups.cc b/chrome/service/cloud_print/print_system_cups.cc
index f1c3fa3..0fb19d4 100644
--- a/chrome/service/cloud_print/print_system_cups.cc
+++ b/chrome/service/cloud_print/print_system_cups.cc
@@ -26,7 +26,7 @@
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/common/child_process_logging.h"
-#include "chrome/service/cloud_print/cloud_print_consts.h"
+#include "chrome/common/cloud_print/cloud_print_constants.h"
#include "chrome/service/cloud_print/cloud_print_helpers.h"
#include "googleurl/src/gurl.h"
#include "grit/generated_resources.h"
@@ -786,7 +786,7 @@ PlatformJobId PrintSystemCUPS::SpoolPrintJob(
DCHECK(res); // If print ticket is invalid we still print using defaults.
// Check if this is a dry run (test) job.
- *dry_run = CloudPrintHelpers::IsDryRunJob(tags);
+ *dry_run = IsDryRunJob(tags);
if (*dry_run) {
VLOG(1) << "CP_CUPS: Dry run job spooled";
return kDryRunJobId;
diff --git a/chrome/service/cloud_print/printer_job_handler.cc b/chrome/service/cloud_print/printer_job_handler.cc
index 0f08948..035355b 100644
--- a/chrome/service/cloud_print/printer_job_handler.cc
+++ b/chrome/service/cloud_print/printer_job_handler.cc
@@ -12,8 +12,8 @@
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
+#include "chrome/common/cloud_print/cloud_print_constants.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_helpers.h"
#include "chrome/service/cloud_print/job_status_updater.h"
#include "googleurl/src/gurl.h"
@@ -23,6 +23,8 @@
#include "printing/backend/print_backend.h"
#include "ui/base/l10n/l10n_util.h"
+namespace cloud_print {
+
PrinterJobHandler::JobDetails::JobDetails() {}
PrinterJobHandler::JobDetails::~JobDetails() {}
@@ -40,7 +42,7 @@ PrinterJobHandler::PrinterJobHandler(
const printing::PrinterBasicInfo& printer_info,
const PrinterInfoFromCloud& printer_info_cloud,
const GURL& cloud_print_server_url,
- cloud_print::PrintSystem* print_system,
+ PrintSystem* print_system,
Delegate* delegate)
: print_system_(print_system),
printer_info_(printer_info),
@@ -161,7 +163,7 @@ CloudPrintURLFetcher::ResponseAction PrinterJobHandler::OnRequestAuthError() {
}
std::string PrinterJobHandler::GetAuthHeader() {
- return CloudPrintHelpers::GetCloudPrintAuthHeaderFromStore();
+ return GetCloudPrintAuthHeaderFromStore();
}
// JobStatusUpdater::Delegate implementation
@@ -208,8 +210,7 @@ void PrinterJobHandler::OnJobChanged() {
}
}
-void PrinterJobHandler::OnJobSpoolSucceeded(
- const cloud_print::PlatformJobId& job_id) {
+void PrinterJobHandler::OnJobSpoolSucceeded(const PlatformJobId& job_id) {
DCHECK(MessageLoop::current() == print_thread_.message_loop());
job_spooler_ = NULL;
job_handler_message_loop_proxy_->PostTask(
@@ -423,7 +424,7 @@ void PrinterJobHandler::Start() {
SetNextJSONHandler(&PrinterJobHandler::HandleJobMetadataResponse);
request_ = new CloudPrintURLFetcher;
request_->StartGetRequest(
- CloudPrintHelpers::GetUrlForJobFetch(
+ GetUrlForJobFetch(
cloud_print_server_url_, printer_info_cloud_.printer_id,
job_fetch_reason_),
this,
@@ -478,7 +479,7 @@ void PrinterJobHandler::Reset() {
print_thread_.Stop();
}
-void PrinterJobHandler::UpdateJobStatus(cloud_print::PrintJobStatus status,
+void PrinterJobHandler::UpdateJobStatus(PrintJobStatus status,
PrintJobError error) {
VLOG(1) << "CP_CONNECTOR: Updating job status"
<< ", printer id: " << printer_info_cloud_.printer_id
@@ -504,10 +505,9 @@ void PrinterJobHandler::UpdateJobStatus(cloud_print::PrintJobStatus status,
&PrinterJobHandler::HandleFailureStatusUpdateResponse);
}
request_ = new CloudPrintURLFetcher;
- request_->StartGetRequest(
- CloudPrintHelpers::GetUrlForJobStatusUpdate(cloud_print_server_url_,
- job_details_.job_id_,
- status),
+ request_->StartGetRequest(GetUrlForJobStatusUpdate(cloud_print_server_url_,
+ job_details_.job_id_,
+ status),
this,
kCloudPrintAPIMaxRetryCount,
std::string());
@@ -529,19 +529,19 @@ void PrinterJobHandler::JobFailed(PrintJobError error) {
<< ", job id: " << job_details_.job_id_
<< ", error: " << error;
if (!shutting_down_) {
- UpdateJobStatus(cloud_print::PRINT_JOB_STATUS_ERROR, error);
+ UpdateJobStatus(PRINT_JOB_STATUS_ERROR, error);
// This job failed, but others may be pending. Schedule a check.
job_check_pending_ = true;
}
}
-void PrinterJobHandler::JobSpooled(cloud_print::PlatformJobId local_job_id) {
+void PrinterJobHandler::JobSpooled(PlatformJobId local_job_id) {
VLOG(1) << "CP_CONNECTOR: 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);
+ UpdateJobStatus(PRINT_JOB_STATUS_IN_PROGRESS, SUCCESS);
print_thread_.Stop();
}
}
@@ -597,7 +597,7 @@ void PrinterJobHandler::OnReceivePrinterCaps(
std::string post_data;
std::string mime_boundary;
- cloud_print::CreateMimeBoundaryForUpload(&mime_boundary);
+ CreateMimeBoundaryForUpload(&mime_boundary);
if (succeeded) {
std::string caps_hash =
@@ -606,13 +606,13 @@ void PrinterJobHandler::OnReceivePrinterCaps(
// 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;
- cloud_print::AddMultipartValueForUpload(kPrinterCapsValue,
+ AddMultipartValueForUpload(kPrinterCapsValue,
caps_and_defaults.printer_capabilities, mime_boundary,
caps_and_defaults.caps_mime_type, &post_data);
- cloud_print::AddMultipartValueForUpload(kPrinterDefaultsValue,
+ AddMultipartValueForUpload(kPrinterDefaultsValue,
caps_and_defaults.printer_defaults, mime_boundary,
caps_and_defaults.defaults_mime_type, &post_data);
- cloud_print::AddMultipartValueForUpload(kPrinterCapsHashValue,
+ AddMultipartValueForUpload(kPrinterCapsHashValue,
caps_hash, mime_boundary, std::string(), &post_data);
}
} else {
@@ -620,29 +620,28 @@ void PrinterJobHandler::OnReceivePrinterCaps(
<< ", printer name: " << printer_name;
}
- std::string tags_hash = CloudPrintHelpers::GetHashOfPrinterTags(printer_info);
+ std::string tags_hash = GetHashOfPrinterInfo(printer_info);
if (tags_hash != printer_info_cloud_.tags_hash) {
printer_info_cloud_.tags_hash = tags_hash;
- post_data += CloudPrintHelpers::GetPostDataForPrinterTags(printer_info,
- mime_boundary);
+ post_data += GetPostDataForPrinterInfo(printer_info, mime_boundary);
// Remove all the existing proxy tags.
- std::string cp_tag_wildcard(kProxyTagPrefix);
+ std::string cp_tag_wildcard(kCloudPrintServiceProxyTagPrefix);
cp_tag_wildcard += ".*";
- cloud_print::AddMultipartValueForUpload(kPrinterRemoveTagValue,
+ AddMultipartValueForUpload(kPrinterRemoveTagValue,
cp_tag_wildcard, mime_boundary, std::string(), &post_data);
}
if (printer_info.printer_name != printer_info_.printer_name) {
- cloud_print::AddMultipartValueForUpload(kPrinterNameValue,
+ AddMultipartValueForUpload(kPrinterNameValue,
printer_info.printer_name, mime_boundary, std::string(), &post_data);
}
if (printer_info.printer_description != printer_info_.printer_description) {
- cloud_print::AddMultipartValueForUpload(kPrinterDescValue,
+ AddMultipartValueForUpload(kPrinterDescValue,
printer_info.printer_description, mime_boundary,
std::string(), &post_data);
}
if (printer_info.printer_status != printer_info_.printer_status) {
- cloud_print::AddMultipartValueForUpload(kPrinterStatusValue,
+ AddMultipartValueForUpload(kPrinterStatusValue,
base::StringPrintf("%d", printer_info.printer_status), mime_boundary,
std::string(), &post_data);
}
@@ -655,7 +654,7 @@ void PrinterJobHandler::OnReceivePrinterCaps(
SetNextJSONHandler(&PrinterJobHandler::HandlePrinterUpdateResponse);
request_ = new CloudPrintURLFetcher;
request_->StartPostRequest(
- CloudPrintHelpers::GetUrlForPrinterUpdate(
+ GetUrlForPrinterUpdate(
cloud_print_server_url_, printer_info_cloud_.printer_id),
this,
kCloudPrintAPIMaxRetryCount,
@@ -697,3 +696,5 @@ void PrinterJobHandler::DoPrint(const JobDetails& job_details,
OnJobSpoolFailed();
}
}
+
+} // namespace cloud_print
diff --git a/chrome/service/cloud_print/printer_job_handler.h b/chrome/service/cloud_print/printer_job_handler.h
index 7ee440c..9090ca3 100644
--- a/chrome/service/cloud_print/printer_job_handler.h
+++ b/chrome/service/cloud_print/printer_job_handler.h
@@ -61,11 +61,13 @@ class URLFetcher;
// Stop
// (If there are pending tasks go back to Start)
+namespace cloud_print {
+
class PrinterJobHandler : public base::RefCountedThreadSafe<PrinterJobHandler>,
public CloudPrintURLFetcherDelegate,
public JobStatusUpdaterDelegate,
- public cloud_print::PrinterWatcherDelegate,
- public cloud_print::JobSpoolerDelegate {
+ public PrinterWatcherDelegate,
+ public JobSpoolerDelegate {
public:
class Delegate {
public:
@@ -88,7 +90,7 @@ class PrinterJobHandler : public base::RefCountedThreadSafe<PrinterJobHandler>,
PrinterJobHandler(const printing::PrinterBasicInfo& printer_info,
const PrinterInfoFromCloud& printer_info_from_server,
const GURL& cloud_print_server_url,
- cloud_print::PrintSystem* print_system,
+ PrintSystem* print_system,
Delegate* delegate);
bool Initialize();
@@ -132,15 +134,14 @@ class PrinterJobHandler : public base::RefCountedThreadSafe<PrinterJobHandler>,
virtual bool OnJobCompleted(JobStatusUpdater* updater) OVERRIDE;
virtual void OnAuthError() OVERRIDE;
- // cloud_print::PrinterWatcherDelegate implementation
+ // PrinterWatcherDelegate implementation
virtual void OnPrinterDeleted() OVERRIDE;
virtual void OnPrinterChanged() OVERRIDE;
virtual void OnJobChanged() OVERRIDE;
- // cloud_print::JobSpoolerDelegate implementation.
+ // JobSpoolerDelegate implementation.
// Called on print_thread_.
- virtual void OnJobSpoolSucceeded(
- const cloud_print::PlatformJobId& job_id) OVERRIDE;
+ virtual void OnJobSpoolSucceeded(const PlatformJobId& job_id) OVERRIDE;
virtual void OnJobSpoolFailed() OVERRIDE;
// End Delegate implementations
@@ -229,7 +230,7 @@ class PrinterJobHandler : public base::RefCountedThreadSafe<PrinterJobHandler>,
void StartPrinting();
void Reset();
- void UpdateJobStatus(cloud_print::PrintJobStatus status, PrintJobError error);
+ void UpdateJobStatus(PrintJobStatus status, PrintJobError error);
// Sets the next response handler to the specifed JSON data handler.
void SetNextJSONHandler(JSONDataHandler handler);
@@ -237,7 +238,7 @@ class PrinterJobHandler : public base::RefCountedThreadSafe<PrinterJobHandler>,
void SetNextDataHandler(DataHandler handler);
void JobFailed(PrintJobError error);
- void JobSpooled(cloud_print::PlatformJobId local_job_id);
+ void JobSpooled(PlatformJobId local_job_id);
// Returns false if printer info is up to date and no updating is needed.
bool UpdatePrinterInfo();
bool HavePendingTasks();
@@ -254,7 +255,7 @@ class PrinterJobHandler : public base::RefCountedThreadSafe<PrinterJobHandler>,
const std::string& printer_name);
scoped_refptr<CloudPrintURLFetcher> request_;
- scoped_refptr<cloud_print::PrintSystem> print_system_;
+ scoped_refptr<PrintSystem> print_system_;
printing::PrinterBasicInfo printer_info_;
PrinterInfoFromCloud printer_info_cloud_;
GURL cloud_print_server_url_;
@@ -263,7 +264,7 @@ class PrinterJobHandler : public base::RefCountedThreadSafe<PrinterJobHandler>,
Delegate* delegate_;
// Once the job has been spooled to the local spooler, this specifies the
// job id of the job on the local spooler.
- cloud_print::PlatformJobId local_job_id_;
+ PlatformJobId local_job_id_;
// The next response handler can either be a JSONDataHandler or a
// DataHandler (depending on the current request being made).
@@ -275,7 +276,7 @@ class PrinterJobHandler : public base::RefCountedThreadSafe<PrinterJobHandler>,
base::Thread print_thread_;
// The Job spooler object. This is only non-NULL during a print operation.
// It lives and dies on |print_thread_|
- scoped_refptr<cloud_print::PrintSystem::JobSpooler> job_spooler_;
+ scoped_refptr<PrintSystem::JobSpooler> job_spooler_;
// The message loop proxy representing the thread on which this object
// was created. Used by the print thread.
scoped_refptr<base::MessageLoopProxy> job_handler_message_loop_proxy_;
@@ -293,7 +294,7 @@ class PrinterJobHandler : public base::RefCountedThreadSafe<PrinterJobHandler>,
// Some task in the state machine is in progress.
bool task_in_progress_;
- scoped_refptr<cloud_print::PrintSystem::PrinterWatcher> printer_watcher_;
+ scoped_refptr<PrintSystem::PrinterWatcher> printer_watcher_;
typedef std::list< scoped_refptr<JobStatusUpdater> > JobStatusUpdaterList;
JobStatusUpdaterList job_status_updater_list_;
@@ -309,4 +310,6 @@ class PrinterJobHandler : public base::RefCountedThreadSafe<PrinterJobHandler>,
// the workaround was not needed for my machine).
typedef PrinterJobHandler::Delegate PrinterJobHandlerDelegate;
+} // namespace cloud_print
+
#endif // CHROME_SERVICE_CLOUD_PRINT_PRINTER_JOB_HANDLER_H_
diff --git a/chrome/service/service_process.cc b/chrome/service/service_process.cc
index 40607d9..f7aa291 100644
--- a/chrome/service/service_process.cc
+++ b/chrome/service/service_process.cc
@@ -270,9 +270,9 @@ bool ServiceProcess::HandleClientDisconnect() {
return true;
}
-CloudPrintProxy* ServiceProcess::GetCloudPrintProxy() {
+cloud_print::CloudPrintProxy* ServiceProcess::GetCloudPrintProxy() {
if (!cloud_print_proxy_.get()) {
- cloud_print_proxy_.reset(new CloudPrintProxy());
+ cloud_print_proxy_.reset(new cloud_print::CloudPrintProxy());
cloud_print_proxy_->Initialize(service_prefs_.get(), this);
}
return cloud_print_proxy_.get();
diff --git a/chrome/service/service_process.h b/chrome/service/service_process.h
index af2afb5..8bc4445 100644
--- a/chrome/service/service_process.h
+++ b/chrome/service/service_process.h
@@ -31,7 +31,7 @@ class CommandLine;
// process can live independently of the browser process.
// ServiceProcess Design Notes
// https://sites.google.com/a/chromium.org/dev/developers/design-documents/service-processes
-class ServiceProcess : public CloudPrintProxy::Client {
+class ServiceProcess : public cloud_print::CloudPrintProxy::Client {
public:
ServiceProcess();
virtual ~ServiceProcess();
@@ -86,7 +86,7 @@ class ServiceProcess : public CloudPrintProxy::Client {
// connections.
bool HandleClientDisconnect();
- CloudPrintProxy* GetCloudPrintProxy();
+ cloud_print::CloudPrintProxy* GetCloudPrintProxy();
// CloudPrintProxy::Client implementation.
virtual void OnCloudPrintProxyEnabled(bool persist_state) OVERRIDE;
@@ -125,7 +125,7 @@ class ServiceProcess : public CloudPrintProxy::Client {
scoped_ptr<base::Thread> io_thread_;
scoped_ptr<base::Thread> file_thread_;
scoped_refptr<base::SequencedWorkerPool> blocking_pool_;
- scoped_ptr<CloudPrintProxy> cloud_print_proxy_;
+ scoped_ptr<cloud_print::CloudPrintProxy> cloud_print_proxy_;
scoped_ptr<ServiceProcessPrefs> service_prefs_;
scoped_ptr<ServiceIPCServer> ipc_server_;
scoped_ptr<ServiceProcessState> service_process_state_;