| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/printing/printer_pref_manager.h" | 5 #include "chrome/browser/chromeos/printing/printer_pref_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 93 } |
| 94 | 94 |
| 95 return printers; | 95 return printers; |
| 96 } | 96 } |
| 97 | 97 |
| 98 void PrinterPrefManager::RegisterPrinter(std::unique_ptr<Printer> printer) { | 98 void PrinterPrefManager::RegisterPrinter(std::unique_ptr<Printer> printer) { |
| 99 if (printer->id().empty()) | 99 if (printer->id().empty()) |
| 100 printer->set_id(base::GenerateGUID()); | 100 printer->set_id(base::GenerateGUID()); |
| 101 | 101 |
| 102 std::unique_ptr<base::DictionaryValue> updated_printer = | 102 std::unique_ptr<base::DictionaryValue> updated_printer = |
| 103 printing::PrinterToPref(*(printer.get())); | 103 printing::PrinterToPref(*printer); |
| 104 UpdatePrinterPref(profile_, printer->id(), std::move(updated_printer)); | 104 UpdatePrinterPref(profile_, printer->id(), std::move(updated_printer)); |
| 105 } | 105 } |
| 106 | 106 |
| 107 bool PrinterPrefManager::RemovePrinter(const std::string& printer_id) { | 107 bool PrinterPrefManager::RemovePrinter(const std::string& printer_id) { |
| 108 DCHECK(!printer_id.empty()); | 108 DCHECK(!printer_id.empty()); |
| 109 ListPrefUpdate update(profile_->GetPrefs(), prefs::kPrintingDevices); | 109 ListPrefUpdate update(profile_->GetPrefs(), prefs::kPrintingDevices); |
| 110 base::ListValue* printer_list = update.Get(); | 110 base::ListValue* printer_list = update.Get(); |
| 111 DCHECK(printer_list) << "Printer preference not registered"; | 111 DCHECK(printer_list) << "Printer preference not registered"; |
| 112 base::DictionaryValue* printer = FindPrinterPref(printer_list, printer_id); | 112 base::DictionaryValue* printer = FindPrinterPref(printer_list, printer_id); |
| 113 | 113 |
| 114 return printer && printer_list->Remove(*printer, nullptr); | 114 return printer && printer_list->Remove(*printer, nullptr); |
| 115 } | 115 } |
| 116 | 116 |
| 117 } // namespace chromeos | 117 } // namespace chromeos |
| OLD | NEW |