1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/service/cloud_print/cloud_print_service_helpers.h"
7 #include "base/strings/stringprintf.h"
8 #include "chrome/common/cloud_print/cloud_print_constants.h"
9 #include "chrome/common/cloud_print/cloud_print_helpers.h"
10 #include "chrome/service/cloud_print/cloud_print_token_store.h"
11 #include "chrome/service/service_process.h"
15 std::string
StringFromJobStatus(cloud_print::PrintJobStatus status
) {
18 case cloud_print::PRINT_JOB_STATUS_IN_PROGRESS
:
21 case cloud_print::PRINT_JOB_STATUS_ERROR
:
24 case cloud_print::PRINT_JOB_STATUS_COMPLETED
:
37 namespace cloud_print
{
39 GURL
GetUrlForJobStatusUpdate(const GURL
& cloud_print_server_url
,
40 const std::string
& job_id
,
41 PrintJobStatus status
,
43 return GetUrlForJobStatusUpdate(cloud_print_server_url
,
45 StringFromJobStatus(status
),
49 GURL
GetUrlForJobStatusUpdate(const GURL
& cloud_print_server_url
,
50 const std::string
& job_id
,
51 const PrintJobDetails
& details
) {
52 std::string status_string
= StringFromJobStatus(details
.status
);
53 std::string
path(AppendPathToUrl(cloud_print_server_url
, "control"));
54 GURL::Replacements replacements
;
55 replacements
.SetPathStr(path
);
57 base::StringPrintf("jobid=%s&status=%s&code=%d&message=%s"
58 "&numpages=%d&pagesprinted=%d",
60 status_string
.c_str(),
61 details
.platform_status_flags
,
62 details
.status_message
.c_str(),
64 details
.pages_printed
);
65 replacements
.SetQueryStr(query
);
66 return cloud_print_server_url
.ReplaceComponents(replacements
);
69 std::string
GetHashOfPrinterInfo(
70 const printing::PrinterBasicInfo
& printer_info
) {
71 return GetHashOfPrinterTags(printer_info
.options
);
74 std::string
GetPostDataForPrinterInfo(
75 const printing::PrinterBasicInfo
& printer_info
,
76 const std::string
& mime_boundary
) {
77 return GetPostDataForPrinterTags(
80 kCloudPrintServiceProxyTagPrefix
,
81 kCloudPrintServiceTagsHashTagName
);
84 bool IsDryRunJob(const std::vector
<std::string
>& tags
) {
85 return std::find(tags
.begin(), tags
.end(),
86 std::string(kCloudPrintServiceTagDryRunFlag
)) != tags
.end();
89 std::string
GetCloudPrintAuthHeaderFromStore() {
90 CloudPrintTokenStore
* token_store
= CloudPrintTokenStore::current();
91 if (!token_store
|| token_store
->token().empty()) {
92 // Using LOG here for critical errors. GCP connector may run in the headless
93 // mode and error indication might be useful for user in that case.
94 LOG(ERROR
) << "CP_PROXY: Missing OAuth token for request";
97 return GetCloudPrintAuthHeader(token_store
->token());
100 } // namespace cloud_print