Include user email into document title before spooling
Could be used to monitor print jobs on OS side. Windows spooler "owner" cannot be changed so we should modify title. Max title length increased from 50 to 80 better readability. BUG=504826 Review URL: https://codereview.chromium.org/1212883003 Cr-Commit-Position: refs/heads/master@{#337647}
This commit is contained in:
chrome
common
service
printing
@ -42,6 +42,7 @@ const char kFileUrlValue[] = "fileUrl";
|
||||
const char kPrinterListValue[] = "printers";
|
||||
const char kJobListValue[] = "jobs";
|
||||
const char kTitleValue[] = "title";
|
||||
const char kOwnerValue[] = "ownerId";
|
||||
const char kPrinterCapsHashValue[] = "capsHash";
|
||||
const char kTagsValue[] = "tags";
|
||||
const char kXMPPJidValue[] = "xmpp_jid";
|
||||
|
@ -51,6 +51,7 @@ extern const char kFileUrlValue[];
|
||||
extern const char kPrinterListValue[];
|
||||
extern const char kJobListValue[];
|
||||
extern const char kTitleValue[];
|
||||
extern const char kOwnerValue[];
|
||||
extern const char kPrinterCapsHashValue[];
|
||||
extern const char kTagsValue[];
|
||||
extern const char kXMPPJidValue[];
|
||||
|
@ -792,12 +792,15 @@ void PrinterJobHandler::DoPrint(const JobDetails& job_details,
|
||||
DCHECK(job_spooler_.get());
|
||||
if (!job_spooler_.get())
|
||||
return;
|
||||
base::string16 document_name = printing::SimplifyDocumentTitle(
|
||||
base::UTF8ToUTF16(job_details.job_title_));
|
||||
if (document_name.empty()) {
|
||||
document_name = printing::SimplifyDocumentTitle(
|
||||
l10n_util::GetStringUTF16(IDS_DEFAULT_PRINT_DOCUMENT_TITLE));
|
||||
}
|
||||
|
||||
base::string16 document_name =
|
||||
job_details.job_title_.empty()
|
||||
? l10n_util::GetStringUTF16(IDS_DEFAULT_PRINT_DOCUMENT_TITLE)
|
||||
: base::UTF8ToUTF16(job_details.job_title_);
|
||||
|
||||
document_name = printing::FormatDocumentTitleWithOwner(
|
||||
base::UTF8ToUTF16(job_details.job_owner_), document_name);
|
||||
|
||||
UMA_HISTOGRAM_ENUMERATION("CloudPrint.JobHandlerEvent",
|
||||
JOB_HANDLER_START_SPOOLING, JOB_HANDLER_MAX);
|
||||
spooling_start_time_ = base::Time::Now();
|
||||
|
@ -28,6 +28,7 @@ JobDetails::~JobDetails() {}
|
||||
void JobDetails::Clear() {
|
||||
job_id_.clear();
|
||||
job_title_.clear();
|
||||
job_owner_.clear();
|
||||
print_ticket_.clear();
|
||||
print_ticket_mime_type_.clear();
|
||||
print_data_mime_type_.clear();
|
||||
@ -58,6 +59,7 @@ void PrinterJobQueueHandler::ConstructJobDetailsFromJson(
|
||||
|
||||
job_data->GetString(kIdValue, &job_details->job_id_);
|
||||
job_data->GetString(kTitleValue, &job_details->job_title_);
|
||||
job_data->GetString(kOwnerValue, &job_details->job_owner_);
|
||||
|
||||
job_data->GetString(kTicketUrlValue, &job_details->print_ticket_url_);
|
||||
job_data->GetString(kFileUrlValue, &job_details->print_data_url_);
|
||||
|
@ -31,6 +31,7 @@ struct JobDetails {
|
||||
|
||||
std::string job_id_;
|
||||
std::string job_title_;
|
||||
std::string job_owner_;
|
||||
|
||||
std::string print_ticket_url_;
|
||||
std::string print_data_url_;
|
||||
|
@ -6,23 +6,57 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "base/logging.h"
|
||||
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "third_party/icu/source/common/unicode/uchar.h"
|
||||
#include "ui/gfx/text_elider.h"
|
||||
|
||||
namespace {
|
||||
const int kMaxDocumentTitleLength = 50;
|
||||
}
|
||||
|
||||
namespace printing {
|
||||
|
||||
base::string16 SimplifyDocumentTitle(const base::string16& title) {
|
||||
namespace {
|
||||
|
||||
const size_t kMaxDocumentTitleLength = 80;
|
||||
|
||||
} // namespace
|
||||
|
||||
base::string16 SimplifyDocumentTitleWithLength(const base::string16& title,
|
||||
size_t length) {
|
||||
base::string16 no_controls(title);
|
||||
no_controls.erase(
|
||||
std::remove_if(no_controls.begin(), no_controls.end(), &u_iscntrl),
|
||||
no_controls.end());
|
||||
base::string16 result;
|
||||
gfx::ElideString(no_controls, kMaxDocumentTitleLength, &result);
|
||||
gfx::ElideString(no_controls, static_cast<int>(length), &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
base::string16 FormatDocumentTitleWithOwnerAndLength(
|
||||
const base::string16& owner,
|
||||
const base::string16& title,
|
||||
size_t length) {
|
||||
const base::string16 separator = base::ASCIIToUTF16(": ");
|
||||
DCHECK(separator.size() < length);
|
||||
|
||||
base::string16 short_title =
|
||||
SimplifyDocumentTitleWithLength(owner, length - separator.size());
|
||||
short_title += separator;
|
||||
if (short_title.size() < length) {
|
||||
short_title +=
|
||||
SimplifyDocumentTitleWithLength(title, length - short_title.size());
|
||||
}
|
||||
|
||||
return short_title;
|
||||
}
|
||||
|
||||
base::string16 SimplifyDocumentTitle(const base::string16& title) {
|
||||
return SimplifyDocumentTitleWithLength(title, kMaxDocumentTitleLength);
|
||||
}
|
||||
|
||||
base::string16 FormatDocumentTitleWithOwner(const base::string16& owner,
|
||||
const base::string16& title) {
|
||||
return FormatDocumentTitleWithOwnerAndLength(owner, title,
|
||||
kMaxDocumentTitleLength);
|
||||
}
|
||||
|
||||
} // namespace printing
|
||||
|
@ -14,6 +14,19 @@ namespace printing {
|
||||
PRINTING_EXPORT base::string16 SimplifyDocumentTitle(
|
||||
const base::string16& title);
|
||||
|
||||
PRINTING_EXPORT base::string16 SimplifyDocumentTitleWithLength(
|
||||
const base::string16& title,
|
||||
size_t length);
|
||||
|
||||
PRINTING_EXPORT base::string16 FormatDocumentTitleWithOwner(
|
||||
const base::string16& owner,
|
||||
const base::string16& title);
|
||||
|
||||
PRINTING_EXPORT base::string16 FormatDocumentTitleWithOwnerAndLength(
|
||||
const base::string16& owner,
|
||||
const base::string16& title,
|
||||
size_t length);
|
||||
|
||||
} // namespace printing
|
||||
|
||||
#endif // PRINTING_PRINTING_UTILS_H_
|
||||
|
@ -8,18 +8,38 @@
|
||||
|
||||
namespace printing {
|
||||
|
||||
std::string Simplify(const char* title) {
|
||||
return base::UTF16ToUTF8(SimplifyDocumentTitle(base::ASCIIToUTF16(title)));
|
||||
namespace {
|
||||
|
||||
const size_t kTestLength = 8;
|
||||
|
||||
std::string Simplify(const std::string& title) {
|
||||
return base::UTF16ToUTF8(
|
||||
SimplifyDocumentTitleWithLength(base::UTF8ToUTF16(title), kTestLength));
|
||||
}
|
||||
|
||||
std::string Format(const std::string& owner, const std::string& title) {
|
||||
return base::UTF16ToUTF8(FormatDocumentTitleWithOwnerAndLength(
|
||||
base::UTF8ToUTF16(owner), base::UTF8ToUTF16(title), kTestLength));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(PrintingUtilsTest, SimplifyDocumentTitle) {
|
||||
EXPECT_STREQ("", Simplify("").c_str());
|
||||
EXPECT_STREQ("Long string. Long string...ng string. Long string.",
|
||||
Simplify("Long string. Long string. Long string. Long string. "
|
||||
"Long string. Long string. Long string.").c_str());
|
||||
EXPECT_STREQ("Control Characters",
|
||||
Simplify("C\ron\ntrol Charac\15ters").c_str());
|
||||
EXPECT_STREQ("", Simplify("\n\r\n\r\t\r").c_str());
|
||||
EXPECT_EQ("", Simplify(""));
|
||||
EXPECT_EQ("abcdefgh", Simplify("abcdefgh"));
|
||||
EXPECT_EQ("abc...ij", Simplify("abcdefghij"));
|
||||
EXPECT_EQ("Controls", Simplify("C\ron\nt\15rols"));
|
||||
EXPECT_EQ("", Simplify("\n\r\n\r\t\r"));
|
||||
}
|
||||
|
||||
TEST(PrintingUtilsTest, FormatDocumentTitleWithOwner) {
|
||||
EXPECT_EQ(": ", Format("", ""));
|
||||
EXPECT_EQ("abc: ", Format("abc", ""));
|
||||
EXPECT_EQ(": 123", Format("", "123"));
|
||||
EXPECT_EQ("abc: 123", Format("abc", "123"));
|
||||
EXPECT_EQ("abc: 0.9", Format("abc", "0123456789"));
|
||||
EXPECT_EQ("ab...j: ", Format("abcdefghij", "123"));
|
||||
EXPECT_EQ("ab...j: ", Format("abcdefghij", "0123456789"));
|
||||
}
|
||||
|
||||
} // namespace printing
|
||||
|
Reference in New Issue
Block a user