Commit 01de7ac6 authored by skau's avatar skau Committed by Commit bot

Add an autoconf field to printer objects.

Printers can be configured without PPDs.  This will be represented by
the field 'autoconf.'  This adds the field to the printer object and the
PrinterSpecifics proto.

BUG=685676

Review-Url: https://codereview.chromium.org/2884863002
Cr-Commit-Position: refs/heads/master@{#474004}
parent 8e36d829
...@@ -21,24 +21,30 @@ namespace { ...@@ -21,24 +21,30 @@ namespace {
Printer::PpdReference SpecificsToPpd( Printer::PpdReference SpecificsToPpd(
const sync_pb::PrinterPPDReference& specifics) { const sync_pb::PrinterPPDReference& specifics) {
Printer::PpdReference ref; Printer::PpdReference ref;
if (specifics.has_user_supplied_ppd_url()) { if (specifics.autoconf()) {
ref.autoconf = specifics.autoconf();
} else if (specifics.has_user_supplied_ppd_url()) {
ref.user_supplied_ppd_url = specifics.user_supplied_ppd_url(); ref.user_supplied_ppd_url = specifics.user_supplied_ppd_url();
} } else if (specifics.has_effective_make_and_model()) {
if (specifics.has_effective_make_and_model()) {
ref.effective_make_and_model = specifics.effective_make_and_model(); ref.effective_make_and_model = specifics.effective_make_and_model();
} }
return ref; return ref;
} }
// Overwrite fields in |specifics| with an appropriately filled field from
// |ref|. If |ref| is the default object, nothing will be changed in
// |specifics|.
void MergeReferenceToSpecifics(sync_pb::PrinterPPDReference* specifics, void MergeReferenceToSpecifics(sync_pb::PrinterPPDReference* specifics,
const Printer::PpdReference& ref) { const Printer::PpdReference& ref) {
if (!ref.user_supplied_ppd_url.empty()) { if (ref.autoconf) {
specifics->Clear();
specifics->set_autoconf(ref.autoconf);
} else if (!ref.user_supplied_ppd_url.empty()) {
specifics->Clear();
specifics->set_user_supplied_ppd_url(ref.user_supplied_ppd_url); specifics->set_user_supplied_ppd_url(ref.user_supplied_ppd_url);
} } else if (!ref.effective_make_and_model.empty()) {
specifics->Clear();
if (!ref.effective_make_and_model.empty()) {
specifics->set_effective_make_and_model(ref.effective_make_and_model); specifics->set_effective_make_and_model(ref.effective_make_and_model);
} }
} }
......
...@@ -13,13 +13,21 @@ ...@@ -13,13 +13,21 @@
namespace chromeos { namespace chromeos {
namespace printing { namespace printing {
// Convert |printer| into its local representation. Enforces that only one
// field in PpdReference is filled in. In order of preference, we populate
// autoconf, user_supplied_ppd_url, or effective_make_and_model.
std::unique_ptr<Printer> SpecificsToPrinter( std::unique_ptr<Printer> SpecificsToPrinter(
const sync_pb::PrinterSpecifics& printer); const sync_pb::PrinterSpecifics& printer);
// Convert |printer| into its proto representation.
std::unique_ptr<sync_pb::PrinterSpecifics> PrinterToSpecifics( std::unique_ptr<sync_pb::PrinterSpecifics> PrinterToSpecifics(
const Printer& printer); const Printer& printer);
// Merge fields from |printer| into |specifics|. // Merge fields from |printer| into |specifics|. Merge strategy is to only
// write non-default fields from |printer| into the appropriate field in
// |specifics|. Default fields are skipped to prevent accidentally clearing
// |specifics|. Enforces field exclusivity in PpdReference as described in
// SpecificsToPrinter.
void MergePrinterToSpecifics(const Printer& printer, void MergePrinterToSpecifics(const Printer& printer,
sync_pb::PrinterSpecifics* specifics); sync_pb::PrinterSpecifics* specifics);
......
...@@ -22,6 +22,7 @@ const char uri[] = "ipps://notaprinter.chromium.org/ipp/print"; ...@@ -22,6 +22,7 @@ const char uri[] = "ipps://notaprinter.chromium.org/ipp/print";
const char uuid[] = "UUIDUUIDUUID"; const char uuid[] = "UUIDUUIDUUID";
const base::Time kUpdateTime = base::Time::FromInternalValue(22114455660000); const base::Time kUpdateTime = base::Time::FromInternalValue(22114455660000);
const char kUserSuppliedPPD[] = "file://foo/bar/baz/eeaaaffccdd00";
const char effective_make_and_model[] = "Manufacturer Model T1000"; const char effective_make_and_model[] = "Manufacturer Model T1000";
} // namespace } // namespace
...@@ -56,6 +57,7 @@ TEST(SpecificsTranslationTest, SpecificsToPrinter) { ...@@ -56,6 +57,7 @@ TEST(SpecificsTranslationTest, SpecificsToPrinter) {
EXPECT_EQ(effective_make_and_model, EXPECT_EQ(effective_make_and_model,
result->ppd_reference().effective_make_and_model); result->ppd_reference().effective_make_and_model);
EXPECT_FALSE(result->IsIppEverywhere());
} }
TEST(SpecificsTranslationTest, PrinterToSpecifics) { TEST(SpecificsTranslationTest, PrinterToSpecifics) {
...@@ -97,7 +99,7 @@ TEST(SpecificsTranslationTest, SpecificsToPrinterRoundTrip) { ...@@ -97,7 +99,7 @@ TEST(SpecificsTranslationTest, SpecificsToPrinterRoundTrip) {
printer.set_uuid(uuid); printer.set_uuid(uuid);
Printer::PpdReference ppd; Printer::PpdReference ppd;
ppd.effective_make_and_model = effective_make_and_model; ppd.autoconf = true;
*printer.mutable_ppd_reference() = ppd; *printer.mutable_ppd_reference() = ppd;
std::unique_ptr<sync_pb::PrinterSpecifics> temp = PrinterToSpecifics(printer); std::unique_ptr<sync_pb::PrinterSpecifics> temp = PrinterToSpecifics(printer);
...@@ -111,8 +113,58 @@ TEST(SpecificsTranslationTest, SpecificsToPrinterRoundTrip) { ...@@ -111,8 +113,58 @@ TEST(SpecificsTranslationTest, SpecificsToPrinterRoundTrip) {
EXPECT_EQ(uri, result->uri()); EXPECT_EQ(uri, result->uri());
EXPECT_EQ(uuid, result->uuid()); EXPECT_EQ(uuid, result->uuid());
EXPECT_TRUE(result->ppd_reference().effective_make_and_model.empty());
EXPECT_TRUE(result->ppd_reference().autoconf);
}
TEST(SpecificsTranslationTest, MergePrinterToSpecifics) {
sync_pb::PrinterSpecifics original;
original.set_id(id);
original.mutable_ppd_reference()->set_autoconf(true);
Printer printer(id);
printer.mutable_ppd_reference()->effective_make_and_model =
effective_make_and_model;
MergePrinterToSpecifics(printer, &original);
EXPECT_EQ(id, original.id());
EXPECT_EQ(effective_make_and_model, EXPECT_EQ(effective_make_and_model,
result->ppd_reference().effective_make_and_model); original.ppd_reference().effective_make_and_model());
// Verify that autoconf is cleared.
EXPECT_FALSE(original.ppd_reference().autoconf());
}
// Tests that the autoconf value overrides other PpdReference fields.
TEST(SpecificsTranslationTest, AutoconfOverrides) {
sync_pb::PrinterSpecifics original;
original.set_id(id);
auto* ppd_reference = original.mutable_ppd_reference();
ppd_reference->set_autoconf(true);
ppd_reference->set_user_supplied_ppd_url(kUserSuppliedPPD);
auto printer = SpecificsToPrinter(original);
EXPECT_TRUE(printer->ppd_reference().autoconf);
EXPECT_TRUE(printer->ppd_reference().user_supplied_ppd_url.empty());
EXPECT_TRUE(printer->ppd_reference().effective_make_and_model.empty());
}
// Tests that user_supplied_ppd_url overwrites other PpdReference fields if
// autoconf is false.
TEST(SpecificsTranslationTest, UserSuppliedOverrides) {
sync_pb::PrinterSpecifics original;
original.set_id(id);
auto* ppd_reference = original.mutable_ppd_reference();
ppd_reference->set_user_supplied_ppd_url(kUserSuppliedPPD);
ppd_reference->set_effective_make_and_model(effective_make_and_model);
auto printer = SpecificsToPrinter(original);
EXPECT_FALSE(printer->ppd_reference().autoconf);
EXPECT_FALSE(printer->ppd_reference().user_supplied_ppd_url.empty());
EXPECT_TRUE(printer->ppd_reference().effective_make_and_model.empty());
} }
} // namespace printing } // namespace printing
......
...@@ -27,8 +27,7 @@ Printer& Printer::operator=(const Printer& other) = default; ...@@ -27,8 +27,7 @@ Printer& Printer::operator=(const Printer& other) = default;
Printer::~Printer() {} Printer::~Printer() {}
bool Printer::IsIppEverywhere() const { bool Printer::IsIppEverywhere() const {
// TODO(skau): Add check for IPP Everywhere value. return ppd_reference_.autoconf;
return false;
} }
} // namespace chromeos } // namespace chromeos
...@@ -36,6 +36,9 @@ class CHROMEOS_EXPORT Printer { ...@@ -36,6 +36,9 @@ class CHROMEOS_EXPORT Printer {
// Where possible, this is the same as the ipp/ldap // Where possible, this is the same as the ipp/ldap
// printer-make-and-model field. // printer-make-and-model field.
std::string effective_make_and_model; std::string effective_make_and_model;
// True if the printer should be auto-configured and a PPD is unnecessary.
bool autoconf = false;
}; };
// The location where the printer is stored. // The location where the printer is stored.
......
...@@ -25,6 +25,9 @@ message PrinterPPDReference { ...@@ -25,6 +25,9 @@ message PrinterPPDReference {
// String identifying the type of printer, used to look up a ppd to drive the // String identifying the type of printer, used to look up a ppd to drive the
// printer. // printer.
optional string effective_make_and_model = 4; optional string effective_make_and_model = 4;
// True if the printer should be automatically configured, false otherwise.
optional bool autoconf = 5 [default = false];
} }
message PrinterSpecifics { message PrinterSpecifics {
......
...@@ -669,6 +669,7 @@ VISIT_PROTO_FIELDS(const sync_pb::PreferenceSpecifics& proto) { ...@@ -669,6 +669,7 @@ VISIT_PROTO_FIELDS(const sync_pb::PreferenceSpecifics& proto) {
VISIT_PROTO_FIELDS(const sync_pb::PrinterPPDReference& proto) { VISIT_PROTO_FIELDS(const sync_pb::PrinterPPDReference& proto) {
VISIT(user_supplied_ppd_url); VISIT(user_supplied_ppd_url);
VISIT(effective_make_and_model); VISIT(effective_make_and_model);
VISIT(autoconf);
} }
VISIT_PROTO_FIELDS(const sync_pb::PrinterSpecifics& proto) { VISIT_PROTO_FIELDS(const sync_pb::PrinterSpecifics& proto) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment