Commit 8fabb768 authored by Luum Habtemariam's avatar Luum Habtemariam Committed by Commit Bot

Migrate to metadata v2 and support PPD Restrictions

Update the GetPrintersURL call to utilize metadata_v2. This allows for certain
restrictions to be placed on the model to determine whether or not the printer should be displayed

Bug: chromium:773766
Change-Id: Iaade00489a066340a095b3b07bbd853f13f8e35a
Reviewed-on: https://chromium-review.googlesource.com/797476
Commit-Queue: Luum Habtemariam <luum@chromium.org>
Reviewed-by: default avatarSean Kau <skau@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521064}
parent 76107e3c
......@@ -11,6 +11,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chromeos/printing/ppd_cache.h"
#include "chromeos/printing/ppd_provider.h"
#include "components/version_info/version_info.h"
#include "google_apis/google_api_keys.h"
#include "net/url_request/url_request_context_getter.h"
......@@ -22,7 +23,8 @@ scoped_refptr<PpdProvider> CreatePpdProvider(Profile* profile) {
return PpdProvider::Create(g_browser_process->GetApplicationLocale(),
g_browser_process->system_request_context(),
PpdCache::Create(ppd_cache_path));
PpdCache::Create(ppd_cache_path),
base::Version(version_info::GetVersionNumber()));
}
} // namespace chromeos
......@@ -567,8 +567,8 @@ void CupsPrintersHandler::HandleAddCupsPrinter(const base::ListValue* args) {
// model.
bool found = false;
for (const auto& resolved_printer : resolved_printers_[ppd_manufacturer]) {
if (resolved_printer.first == ppd_model) {
*printer->mutable_ppd_reference() = resolved_printer.second;
if (resolved_printer.name == ppd_model) {
*(printer->mutable_ppd_reference()) = resolved_printer.ppd_ref;
found = true;
break;
}
......@@ -745,7 +745,7 @@ void CupsPrintersHandler::ResolvePrintersDone(
if (result_code == PpdProvider::SUCCESS) {
resolved_printers_[manufacturer] = printers;
for (const auto& printer : printers) {
printers_value->AppendString(printer.first);
printers_value->AppendString(printer.name);
}
}
base::DictionaryValue response;
......
This diff is collapsed.
......@@ -13,6 +13,7 @@
#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/version.h"
#include "chromeos/chromeos_export.h"
#include "chromeos/printing/printer_configuration.h"
......@@ -78,6 +79,26 @@ class CHROMEOS_EXPORT PpdProvider : public base::RefCounted<PpdProvider> {
int usb_product_id = 0;
};
// Defines the limitations on when we show a particular PPD
struct Restrictions {
// Minimum milestone for ChromeOS build
base::Version min_milestone = base::Version("0.0");
// Maximum milestone for ChomeOS build
base::Version max_milestone = base::Version("0.0");
};
struct ResolvedPpdReference {
// The name of the model of printer or printer line
std::string name;
// The limitations on this model
Restrictions restrictions;
// Correct PpdReferece to be used with this printer
Printer::PpdReference ppd_ref;
};
// Result of a ResolvePpd() call.
// If the result code is SUCCESS, then:
// string holds the contents of a PPD (that may or may not be gzipped).
......@@ -96,8 +117,7 @@ class CHROMEOS_EXPORT PpdProvider : public base::RefCounted<PpdProvider> {
// A list of printer names paired with the PpdReference that should be used
// for that printer.
using ResolvedPrintersList =
std::vector<std::pair<std::string, Printer::PpdReference>>;
using ResolvedPrintersList = std::vector<ResolvedPpdReference>;
// Result of a ResolvePrinters() call. If the result code is SUCCESS, then
// the vector contains a sorted list <model_name, PpdReference> tuples of all
......@@ -128,6 +148,7 @@ class CHROMEOS_EXPORT PpdProvider : public base::RefCounted<PpdProvider> {
const std::string& browser_locale,
scoped_refptr<net::URLRequestContextGetter> url_context_getter,
scoped_refptr<PpdCache> cache,
const base::Version& current_version,
const Options& options = Options());
// Get all manufacturers for which we have drivers. Keys of the map will be
......
......@@ -20,6 +20,7 @@
#include "base/test/test_message_loop.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/version.h"
#include "chromeos/chromeos_paths.h"
#include "chromeos/printing/ppd_cache.h"
#include "chromeos/printing/ppd_provider.h"
......@@ -80,7 +81,7 @@ class PpdProviderTest : public ::testing::Test {
return PpdProvider::Create(locale, request_context_getter_.get(),
PpdCache::Create(ppd_cache_temp_dir_.GetPath()),
provider_options);
base::Version("40.8.6753.09"), provider_options);
}
// Create an interceptor that serves a small fileset of ppd server files.
......@@ -100,7 +101,9 @@ class PpdProviderTest : public ::testing::Test {
R"([
["printer_a_ref", "printer_a.ppd"],
["printer_b_ref", "printer_b.ppd"],
["printer_c_ref", "printer_c.ppd"]
["printer_c_ref", "printer_c.ppd"],
["printer_d_ref", "printer_d.ppd"],
["printer_e_ref", "printer_e.ppd"]
])"},
{"metadata/usb-031f.json",
R"([
......@@ -126,10 +129,21 @@ class PpdProviderTest : public ::testing::Test {
R"([
["printer_a", "printer_a_ref"],
["printer_b", "printer_b_ref"]
["printer_d", "printer_d_ref"]
])"},
{"metadata_v2/manufacturer_a.json",
R"([
["printer_a", "printer_a_ref",
{"min_milestone":25.0000}],
["printer_b", "printer_b_ref",
{"min_milestone":30.0000, "max_milestone":45.0000}],
["printer_d", "printer_d_ref",
{"min_milestone":60.0000, "max_milestone":75.0000}]
])"},
{"metadata/manufacturer_b.json",
R"([
["printer_c", "printer_c_ref"]
["printer_c", "printer_c_ref"],
["printer_e", "printer_e_ref"]
])"},
{"metadata_v2/reverse_index-en-01.json",
R"([
......@@ -138,9 +152,18 @@ class PpdProviderTest : public ::testing::Test {
{"metadata_v2/reverse_index-en-19.json",
R"([
])"},
{"metadata_v2/manufacturer_b.json",
R"([
["printer_c", "printer_c_ref",
{"max_milestone":55.0000}],
["printer_e", "printer_e_ref",
{"min_milestone":17.0000, "max_milestone":33.0000}]
])"},
{"ppds/printer_a.ppd", kCupsFilterPpdContents},
{"ppds/printer_b.ppd", kCupsFilter2PpdContents},
{"ppds/printer_c.ppd", "c"},
{"ppds/printer_d.ppd", "d"},
{"ppds/printer_e.ppd", "e"},
{"user_supplied_ppd_directory/user_supplied.ppd", "u"}};
int next_file_num = 0;
for (const auto& entry : server_contents) {
......@@ -434,6 +457,7 @@ TEST_F(PpdProviderTest, ResolvePrinters) {
provider->ResolvePrinters("manufacturer_b_en",
base::Bind(&PpdProviderTest::CaptureResolvePrinters,
base::Unretained(this)));
scoped_task_environment_.RunUntilIdle();
ASSERT_EQ(2UL, captured_resolve_printers_.size());
EXPECT_EQ(PpdProvider::SUCCESS, captured_resolve_printers_[0].first);
......@@ -444,18 +468,22 @@ TEST_F(PpdProviderTest, ResolvePrinters) {
// reference effective make and models of printer_a_ref and printer_b_ref.
const auto& capture0 = captured_resolve_printers_[0].second;
ASSERT_EQ(2UL, capture0.size());
EXPECT_EQ("printer_a", capture0[0].first);
EXPECT_EQ("printer_a_ref", capture0[0].second.effective_make_and_model);
EXPECT_EQ("printer_a", capture0[0].name);
EXPECT_EQ("printer_a_ref", capture0[0].ppd_ref.effective_make_and_model);
EXPECT_EQ(base::Version("25"), capture0[0].restrictions.min_milestone);
EXPECT_EQ("printer_b", capture0[1].first);
EXPECT_EQ("printer_b_ref", capture0[1].second.effective_make_and_model);
EXPECT_EQ("printer_b", capture0[1].name);
EXPECT_EQ("printer_b_ref", capture0[1].ppd_ref.effective_make_and_model);
EXPECT_EQ(base::Version("30"), capture0[1].restrictions.min_milestone);
EXPECT_EQ(base::Version("45"), capture0[1].restrictions.max_milestone);
// Second capture should get back printer_c with effective make and model of
// printer_c_ref
const auto& capture1 = captured_resolve_printers_[1].second;
ASSERT_EQ(1UL, capture1.size());
EXPECT_EQ("printer_c", capture1[0].first);
EXPECT_EQ("printer_c_ref", capture1[0].second.effective_make_and_model);
EXPECT_EQ("printer_c", capture1[0].name);
EXPECT_EQ("printer_c_ref", capture1[0].ppd_ref.effective_make_and_model);
EXPECT_EQ(base::Version("55"), capture1[0].restrictions.max_milestone);
}
// Test that if we give a bad reference to ResolvePrinters(), we get an
......
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