Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(884)

Unified Diff: chrome/browser/chromeos/printing/usb_printer_util.cc

Issue 2974103002: Remove requirement that USB printers have a make/model metadata (Closed)
Patch Set: Moar better naming logic to prevent spurios extra spaces in some cases" Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/printing/usb_printer_util.cc
diff --git a/chrome/browser/chromeos/printing/usb_printer_util.cc b/chrome/browser/chromeos/printing/usb_printer_util.cc
index 28ae5c15e147464d74a227060c432c1ebfe28c42..5ba38bb56f6d3dfb5df8cf6f19fb0abfa75f639c 100644
--- a/chrome/browser/chromeos/printing/usb_printer_util.cc
+++ b/chrome/browser/chromeos/printing/usb_printer_util.cc
@@ -13,6 +13,7 @@
#include "base/memory/ptr_util.h"
#include "base/strings/string16.h"
#include "base/strings/string_piece.h"
+#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "chromeos/printing/printer_configuration.h"
@@ -146,8 +147,7 @@ std::string UsbPrinterDeviceDetailsAsString(const device::UsbDevice& device) {
// from arbitrary devices.
std::unique_ptr<Printer> UsbDeviceToPrinter(const device::UsbDevice& device) {
// Preflight all required fields and log errors if we find something wrong.
- if (device.vendor_id() == 0 || device.product_id() == 0 ||
- device.manufacturer_string().empty() || device.product_string().empty()) {
+ if (device.vendor_id() == 0 || device.product_id() == 0) {
LOG(ERROR) << "Failed to convert USB device to printer. Fields were:\n"
<< UsbPrinterDeviceDetailsAsString(device);
return nullptr;
@@ -156,9 +156,23 @@ 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()));
- printer->set_display_name(base::StringPrintf("%s %s (USB)",
- printer->manufacturer().c_str(),
- printer->model().c_str()));
+
+ // Construct the display name by however much of the manufacturer/model
+ // information that we have available.
+ std::vector<std::string> display_name_parts;
+ if (!printer->manufacturer().empty()) {
+ display_name_parts.push_back(printer->manufacturer());
+ }
+ if (!printer->model().empty()) {
+ display_name_parts.push_back(printer->model());
+ }
+ if (display_name_parts.empty()) {
+ // If we have neither manufacturer nor model, just display the name as
+ // 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());
printer->set_uri(UsbPrinterUri(device));
printer->set_id(UsbPrinterId(device));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698