| 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> |
| 11 | 11 |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chromeos/printing/printer_configuration.h" | 14 #include "chromeos/printing/printer_configuration.h" |
| 15 | 15 |
| 16 using base::DictionaryValue; | 16 using base::DictionaryValue; |
| 17 | 17 |
| 18 namespace chromeos { | 18 namespace chromeos { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // PPD reference fields | 22 // PPD reference fields |
| 23 const char kUserSuppliedPpdUrl[] = "user_supplied_ppd_url"; | 23 const char kUserSuppliedPpdUrl[] = "user_supplied_ppd_url"; |
| 24 const char kEffectiveManufacturer[] = "effective_manufacturer"; | |
| 25 const char kEffectiveModel[] = "effective_model"; | 24 const char kEffectiveModel[] = "effective_model"; |
| 26 | 25 |
| 27 // printer fields | 26 // printer fields |
| 28 const char kDisplayName[] = "display_name"; | 27 const char kDisplayName[] = "display_name"; |
| 29 const char kDescription[] = "description"; | 28 const char kDescription[] = "description"; |
| 30 const char kManufacturer[] = "manufacturer"; | 29 const char kManufacturer[] = "manufacturer"; |
| 31 const char kModel[] = "model"; | 30 const char kModel[] = "model"; |
| 32 const char kUri[] = "uri"; | 31 const char kUri[] = "uri"; |
| 33 const char kPpdReference[] = "ppd_reference"; | 32 const char kPpdReference[] = "ppd_reference"; |
| 34 const char kUUID[] = "uuid"; | 33 const char kUUID[] = "uuid"; |
| 35 | 34 |
| 36 // The name of the PpdResource for policy printers. | 35 // The name of the PpdResource for policy printers. |
| 37 const char kPpdResource[] = "ppd_resource"; | 36 const char kPpdResource[] = "ppd_resource"; |
| 38 | 37 |
| 39 Printer::PpdReference DictionaryToPpdReference( | 38 Printer::PpdReference DictionaryToPpdReference( |
| 40 const base::DictionaryValue* value) { | 39 const base::DictionaryValue* value) { |
| 41 Printer::PpdReference ppd; | 40 Printer::PpdReference ppd; |
| 42 value->GetString(kUserSuppliedPpdUrl, &ppd.user_supplied_ppd_url); | 41 value->GetString(kUserSuppliedPpdUrl, &ppd.user_supplied_ppd_url); |
| 43 value->GetString(kEffectiveManufacturer, &ppd.effective_manufacturer); | |
| 44 value->GetString(kEffectiveModel, &ppd.effective_model); | 42 value->GetString(kEffectiveModel, &ppd.effective_model); |
| 45 return ppd; | 43 return ppd; |
| 46 } | 44 } |
| 47 | 45 |
| 48 // Convert a PpdReference struct to a DictionaryValue. | 46 // Convert a PpdReference struct to a DictionaryValue. |
| 49 std::unique_ptr<base::DictionaryValue> PpdReferenceToDictionary( | 47 std::unique_ptr<base::DictionaryValue> PpdReferenceToDictionary( |
| 50 const Printer::PpdReference& ppd) { | 48 const Printer::PpdReference& ppd) { |
| 51 auto dictionary = base::MakeUnique<DictionaryValue>(); | 49 auto dictionary = base::MakeUnique<DictionaryValue>(); |
| 52 if (!ppd.user_supplied_ppd_url.empty()) { | 50 if (!ppd.user_supplied_ppd_url.empty()) { |
| 53 dictionary->SetString(kUserSuppliedPpdUrl, ppd.user_supplied_ppd_url); | 51 dictionary->SetString(kUserSuppliedPpdUrl, ppd.user_supplied_ppd_url); |
| 54 } | 52 } |
| 55 if (!ppd.effective_manufacturer.empty()) { | |
| 56 dictionary->SetString(kEffectiveManufacturer, ppd.effective_manufacturer); | |
| 57 } | |
| 58 if (!ppd.effective_model.empty()) { | 53 if (!ppd.effective_model.empty()) { |
| 59 dictionary->SetString(kEffectiveModel, ppd.effective_model); | 54 dictionary->SetString(kEffectiveModel, ppd.effective_model); |
| 60 } | 55 } |
| 61 return dictionary; | 56 return dictionary; |
| 62 } | 57 } |
| 63 | 58 |
| 64 // Converts |value| into a Printer object for the fields that are shared | 59 // Converts |value| into a Printer object for the fields that are shared |
| 65 // between pref printers and policy printers. | 60 // between pref printers and policy printers. |
| 66 std::unique_ptr<Printer> DictionaryToPrinter(const DictionaryValue& value) { | 61 std::unique_ptr<Printer> DictionaryToPrinter(const DictionaryValue& value) { |
| 67 std::string id; | 62 std::string id; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 const DictionaryValue* ppd; | 140 const DictionaryValue* ppd; |
| 146 if (pref.GetDictionary(kPpdResource, &ppd)) { | 141 if (pref.GetDictionary(kPpdResource, &ppd)) { |
| 147 *printer->mutable_ppd_reference() = DictionaryToPpdReference(ppd); | 142 *printer->mutable_ppd_reference() = DictionaryToPpdReference(ppd); |
| 148 } | 143 } |
| 149 | 144 |
| 150 return printer; | 145 return printer; |
| 151 } | 146 } |
| 152 | 147 |
| 153 } // namespace printing | 148 } // namespace printing |
| 154 } // namespace chromeos | 149 } // namespace chromeos |
| OLD | NEW |