Chromium Code Reviews| 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"; | 24 const char kEffectiveMakeAndModel[] = "effective_make_and_model"; | 
| 
 
skau
2017/01/27 01:37:01
Leave the constants alone for now.  The Policy pro
 
Carlson
2017/01/27 18:48:43
Not sure how that migration will work, but ok.
 
 | |
| 25 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); | 42 value->GetString(kEffectiveMakeAndModel, &ppd.effective_make_and_model); | 
| 44 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()) { | 53 if (!ppd.effective_make_and_model.empty()) { | 
| 56 dictionary->SetString(kEffectiveManufacturer, ppd.effective_manufacturer); | 54 dictionary->SetString(kEffectiveMakeAndModel, ppd.effective_make_and_model); | 
| 57 } | |
| 58 if (!ppd.effective_model.empty()) { | |
| 59 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; | 
| 68 if (!value.GetString(printing::kPrinterId, &id)) { | 63 if (!value.GetString(printing::kPrinterId, &id)) { | 
| 69 LOG(WARNING) << "Record id required"; | 64 LOG(WARNING) << "Record id required"; | 
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 const DictionaryValue* ppd; | 142 const DictionaryValue* ppd; | 
| 148 if (pref.GetDictionary(kPpdResource, &ppd)) { | 143 if (pref.GetDictionary(kPpdResource, &ppd)) { | 
| 149 *printer->mutable_ppd_reference() = DictionaryToPpdReference(ppd); | 144 *printer->mutable_ppd_reference() = DictionaryToPpdReference(ppd); | 
| 150 } | 145 } | 
| 151 | 146 | 
| 152 return printer; | 147 return printer; | 
| 153 } | 148 } | 
| 154 | 149 | 
| 155 } // namespace printing | 150 } // namespace printing | 
| 156 } // namespace chromeos | 151 } // namespace chromeos | 
| OLD | NEW |