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

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

Issue 2457933004: Register and select printer on click. (Closed)
Patch Set: lint Created 4 years, 1 month 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
Index: chrome/browser/chromeos/printing/printer_pref_manager.cc
diff --git a/chrome/browser/chromeos/printing/printer_pref_manager.cc b/chrome/browser/chromeos/printing/printer_pref_manager.cc
index 1ea5226880c65f077845760f006c6ad8d16627ad..611c00df0b2598237b9e07b78325f033e2c7835a 100644
--- a/chrome/browser/chromeos/printing/printer_pref_manager.cc
+++ b/chrome/browser/chromeos/printing/printer_pref_manager.cc
@@ -31,7 +31,7 @@ const base::ListValue* GetPrinterList(Profile* profile) {
// Returns the printer with the matching |id| from the list |values|. The
// returned value is mutable and |values| could be modified.
-base::DictionaryValue* FindPrinterPref(base::ListValue* values,
+base::DictionaryValue* FindPrinterPref(const base::ListValue* values,
const std::string& id) {
for (const auto& value : *values) {
base::DictionaryValue* printer_dictionary;
@@ -96,6 +96,17 @@ std::vector<std::unique_ptr<Printer>> PrinterPrefManager::GetPrinters() const {
return printers;
}
+std::unique_ptr<Printer> PrinterPrefManager::GetPrinter(
+ const std::string& printer_id) const {
+ const base::ListValue* values = GetPrinterList(profile_);
+ if (!values)
Lei Zhang 2016/11/02 23:09:22 So either line 83 needs this check, or this isn't
skau 2016/11/03 22:38:08 It's not needed.
+ return nullptr;
+
+ const base::DictionaryValue* printer = FindPrinterPref(values, printer_id);
+
+ return printer ? printing::PrefToPrinter(*printer) : nullptr;
+}
+
void PrinterPrefManager::RegisterPrinter(std::unique_ptr<Printer> printer) {
if (printer->id().empty())
printer->set_id(base::GenerateGUID());

Powered by Google App Engine
This is Rietveld 408576698