| 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 "chromeos/printing/printer_translator.h" | 5 #include "chromeos/printing/printer_translator.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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 105 |
| 106 const char kPrinterId[] = "id"; | 106 const char kPrinterId[] = "id"; |
| 107 | 107 |
| 108 std::unique_ptr<Printer> PrefToPrinter(const DictionaryValue& value) { | 108 std::unique_ptr<Printer> PrefToPrinter(const DictionaryValue& value) { |
| 109 if (!value.HasKey(kPrinterId)) { | 109 if (!value.HasKey(kPrinterId)) { |
| 110 LOG(WARNING) << "Record id required"; | 110 LOG(WARNING) << "Record id required"; |
| 111 return nullptr; | 111 return nullptr; |
| 112 } | 112 } |
| 113 | 113 |
| 114 std::unique_ptr<Printer> printer = DictionaryToPrinter(value); | 114 std::unique_ptr<Printer> printer = DictionaryToPrinter(value); |
| 115 printer->set_source(Printer::SRC_USER_PREFS); |
| 115 | 116 |
| 116 const DictionaryValue* ppd; | 117 const DictionaryValue* ppd; |
| 117 if (value.GetDictionary(kPpdReference, &ppd)) { | 118 if (value.GetDictionary(kPpdReference, &ppd)) { |
| 118 *printer->mutable_ppd_reference() = DictionaryToPpdReference(ppd); | 119 *printer->mutable_ppd_reference() = DictionaryToPpdReference(ppd); |
| 119 } | 120 } |
| 120 | 121 |
| 121 return printer; | 122 return printer; |
| 122 } | 123 } |
| 123 | 124 |
| 124 std::unique_ptr<base::DictionaryValue> PrinterToPref(const Printer& printer) { | 125 std::unique_ptr<base::DictionaryValue> PrinterToPref(const Printer& printer) { |
| 125 std::unique_ptr<DictionaryValue> dictionary = | 126 std::unique_ptr<DictionaryValue> dictionary = |
| 126 base::MakeUnique<base::DictionaryValue>(); | 127 base::MakeUnique<base::DictionaryValue>(); |
| 127 dictionary->SetString(kPrinterId, printer.id()); | 128 dictionary->SetString(kPrinterId, printer.id()); |
| 128 dictionary->SetString(kDisplayName, printer.display_name()); | 129 dictionary->SetString(kDisplayName, printer.display_name()); |
| 129 dictionary->SetString(kDescription, printer.description()); | 130 dictionary->SetString(kDescription, printer.description()); |
| 130 dictionary->SetString(kManufacturer, printer.manufacturer()); | 131 dictionary->SetString(kManufacturer, printer.manufacturer()); |
| 131 dictionary->SetString(kModel, printer.model()); | 132 dictionary->SetString(kModel, printer.model()); |
| 132 dictionary->SetString(kUri, printer.uri()); | 133 dictionary->SetString(kUri, printer.uri()); |
| 133 dictionary->SetString(kUUID, printer.uuid()); | 134 dictionary->SetString(kUUID, printer.uuid()); |
| 134 | 135 |
| 135 dictionary->Set(kPpdReference, | 136 dictionary->Set(kPpdReference, |
| 136 PpdReferenceToDictionary(printer.ppd_reference())); | 137 PpdReferenceToDictionary(printer.ppd_reference())); |
| 137 | 138 |
| 138 return dictionary; | 139 return dictionary; |
| 139 } | 140 } |
| 140 | 141 |
| 141 std::unique_ptr<Printer> RecommendedPrinterToPrinter( | 142 std::unique_ptr<Printer> RecommendedPrinterToPrinter( |
| 142 const base::DictionaryValue& pref) { | 143 const base::DictionaryValue& pref) { |
| 143 std::unique_ptr<Printer> printer = DictionaryToPrinter(pref); | 144 std::unique_ptr<Printer> printer = DictionaryToPrinter(pref); |
| 145 printer->set_source(Printer::SRC_POLICY); |
| 144 | 146 |
| 145 const DictionaryValue* ppd; | 147 const DictionaryValue* ppd; |
| 146 if (pref.GetDictionary(kPpdResource, &ppd)) { | 148 if (pref.GetDictionary(kPpdResource, &ppd)) { |
| 147 *printer->mutable_ppd_reference() = DictionaryToPpdReference(ppd); | 149 *printer->mutable_ppd_reference() = DictionaryToPpdReference(ppd); |
| 148 } | 150 } |
| 149 | 151 |
| 150 return printer; | 152 return printer; |
| 151 } | 153 } |
| 152 | 154 |
| 153 } // namespace printing | 155 } // namespace printing |
| 154 } // namespace chromeos | 156 } // namespace chromeos |
| OLD | NEW |