Commit 2cbe8356 authored by Luum Habtemariam's avatar Luum Habtemariam Committed by Commit Bot

Supporting Epson printer PPD matching

This change implements instructions sent by Epson to properly setup
their printers; mostly just boils down to falling back on a provided
generic Epson PPD.

Bug: chromium:895037
Test: All current and added test cases pass. Verified non-Epson matching unchanged
Change-Id: Ie336586bed844e1b9f6671d36312a89ed16849bc
Reviewed-on: https://chromium-review.googlesource.com/c/1407918Reviewed-by: default avatarHector Carmona <hcarmona@chromium.org>
Reviewed-by: default avatarSean Kau <skau@chromium.org>
Auto-Submit: Luum Habtemariam <luum@chromium.org>
Commit-Queue: Luum Habtemariam <luum@chromium.org>
Cr-Commit-Position: refs/heads/master@{#626195}
parent 3966393d
...@@ -34,7 +34,7 @@ class CHROMEOS_EXPORT PrinterDetector { ...@@ -34,7 +34,7 @@ class CHROMEOS_EXPORT PrinterDetector {
Printer printer; Printer printer;
// Additional metadata used to find a driver. // Additional metadata used to find a driver.
PpdProvider::PrinterSearchData ppd_search_data; PrinterSearchData ppd_search_data;
}; };
class Observer { class Observer {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define CHROME_BROWSER_CHROMEOS_PRINTING_PRINTER_INFO_H_ #define CHROME_BROWSER_CHROMEOS_PRINTING_PRINTER_INFO_H_
#include <string> #include <string>
#include <vector>
#include "base/callback_forward.h" #include "base/callback_forward.h"
...@@ -21,6 +22,7 @@ using PrinterInfoCallback = ...@@ -21,6 +22,7 @@ using PrinterInfoCallback =
const std::string& make, const std::string& make,
const std::string& model, const std::string& model,
const std::string& make_and_model, const std::string& make_and_model,
const std::vector<std::string>& document_formats,
bool autoconf)>; bool autoconf)>;
// Dispatch an IPP request to |host| on |port| for |path| to obtain // Dispatch an IPP request to |host| on |port| for |path| to obtain
......
...@@ -98,7 +98,7 @@ void OnPrinterQueried(const chromeos::PrinterInfoCallback& callback, ...@@ -98,7 +98,7 @@ void OnPrinterQueried(const chromeos::PrinterInfoCallback& callback,
std::unique_ptr<::printing::PrinterInfo> info) { std::unique_ptr<::printing::PrinterInfo> info) {
if (!info) { if (!info) {
VLOG(1) << "Could not reach printer"; VLOG(1) << "Could not reach printer";
callback.Run(false, std::string(), std::string(), std::string(), false); callback.Run(false, std::string(), std::string(), std::string(), {}, false);
return; return;
} }
...@@ -116,7 +116,7 @@ void OnPrinterQueried(const chromeos::PrinterInfoCallback& callback, ...@@ -116,7 +116,7 @@ void OnPrinterQueried(const chromeos::PrinterInfoCallback& callback,
} }
callback.Run(true, make.as_string(), model.as_string(), info->make_and_model, callback.Run(true, make.as_string(), model.as_string(), info->make_and_model,
IsAutoconf(*info)); info->document_formats, IsAutoconf(*info));
} }
} // namespace } // namespace
......
...@@ -18,7 +18,8 @@ void QueryIppPrinter(const std::string& host, ...@@ -18,7 +18,8 @@ void QueryIppPrinter(const std::string& host,
DCHECK(!host.empty()); DCHECK(!host.empty());
base::PostTask(FROM_HERE, base::PostTask(FROM_HERE,
base::Bind(callback, false, "Foo", "Bar", "Foo Bar", false)); base::BindOnce(callback, false, "Foo", "Bar", "Foo Bar",
std::vector<std::string>{}, false));
} }
} // namespace chromeos } // namespace chromeos
...@@ -39,9 +39,11 @@ namespace { ...@@ -39,9 +39,11 @@ namespace {
// Given a usb device, guesses the make and model for a driver lookup. // Given a usb device, guesses the make and model for a driver lookup.
// //
// TODO(justincarlson): Possibly go deeper and query the IEEE1284 fields // TODO(https://crbug.com/895037): Possibly go deeper and query the IEEE1284
// for make and model if we determine those are more likely to contain // fields for make and model if we determine those are more likely to contain
// what we want. Strings currently come from udev. // what we want. Strings currently come from udev.
// TODO(https://crbug.com/895037): When above is added, parse out document
// formats and add to DetectedPrinter
std::string GuessEffectiveMakeAndModel(const device::UsbDevice& device) { std::string GuessEffectiveMakeAndModel(const device::UsbDevice& device) {
return base::UTF16ToUTF8(device.manufacturer_string()) + " " + return base::UTF16ToUTF8(device.manufacturer_string()) + " " +
base::UTF16ToUTF8(device.product_string()); base::UTF16ToUTF8(device.product_string());
...@@ -118,6 +120,9 @@ class UsbPrinterDetectorImpl : public UsbPrinterDetector, ...@@ -118,6 +120,9 @@ class UsbPrinterDetectorImpl : public UsbPrinterDetector,
entry.ppd_search_data.usb_product_id = device->product_id(); entry.ppd_search_data.usb_product_id = device->product_id();
entry.ppd_search_data.make_and_model.push_back( entry.ppd_search_data.make_and_model.push_back(
GuessEffectiveMakeAndModel(*device)); GuessEffectiveMakeAndModel(*device));
entry.ppd_search_data.discovery_type =
PrinterSearchData::PrinterDiscoveryType::kUsb;
// TODO(https://crbug.com/895037): Add in command set from IEEE1284
base::AutoLock auto_lock(printers_lock_); base::AutoLock auto_lock(printers_lock_);
printers_[device->guid()] = entry; printers_[device->guid()] = entry;
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include "base/md5.h" #include "base/md5.h"
#include "base/observer_list_threadsafe.h" #include "base/observer_list_threadsafe.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "chrome/browser/local_discovery/service_discovery_device_lister.h" #include "chrome/browser/local_discovery/service_discovery_device_lister.h"
...@@ -178,6 +180,8 @@ bool ConvertToPrinter(const ServiceDescription& service_description, ...@@ -178,6 +180,8 @@ bool ConvertToPrinter(const ServiceDescription& service_description,
base::StringPiece(service_type).ends_with(",_print"); base::StringPiece(service_type).ends_with(",_print");
// gather ppd identification candidates. // gather ppd identification candidates.
detected_printer->ppd_search_data.discovery_type =
PrinterSearchData::PrinterDiscoveryType::kZeroconf;
if (!metadata.ty.empty()) { if (!metadata.ty.empty()) {
detected_printer->ppd_search_data.make_and_model.push_back(metadata.ty); detected_printer->ppd_search_data.make_and_model.push_back(metadata.ty);
} }
...@@ -190,6 +194,22 @@ bool ConvertToPrinter(const ServiceDescription& service_description, ...@@ -190,6 +194,22 @@ bool ConvertToPrinter(const ServiceDescription& service_description,
base::StringPrintf("%s %s", metadata.usb_MFG.c_str(), base::StringPrintf("%s %s", metadata.usb_MFG.c_str(),
metadata.usb_MDL.c_str())); metadata.usb_MDL.c_str()));
} }
if (!metadata.pdl.empty()) {
// Per Bonjour Printer Spec v1.2 section 9.2.8, it is invalid for the pdl to
// end with a comma.
auto media_types = base::SplitString(
metadata.pdl, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
if (!media_types.empty() && !media_types.back().empty()) {
// Prune any empty splits.
base::EraseIf(media_types, [](base::StringPiece s) { return s.empty(); });
std::transform(
media_types.begin(), media_types.end(),
std::back_inserter(
detected_printer->ppd_search_data.supported_document_formats),
[](base::StringPiece s) { return base::ToLowerASCII(s); });
}
}
return true; return true;
} }
......
...@@ -103,7 +103,7 @@ void QueryAutoconf(const std::string& printer_uri, ...@@ -103,7 +103,7 @@ void QueryAutoconf(const std::string& printer_uri,
// Behavior for querying a non-IPP uri is undefined and disallowed. // Behavior for querying a non-IPP uri is undefined and disallowed.
if (!IsIppUri(printer_uri) || !optional.has_value()) { if (!IsIppUri(printer_uri) || !optional.has_value()) {
PRINTER_LOG(ERROR) << "Printer uri is invalid: " << printer_uri; PRINTER_LOG(ERROR) << "Printer uri is invalid: " << printer_uri;
callback.Run(false, "", "", "", false); callback.Run(false, "", "", "", {}, false);
return; return;
} }
...@@ -423,7 +423,7 @@ void CupsPrintersHandler::HandleGetPrinterInfo(const base::ListValue* args) { ...@@ -423,7 +423,7 @@ void CupsPrintersHandler::HandleGetPrinterInfo(const base::ListValue* args) {
if (printer_address.empty()) { if (printer_address.empty()) {
// Run the failure callback. // Run the failure callback.
OnAutoconfQueried(callback_id, false, "", "", "", false); OnAutoconfQueried(callback_id, false, "", "", "", {}, false);
return; return;
} }
...@@ -452,6 +452,7 @@ void CupsPrintersHandler::OnAutoconfQueriedDiscovered( ...@@ -452,6 +452,7 @@ void CupsPrintersHandler::OnAutoconfQueriedDiscovered(
const std::string& make, const std::string& make,
const std::string& model, const std::string& model,
const std::string& make_and_model, const std::string& make_and_model,
const std::vector<std::string>& document_formats,
bool ipp_everywhere) { bool ipp_everywhere) {
RecordIppQuerySuccess(success); RecordIppQuerySuccess(success);
...@@ -488,12 +489,14 @@ void CupsPrintersHandler::OnAutoconfQueriedDiscovered( ...@@ -488,12 +489,14 @@ void CupsPrintersHandler::OnAutoconfQueriedDiscovered(
FireManuallyAddDiscoveredPrinter(*printer); FireManuallyAddDiscoveredPrinter(*printer);
} }
void CupsPrintersHandler::OnAutoconfQueried(const std::string& callback_id, void CupsPrintersHandler::OnAutoconfQueried(
bool success, const std::string& callback_id,
const std::string& make, bool success,
const std::string& model, const std::string& make,
const std::string& make_and_model, const std::string& model,
bool ipp_everywhere) { const std::string& make_and_model,
const std::vector<std::string>& document_formats,
bool ipp_everywhere) {
RecordIppQuerySuccess(success); RecordIppQuerySuccess(success);
if (!success) { if (!success) {
...@@ -521,8 +524,11 @@ void CupsPrintersHandler::OnAutoconfQueried(const std::string& callback_id, ...@@ -521,8 +524,11 @@ void CupsPrintersHandler::OnAutoconfQueried(const std::string& callback_id,
return; return;
} }
PpdProvider::PrinterSearchData ppd_search_data; PrinterSearchData ppd_search_data;
ppd_search_data.discovery_type =
PrinterSearchData::PrinterDiscoveryType::kManual;
ppd_search_data.make_and_model.push_back(make_and_model); ppd_search_data.make_and_model.push_back(make_and_model);
ppd_search_data.supported_document_formats = document_formats;
// Try to resolve the PPD matching. // Try to resolve the PPD matching.
ppd_provider_->ResolvePpdReference( ppd_provider_->ResolvePpdReference(
......
...@@ -68,15 +68,18 @@ class CupsPrintersHandler : public ::settings::SettingsPageUIHandler, ...@@ -68,15 +68,18 @@ class CupsPrintersHandler : public ::settings::SettingsPageUIHandler,
const std::string& make, const std::string& make,
const std::string& model, const std::string& model,
const std::string& make_and_model, const std::string& make_and_model,
const std::vector<std::string>& document_formats,
bool ipp_everywhere); bool ipp_everywhere);
// Handles the callback for HandleGetPrinterInfo for a discovered printer. // Handles the callback for HandleGetPrinterInfo for a discovered printer.
void OnAutoconfQueriedDiscovered(std::unique_ptr<Printer> printer, void OnAutoconfQueriedDiscovered(
bool success, std::unique_ptr<Printer> printer,
const std::string& make, bool success,
const std::string& model, const std::string& make,
const std::string& make_and_model, const std::string& model,
bool ipp_everywhere); const std::string& make_and_model,
const std::vector<std::string>& document_formats,
bool ipp_everywhere);
// Callback for PPD matching attempts; // Callback for PPD matching attempts;
void OnPpdResolved(const std::string& callback_id, void OnPpdResolved(const std::string& callback_id,
......
...@@ -53,6 +53,8 @@ component("chromeos") { ...@@ -53,6 +53,8 @@ component("chromeos") {
"policy/weekly_time/weekly_time.h", "policy/weekly_time/weekly_time.h",
"policy/weekly_time/weekly_time_interval.cc", "policy/weekly_time/weekly_time_interval.cc",
"policy/weekly_time/weekly_time_interval.h", "policy/weekly_time/weekly_time_interval.h",
"printing/epson_driver_matching.cc",
"printing/epson_driver_matching.h",
"printing/ppd_cache.cc", "printing/ppd_cache.cc",
"printing/ppd_cache.h", "printing/ppd_cache.h",
"printing/ppd_line_reader.cc", "printing/ppd_line_reader.cc",
...@@ -217,6 +219,7 @@ test("chromeos_unittests") { ...@@ -217,6 +219,7 @@ test("chromeos_unittests") {
"policy/weekly_time/time_utils_unittest.cc", "policy/weekly_time/time_utils_unittest.cc",
"policy/weekly_time/weekly_time_interval_unittest.cc", "policy/weekly_time/weekly_time_interval_unittest.cc",
"policy/weekly_time/weekly_time_unittest.cc", "policy/weekly_time/weekly_time_unittest.cc",
"printing/epson_driver_matching_unittest.cc",
"printing/ppd_cache_unittest.cc", "printing/ppd_cache_unittest.cc",
"printing/ppd_line_reader_unittest.cc", "printing/ppd_line_reader_unittest.cc",
"printing/ppd_provider_unittest.cc", "printing/ppd_provider_unittest.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/printing/epson_driver_matching.h"
#include <algorithm>
#include "chromeos/printing/ppd_provider.h"
namespace chromeos {
bool CanUseEpsonGenericPPD(const PrinterSearchData& sd) {
// Needed to check if its an Epson printer.
if (sd.make_and_model.empty()) {
return false;
}
// Fail if this isn't an Epson printer.
// Note: Assumes make and model strings are already lowercase.
auto it = std::find_if(sd.make_and_model.begin(), sd.make_and_model.end(),
[](base::StringPiece emm) {
return emm.find("epson") != base::StringPiece::npos;
});
if (it == sd.make_and_model.end()) {
return false;
}
switch (sd.discovery_type) {
case PrinterSearchData::PrinterDiscoveryType::kManual:
// For manually discovered printers, supported_document_formats is
// retrieved via an ippGetAttributes query to the printer.
return base::ContainsValue(sd.supported_document_formats,
"application/octet-stream");
case PrinterSearchData::PrinterDiscoveryType::kUsb:
return base::ContainsValue(sd.usb_command_set, "ESC/P-R");
case PrinterSearchData::PrinterDiscoveryType::kZeroconf:
// For printers found through mDNS/DNS-SD discovery,
// supported_document_formats is retrieved via the Printer Description TXT
// Record(from the key 'pdl').
return base::ContainsValue(sd.supported_document_formats,
"application/vnd.epson.escpr");
default:
return false;
}
}
} // namespace chromeos
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_PRINTING_EPSON_DRIVER_MATCHING_H_
#define CHROMEOS_PRINTING_EPSON_DRIVER_MATCHING_H_
#include "chromeos/chromeos_export.h"
namespace chromeos {
struct PrinterSearchData;
// Implements PPD matching rules obtained from Epson. Returns true when this
// printer can be saftely setup using the generic Epson PPD.
bool CHROMEOS_EXPORT CanUseEpsonGenericPPD(const PrinterSearchData& sd);
} // namespace chromeos
#endif // CHROMEOS_PRINTING_EPSON_DRIVER_MATCHING_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/printing/epson_driver_matching.h"
#include <string>
#include "chromeos/printing/ppd_provider.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
namespace {
const char kOctetStream[] = "application/octet-stream";
const char kEscPr[] = "ESC/P-R";
const char kEpsonEscpr[] = "application/vnd.epson.escpr";
using PrinterDiscoveryType = PrinterSearchData::PrinterDiscoveryType;
PrinterSearchData GetTestPrinterSearchData(
PrinterDiscoveryType type = PrinterDiscoveryType::kManual) {
PrinterSearchData sd;
sd.make_and_model.push_back("epson");
switch (type) {
case PrinterDiscoveryType::kManual:
sd.discovery_type = PrinterDiscoveryType::kManual;
sd.supported_document_formats.push_back(kOctetStream);
break;
case PrinterDiscoveryType::kUsb:
sd.discovery_type = PrinterDiscoveryType::kUsb;
sd.usb_command_set.push_back(kEscPr);
break;
case PrinterDiscoveryType::kZeroconf:
sd.discovery_type = PrinterDiscoveryType::kZeroconf;
sd.supported_document_formats.push_back(kEpsonEscpr);
break;
default:
sd.discovery_type = type;
break;
}
return sd;
}
// Ensuring simple good cases generated above pass.
TEST(EpsonDriverMatchingTest, SimpleSanityTest) {
EXPECT_TRUE(CanUseEpsonGenericPPD(
GetTestPrinterSearchData(PrinterDiscoveryType::kManual)));
EXPECT_TRUE(CanUseEpsonGenericPPD(
GetTestPrinterSearchData(PrinterDiscoveryType::kUsb)));
EXPECT_TRUE(CanUseEpsonGenericPPD(
GetTestPrinterSearchData(PrinterDiscoveryType::kZeroconf)));
}
// Always fails printers missing make and model information.
TEST(EpsonDriverMatchingTest, EmptyMakeAndModels) {
EXPECT_FALSE(CanUseEpsonGenericPPD(PrinterSearchData()));
}
// Always fails printers with invalid discovery types.
TEST(EpsonDriverMatchingTest, InvalidPrinterDiscoveryType) {
EXPECT_FALSE(CanUseEpsonGenericPPD(
GetTestPrinterSearchData(PrinterDiscoveryType::kUnknown)));
EXPECT_FALSE(CanUseEpsonGenericPPD(
GetTestPrinterSearchData(PrinterDiscoveryType::kDiscoveryTypeMax)));
}
// Confirms an Epson printer if any make and models have 'epson'.
TEST(EpsonDriverMatchingTest, ChecksAllMakeAndModels) {
PrinterSearchData sd(GetTestPrinterSearchData());
sd.make_and_model.clear();
sd.make_and_model.push_back("kodak fdasf");
EXPECT_FALSE(CanUseEpsonGenericPPD(sd));
sd.make_and_model.push_back("epso nomega x301");
EXPECT_FALSE(CanUseEpsonGenericPPD(sd));
sd.make_and_model.push_back("epson xp5100");
EXPECT_TRUE(CanUseEpsonGenericPPD(sd));
}
// Simple PrinterDiscoveryType::kManual checks.
TEST(EpsonDriverMatchingTest, ManualDiscovery) {
PrinterSearchData sd(GetTestPrinterSearchData(PrinterDiscoveryType::kManual));
sd.supported_document_formats.clear();
sd.supported_document_formats.push_back("application/");
EXPECT_FALSE(CanUseEpsonGenericPPD(sd));
sd.supported_document_formats.push_back(std::string(kOctetStream) + "afds");
EXPECT_FALSE(CanUseEpsonGenericPPD(sd));
sd.usb_command_set.push_back(kOctetStream);
EXPECT_FALSE(CanUseEpsonGenericPPD(sd));
sd.supported_document_formats.push_back(kOctetStream);
EXPECT_TRUE(CanUseEpsonGenericPPD(sd));
}
// Simple PrinterDiscoveryType::kUsb checks.
TEST(EpsonDriverMatchingTest, UsbDiscovery) {
PrinterSearchData sd(GetTestPrinterSearchData(PrinterDiscoveryType::kUsb));
sd.usb_command_set.clear();
sd.usb_command_set.push_back("ESC");
EXPECT_FALSE(CanUseEpsonGenericPPD(sd));
sd.usb_command_set.push_back(std::string(kEscPr) + ":asfd");
EXPECT_FALSE(CanUseEpsonGenericPPD(sd));
sd.supported_document_formats.push_back(kEscPr);
EXPECT_FALSE(CanUseEpsonGenericPPD(sd));
sd.usb_command_set.push_back(kEscPr);
EXPECT_TRUE(CanUseEpsonGenericPPD(sd));
}
TEST(EpsonDriverMatchingTest, ZerconfDiscovery) {
PrinterSearchData sd(
GetTestPrinterSearchData(PrinterDiscoveryType::kZeroconf));
sd.supported_document_formats.clear();
sd.supported_document_formats.push_back("application/");
EXPECT_FALSE(CanUseEpsonGenericPPD(sd));
sd.supported_document_formats.push_back(std::string(kEpsonEscpr) + ":asfd");
EXPECT_FALSE(CanUseEpsonGenericPPD(sd));
sd.usb_command_set.push_back(kEpsonEscpr);
EXPECT_FALSE(CanUseEpsonGenericPPD(sd));
sd.supported_document_formats.push_back(kEpsonEscpr);
EXPECT_TRUE(CanUseEpsonGenericPPD(sd));
}
} // namespace
} // namespace chromeos
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "base/threading/sequenced_task_runner_handle.h" #include "base/threading/sequenced_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/values.h" #include "base/values.h"
#include "chromeos/printing/epson_driver_matching.h"
#include "chromeos/printing/ppd_cache.h" #include "chromeos/printing/ppd_cache.h"
#include "chromeos/printing/ppd_line_reader.h" #include "chromeos/printing/ppd_line_reader.h"
#include "chromeos/printing/printing_constants.h" #include "chromeos/printing/printing_constants.h"
...@@ -48,6 +49,8 @@ ...@@ -48,6 +49,8 @@
namespace chromeos { namespace chromeos {
namespace { namespace {
const char kEpsonGenericPPD[] = "epson generic escpr printer";
// Holds a metadata_v2 reverse-index response // Holds a metadata_v2 reverse-index response
struct ReverseIndexJSON { struct ReverseIndexJSON {
// Canonical name of printer // Canonical name of printer
...@@ -173,7 +176,7 @@ struct PpdReferenceResolutionQueueEntry { ...@@ -173,7 +176,7 @@ struct PpdReferenceResolutionQueueEntry {
~PpdReferenceResolutionQueueEntry() = default; ~PpdReferenceResolutionQueueEntry() = default;
// Metadata used to resolve to a unique PpdReference object. // Metadata used to resolve to a unique PpdReference object.
PpdProvider::PrinterSearchData search_data; PrinterSearchData search_data;
// If true, we have failed usb_index_resolution already. // If true, we have failed usb_index_resolution already.
bool usb_resolution_attempted = false; bool usb_resolution_attempted = false;
...@@ -452,11 +455,24 @@ class PpdProviderImpl : public PpdProvider { ...@@ -452,11 +455,24 @@ class PpdProviderImpl : public PpdProvider {
StartFetch(GetUsbURL(search_data.usb_vendor_id), FT_USB_DEVICES); StartFetch(GetUsbURL(search_data.usb_vendor_id), FT_USB_DEVICES);
return true; return true;
} }
// We don't have anything else left to try. NOT_FOUND it is.
base::SequencedTaskRunnerHandle::Get()->PostTask( // If possible, here we fall back to OEM designated generic PPDs.
FROM_HERE, base::BindOnce(std::move(next.cb), PpdProvider::NOT_FOUND, if (CanUseEpsonGenericPPD(search_data)) {
Printer::PpdReference())); // Found a hit, satisfy this resolution.
ppd_reference_resolution_queue_.pop_front(); Printer::PpdReference ret;
ret.effective_make_and_model = kEpsonGenericPPD;
base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(std::move(next.cb), PpdProvider::SUCCESS, ret));
ppd_reference_resolution_queue_.pop_front();
} else {
// We don't have anything else left to try. NOT_FOUND it is.
base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(std::move(next.cb), PpdProvider::NOT_FOUND,
Printer::PpdReference()));
ppd_reference_resolution_queue_.pop_front();
}
} }
// Didn't start any fetches. // Didn't start any fetches.
return false; return false;
...@@ -1066,13 +1082,13 @@ class PpdProviderImpl : public PpdProvider { ...@@ -1066,13 +1082,13 @@ class PpdProviderImpl : public PpdProvider {
} }
} }
} }
Printer::PpdReference ret;
if (result == PpdProvider::SUCCESS) { if (result == PpdProvider::SUCCESS) {
Printer::PpdReference ret;
ret.effective_make_and_model = contents; ret.effective_make_and_model = contents;
base::SequencedTaskRunnerHandle::Get()->PostTask( base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(std::move(ppd_reference_resolution_queue_.front().cb), base::BindOnce(std::move(ppd_reference_resolution_queue_.front().cb),
result, ret)); result, std::move(ret)));
ppd_reference_resolution_queue_.pop_front(); ppd_reference_resolution_queue_.pop_front();
} else { } else {
ppd_reference_resolution_queue_.front().usb_resolution_attempted = true; ppd_reference_resolution_queue_.front().usb_resolution_attempted = true;
...@@ -1558,10 +1574,9 @@ std::string PpdProvider::PpdReferenceToCacheKey( ...@@ -1558,10 +1574,9 @@ std::string PpdProvider::PpdReferenceToCacheKey(
} }
} }
PpdProvider::PrinterSearchData::PrinterSearchData() = default; PrinterSearchData::PrinterSearchData() = default;
PpdProvider::PrinterSearchData::PrinterSearchData( PrinterSearchData::PrinterSearchData(const PrinterSearchData& other) = default;
const PrinterSearchData& other) = default; PrinterSearchData::~PrinterSearchData() = default;
PpdProvider::PrinterSearchData::~PrinterSearchData() = default;
// static // static
scoped_refptr<PpdProvider> PpdProvider::Create( scoped_refptr<PpdProvider> PpdProvider::Create(
......
...@@ -27,6 +27,42 @@ namespace chromeos { ...@@ -27,6 +27,42 @@ namespace chromeos {
class PpdCache; class PpdCache;
// Everything we might know about a printer when looking for a
// driver for it. All of the default values for fields in this struct
// mean we *don't* have that piece of information.
//
// Fields are listed in search order preference -- we use earlier
// fields first to attempt to find a match.
struct CHROMEOS_EXPORT PrinterSearchData {
PrinterSearchData();
PrinterSearchData(const PrinterSearchData& other);
~PrinterSearchData();
// Make-and-model string guesses.
std::vector<std::string> make_and_model;
// 16-bit usb identifiers.
int usb_vendor_id = 0;
int usb_product_id = 0;
// Method of printer discovery.
enum PrinterDiscoveryType {
kUnknown = 0,
kManual = 1,
kUsb = 2,
kZeroconf = 3,
kDiscoveryTypeMax
};
PrinterDiscoveryType discovery_type;
// Set of MIME types supported by this printer.
std::vector<std::string> supported_document_formats;
// Stripped from IEEE1284 signaling method(from the device ID key 'CMD').
// Details a set of languages this printer understands.
std::vector<std::string> usb_command_set;
};
// PpdProvider is responsible for mapping printer descriptions to // PpdProvider is responsible for mapping printer descriptions to
// CUPS-PostScript Printer Description (PPD) files. It provides PPDs that a // CUPS-PostScript Printer Description (PPD) files. It provides PPDs that a
// user previously identified for use, and falls back to querying quirksserver // user previously identified for use, and falls back to querying quirksserver
...@@ -68,25 +104,6 @@ class CHROMEOS_EXPORT PpdProvider : public base::RefCounted<PpdProvider> { ...@@ -68,25 +104,6 @@ class CHROMEOS_EXPORT PpdProvider : public base::RefCounted<PpdProvider> {
std::string ppd_server_root = "https://www.gstatic.com/chromeos_printing"; std::string ppd_server_root = "https://www.gstatic.com/chromeos_printing";
}; };
// Everything we might know about a printer when looking for a
// driver for it. All of the default values for fields in this struct
// mean we *don't* have that piece of information.
//
// Fields are listed in search order preference -- we use earlier
// fields first to attempt to find a match.
struct PrinterSearchData {
PrinterSearchData();
PrinterSearchData(const PrinterSearchData& other);
~PrinterSearchData();
// Make-and-model string guesses.
std::vector<std::string> make_and_model;
// 16-bit usb identifiers.
int usb_vendor_id = 0;
int usb_product_id = 0;
};
// Defines the limitations on when we show a particular PPD // Defines the limitations on when we show a particular PPD
struct Restrictions { struct Restrictions {
// Minimum milestone for ChromeOS build // Minimum milestone for ChromeOS build
......
...@@ -392,13 +392,13 @@ TEST_F(PpdProviderTest, RepeatedMakeModel) { ...@@ -392,13 +392,13 @@ TEST_F(PpdProviderTest, RepeatedMakeModel) {
StartFakePpdServer(); StartFakePpdServer();
auto provider = CreateProvider("en", false); auto provider = CreateProvider("en", false);
PpdProvider::PrinterSearchData unrecognized_printer; PrinterSearchData unrecognized_printer;
unrecognized_printer.make_and_model = {"Printer Printer"}; unrecognized_printer.make_and_model = {"Printer Printer"};
PpdProvider::PrinterSearchData recognized_printer; PrinterSearchData recognized_printer;
recognized_printer.make_and_model = {"printer_a_ref"}; recognized_printer.make_and_model = {"printer_a_ref"};
PpdProvider::PrinterSearchData mixed; PrinterSearchData mixed;
mixed.make_and_model = {"printer_a_ref", "Printer Printer"}; mixed.make_and_model = {"printer_a_ref", "Printer Printer"};
// Resolve the same thing repeatedly. // Resolve the same thing repeatedly.
...@@ -432,7 +432,7 @@ TEST_F(PpdProviderTest, UsbResolution) { ...@@ -432,7 +432,7 @@ TEST_F(PpdProviderTest, UsbResolution) {
StartFakePpdServer(); StartFakePpdServer();
auto provider = CreateProvider("en", false); auto provider = CreateProvider("en", false);
PpdProvider::PrinterSearchData search_data; PrinterSearchData search_data;
// Should get back "Some canonical reference" // Should get back "Some canonical reference"
search_data.usb_vendor_id = 0x031f; search_data.usb_vendor_id = 0x031f;
...@@ -728,7 +728,7 @@ TEST_F(PpdProviderTest, CaseInsensitiveMakeAndModel) { ...@@ -728,7 +728,7 @@ TEST_F(PpdProviderTest, CaseInsensitiveMakeAndModel) {
provider->ReverseLookup(ref, provider->ReverseLookup(ref,
base::BindOnce(&PpdProviderTest::CaptureReverseLookup, base::BindOnce(&PpdProviderTest::CaptureReverseLookup,
base::Unretained(this))); base::Unretained(this)));
PpdProvider::PrinterSearchData printer_info; PrinterSearchData printer_info;
printer_info.make_and_model = {ref}; printer_info.make_and_model = {ref};
provider->ResolvePpdReference( provider->ResolvePpdReference(
printer_info, base::BindOnce(&PpdProviderTest::CaptureResolvePpdReference, printer_info, base::BindOnce(&PpdProviderTest::CaptureResolvePpdReference,
......
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