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

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

Issue 2457933004: Register and select printer on click. (Closed)
Patch Set: rebase 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
« no previous file with comments | « chrome/browser/chromeos/printing/printer_pref_manager.h ('k') | chrome/browser/ui/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 145af2e64a3fbde436346a7e060437a58d2e876d..e92824e444b7751336463aac68d8604f9a31f4f0 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,12 +96,20 @@ 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_);
+ 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());
std::unique_ptr<base::DictionaryValue> updated_printer =
- printing::PrinterToPref(*(printer.get()));
+ printing::PrinterToPref(*printer);
UpdatePrinterPref(profile_, printer->id(), std::move(updated_printer));
}
« no previous file with comments | « chrome/browser/chromeos/printing/printer_pref_manager.h ('k') | chrome/browser/ui/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698