Commit f99df198 authored by Piotr Pawliczek's avatar Piotr Pawliczek Committed by Commit Bot

Correct AppSocket printers saved before R86

URIs of AppSocket printers saved in version <=R85 contain
incorrect path component. As a result, the do not work in
versions >=R86. This patch solves the problem by correcting
printers URIs loaded from the user profile.

BUG=chromium:1139589
TEST=tested on atlas by loading an AppSocket printer saved in the version R85

Change-Id: I664e263c36d78209e0bc1f3d291d1d3403a3c0d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2490660
Auto-Submit: Piotr Pawliczek <pawliczek@chromium.org>
Reviewed-by: default avatarSean Kau <skau@chromium.org>
Commit-Queue: Piotr Pawliczek <pawliczek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821755}
parent ea006291
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/check_op.h" #include "base/check_op.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/time/time.h" #include "base/time/time.h"
...@@ -67,8 +68,23 @@ std::unique_ptr<Printer> SpecificsToPrinter( ...@@ -67,8 +68,23 @@ std::unique_ptr<Printer> SpecificsToPrinter(
MakeAndModel(specifics.manufacturer(), specifics.model())); MakeAndModel(specifics.manufacturer(), specifics.model()));
} }
bool result = false;
std::string message; std::string message;
if (!printer->SetUri(specifics.uri(), &message)) Uri uri(specifics.uri());
const Uri::ParserStatus uri_error_code = uri.GetLastParsingError().status;
if (uri_error_code == Uri::ParserStatus::kNoErrors) {
// Versions of Chrome <= R85 saved incorrectly AppSocket printers with a
// default IPP path. Here, we have to make sure that URIs of these types of
// printers do not contain a path component. It would cause an error in the
// printer->SetUri(...) method.
if (uri.GetScheme() == "socket")
uri.SetPathEncoded("");
result = printer->SetUri(uri, &message);
} else {
message = "Malformed URI, error code: " +
base::NumberToString(static_cast<int>(uri_error_code));
}
if (!result)
LOG(WARNING) << message; LOG(WARNING) << message;
printer->set_uuid(specifics.uuid()); printer->set_uuid(specifics.uuid());
......
...@@ -57,6 +57,24 @@ TEST(SpecificsTranslationTest, SpecificsToPrinter) { ...@@ -57,6 +57,24 @@ TEST(SpecificsTranslationTest, SpecificsToPrinter) {
EXPECT_FALSE(result->IsIppEverywhere()); EXPECT_FALSE(result->IsIppEverywhere());
} }
TEST(SpecificsTranslationTest, SpecificsToPrinterSocketUriWithPath) {
sync_pb::PrinterSpecifics specifics;
specifics.set_id(kId);
specifics.set_display_name(kDisplayName);
specifics.set_description(kDescription);
specifics.set_make_and_model(kMakeAndModel);
specifics.set_uri("socket://abc.def:1234/path1/path2");
specifics.set_uuid(kUuid);
specifics.set_updated_timestamp(kUpdateTime.ToJavaTime());
sync_pb::PrinterPPDReference ppd;
ppd.set_effective_make_and_model(kEffectiveMakeAndModel);
*specifics.mutable_ppd_reference() = ppd;
std::unique_ptr<Printer> result = SpecificsToPrinter(specifics);
EXPECT_EQ("socket://abc.def:1234", result->uri().GetNormalized());
}
TEST(SpecificsTranslationTest, PrinterToSpecifics) { TEST(SpecificsTranslationTest, PrinterToSpecifics) {
Printer printer; Printer printer;
printer.set_id(kId); printer.set_id(kId);
......
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