Commit 1e866a3b authored by Sean Kau's avatar Sean Kau Committed by Commit Bot

Populate make_and_model field for printers.

Ensure that manufacturer, model, and make_and_model are all populated.
manufacturer and model are populated for backward compatability.

Bug: 730242
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I8a31dbe57bfbc09e7f2e0f04bc7a1aa9b1599368
Reviewed-on: https://chromium-review.googlesource.com/563521Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Commit-Queue: Sean Kau <skau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488414}
parent 6ac836ba
......@@ -13,12 +13,15 @@ namespace chromeos {
// Callback for basic printer information. |success| indicates if the request
// succeeded at all. |make| represents the printer manufacturer. |model| is
// the printer model. |autoconf| indicates if we think we can compute the
// the printer model. |make_and_model| is the raw printer-make-and-model value
// from the printer. |autoconf| indicates if we think we can compute the
// printer capabilites without a PPD.
using PrinterInfoCallback = base::Callback<void(bool success,
const std::string& make,
const std::string& model,
bool autoconf)>;
using PrinterInfoCallback =
base::Callback<void(bool success,
const std::string& make,
const std::string& model,
const std::string& make_and_model,
bool autoconf)>;
// Dispatch an IPP request to |host| on |port| for |path| to obtain
// basic printer information.
......
......@@ -97,7 +97,7 @@ void OnPrinterQueried(const chromeos::PrinterInfoCallback& callback,
std::unique_ptr<::printing::PrinterInfo> info) {
if (!info) {
VLOG(1) << "Could not reach printer";
callback.Run(false, std::string(), std::string(), false);
callback.Run(false, std::string(), std::string(), std::string(), false);
return;
}
......@@ -114,7 +114,8 @@ void OnPrinterQueried(const chromeos::PrinterInfoCallback& callback,
model = make_and_model;
}
callback.Run(true, make.as_string(), model.as_string(), IsAutoconf(*info));
callback.Run(true, make.as_string(), model.as_string(), info->make_and_model,
IsAutoconf(*info));
}
} // namespace
......
......@@ -15,7 +15,8 @@ void QueryIppPrinter(const std::string& host,
const PrinterInfoCallback& callback) {
DCHECK(!host.empty());
base::PostTask(FROM_HERE, base::Bind(callback, false, "Foo", "Bar", false));
base::PostTask(FROM_HERE,
base::Bind(callback, false, "Foo", "Bar", "Foo Bar", false));
}
} // namespace chromeos
......@@ -156,7 +156,11 @@ std::unique_ptr<Printer> UsbDeviceToPrinter(const device::UsbDevice& device) {
auto printer = base::MakeUnique<Printer>();
printer->set_manufacturer(base::UTF16ToUTF8(device.manufacturer_string()));
printer->set_model(base::UTF16ToUTF8(device.product_string()));
// Synthesize make-and-model string for printer identification.
printer->set_make_and_model(
base::JoinString({printer->manufacturer(), printer->model()}, " "));
// TODO(crbug.com/740727): i18n for display names.
// Construct the display name by however much of the manufacturer/model
// information that we have available.
std::vector<std::string> display_name_parts;
......@@ -171,6 +175,7 @@ std::unique_ptr<Printer> UsbDeviceToPrinter(const device::UsbDevice& device) {
// unknown.
display_name_parts.push_back("Unknown Printer");
}
display_name_parts.push_back("(USB)");
printer->set_display_name(base::JoinString(display_name_parts, " "));
printer->set_description(printer->display_name());
......
......@@ -47,6 +47,7 @@ function getEmptyPrinter_() {
printerId: '',
printerManufacturer: '',
printerModel: '',
printerMakeAndModel: '',
printerName: '',
printerPPDPath: '',
printerProtocol: 'ipp',
......@@ -456,6 +457,7 @@ Polymer({
this.newPrinter.printerAutoconf = info.autoconf;
this.newPrinter.printerManufacturer = info.manufacturer;
this.newPrinter.printerModel = info.model;
this.newPrinter.printerMakeAndModel = info.makeAndModel;
// Add the printer if it's configurable. Otherwise, forward to the
// manufacturer dialog.
......
......@@ -17,6 +17,7 @@
* printerId: string,
* printerManufacturer: string,
* printerModel: string,
* printerMakeAndModel: string,
* printerName: string,
* printerPPDPath: string,
* printerProtocol: string,
......@@ -53,6 +54,7 @@ var ModelsInfo;
* @typedef {{
* manufacturer: string,
* model: string,
* makeAndModel: string,
* autoconf: boolean
* }}
*/
......
......@@ -76,6 +76,7 @@ std::unique_ptr<base::DictionaryValue> GetPrinterInfo(const Printer& printer) {
printer_info->SetString("printerDescription", printer.description());
printer_info->SetString("printerManufacturer", printer.manufacturer());
printer_info->SetString("printerModel", printer.model());
printer_info->SetString("printerMakeAndModel", printer.make_and_model());
// Get protocol, ip address and queue from the printer's URI.
const std::string printer_uri = printer.uri();
url::Parsed parsed;
......@@ -255,7 +256,7 @@ void CupsPrintersHandler::HandleGetPrinterInfo(const base::ListValue* args) {
if (printer_address.empty()) {
// Run the failure callback.
OnPrinterInfo(callback_id, false, "", "", false);
OnPrinterInfo(callback_id, false, "", "", "", false);
return;
}
......@@ -299,6 +300,7 @@ void CupsPrintersHandler::OnPrinterInfo(const std::string& callback_id,
bool success,
const std::string& make,
const std::string& model,
const std::string& make_and_model,
bool ipp_everywhere) {
if (!success) {
base::DictionaryValue reject;
......@@ -310,6 +312,7 @@ void CupsPrintersHandler::OnPrinterInfo(const std::string& callback_id,
base::DictionaryValue info;
info.SetString("manufacturer", make);
info.SetString("model", model);
info.SetString("makeAndModel", make_and_model);
info.SetBoolean("autoconf", ipp_everywhere);
ResolveJavascriptCallback(base::Value(callback_id), info);
}
......@@ -325,6 +328,7 @@ void CupsPrintersHandler::HandleAddCupsPrinter(const base::ListValue* args) {
std::string printer_description;
std::string printer_manufacturer;
std::string printer_model;
std::string printer_make_and_model;
std::string printer_address;
std::string printer_protocol;
CHECK(printer_dict->GetString("printerId", &printer_id));
......@@ -332,6 +336,8 @@ void CupsPrintersHandler::HandleAddCupsPrinter(const base::ListValue* args) {
CHECK(printer_dict->GetString("printerDescription", &printer_description));
CHECK(printer_dict->GetString("printerManufacturer", &printer_manufacturer));
CHECK(printer_dict->GetString("printerModel", &printer_model));
CHECK(
printer_dict->GetString("printerMakeAndModel", &printer_make_and_model));
CHECK(printer_dict->GetString("printerAddress", &printer_address));
CHECK(printer_dict->GetString("printerProtocol", &printer_protocol));
......@@ -358,6 +364,7 @@ void CupsPrintersHandler::HandleAddCupsPrinter(const base::ListValue* args) {
printer.set_description(printer_description);
printer.set_manufacturer(printer_manufacturer);
printer.set_model(printer_model);
printer.set_make_and_model(printer_make_and_model);
printer.set_uri(printer_uri);
bool autoconf = false;
......
......@@ -55,16 +55,17 @@ class CupsPrintersHandler : public ::settings::SettingsPageUIHandler,
void HandleGetPrinterInfo(const base::ListValue* args);
// Handles the callback for HandleGetPrinterInfo. |callback_id| is the
// identifier to resolve the correct Promise. |success| indicates if the
// query was successful. |make| is the detected printer manufacturer.
// |model| is the detected model. |ipp_everywhere| indicates if configuration
// using the CUPS IPP Everywhere driver should be attempted. If |success| is
// false, the values of |make|, |model| and |ipp_everywhere| are not
// specified.
// identifier to resolve the correct Promise. |success| indicates if the query
// was successful. |make| is the detected printer manufacturer. |model| is the
// detected model. |make_and_model| is the unparsed printer-make-and-model
// string. |ipp_everywhere| indicates if configuration using the CUPS IPP
// Everywhere driver should be attempted. If |success| is false, the values of
// |make|, |model|, |make_and_model|, and |ipp_everywhere| are not specified.
void OnPrinterInfo(const std::string& callback_id,
bool success,
const std::string& make,
const std::string& model,
const std::string& make_and_model,
bool ipp_everywhere);
void HandleAddCupsPrinter(const base::ListValue* args);
......
......@@ -149,7 +149,8 @@ class CHROMEOS_EXPORT Printer {
std::string model_;
// The manufactuer and model of the printer in one string. e.g. HP OfficeJet
// 415.
// 415. This is either read from or derived from printer information and is
// not necessarily suitable for display.
std::string make_and_model_;
// The full path for the printer. Suitable for configuration in CUPS.
......
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