| 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 // TODO(justincarlson) -- This should be changed to effective_make_and_model to | 
 |   25 // match the implementation. | 
|   25 const char kEffectiveModel[] = "effective_model"; |   26 const char kEffectiveModel[] = "effective_model"; | 
|   26  |   27  | 
|   27 // printer fields |   28 // printer fields | 
|   28 const char kDisplayName[] = "display_name"; |   29 const char kDisplayName[] = "display_name"; | 
|   29 const char kDescription[] = "description"; |   30 const char kDescription[] = "description"; | 
|   30 const char kManufacturer[] = "manufacturer"; |   31 const char kManufacturer[] = "manufacturer"; | 
|   31 const char kModel[] = "model"; |   32 const char kModel[] = "model"; | 
|   32 const char kUri[] = "uri"; |   33 const char kUri[] = "uri"; | 
|   33 const char kPpdReference[] = "ppd_reference"; |   34 const char kPpdReference[] = "ppd_reference"; | 
|   34 const char kUUID[] = "uuid"; |   35 const char kUUID[] = "uuid"; | 
|   35  |   36  | 
|   36 // The name of the PpdResource for policy printers. |   37 // The name of the PpdResource for policy printers. | 
|   37 const char kPpdResource[] = "ppd_resource"; |   38 const char kPpdResource[] = "ppd_resource"; | 
|   38  |   39  | 
|   39 Printer::PpdReference DictionaryToPpdReference( |   40 Printer::PpdReference DictionaryToPpdReference( | 
|   40     const base::DictionaryValue* value) { |   41     const base::DictionaryValue* value) { | 
|   41   Printer::PpdReference ppd; |   42   Printer::PpdReference ppd; | 
|   42   value->GetString(kUserSuppliedPpdUrl, &ppd.user_supplied_ppd_url); |   43   value->GetString(kUserSuppliedPpdUrl, &ppd.user_supplied_ppd_url); | 
|   43   value->GetString(kEffectiveManufacturer, &ppd.effective_manufacturer); |   44   value->GetString(kEffectiveModel, &ppd.effective_make_and_model); | 
|   44   value->GetString(kEffectiveModel, &ppd.effective_model); |  | 
|   45   return ppd; |   45   return ppd; | 
|   46 } |   46 } | 
|   47  |   47  | 
|   48 // Convert a PpdReference struct to a DictionaryValue. |   48 // Convert a PpdReference struct to a DictionaryValue. | 
|   49 std::unique_ptr<base::DictionaryValue> PpdReferenceToDictionary( |   49 std::unique_ptr<base::DictionaryValue> PpdReferenceToDictionary( | 
|   50     const Printer::PpdReference& ppd) { |   50     const Printer::PpdReference& ppd) { | 
|   51   auto dictionary = base::MakeUnique<DictionaryValue>(); |   51   auto dictionary = base::MakeUnique<DictionaryValue>(); | 
|   52   if (!ppd.user_supplied_ppd_url.empty()) { |   52   if (!ppd.user_supplied_ppd_url.empty()) { | 
|   53     dictionary->SetString(kUserSuppliedPpdUrl, ppd.user_supplied_ppd_url); |   53     dictionary->SetString(kUserSuppliedPpdUrl, ppd.user_supplied_ppd_url); | 
|   54   } |   54   } | 
|   55   if (!ppd.effective_manufacturer.empty()) { |   55   if (!ppd.effective_make_and_model.empty()) { | 
|   56     dictionary->SetString(kEffectiveManufacturer, ppd.effective_manufacturer); |   56     dictionary->SetString(kEffectiveModel, ppd.effective_make_and_model); | 
|   57   } |  | 
|   58   if (!ppd.effective_model.empty()) { |  | 
|   59     dictionary->SetString(kEffectiveModel, ppd.effective_model); |  | 
|   60   } |   57   } | 
|   61   return dictionary; |   58   return dictionary; | 
|   62 } |   59 } | 
|   63  |   60  | 
|   64 // Converts |value| into a Printer object for the fields that are shared |   61 // Converts |value| into a Printer object for the fields that are shared | 
|   65 // between pref printers and policy printers. |   62 // between pref printers and policy printers. | 
|   66 std::unique_ptr<Printer> DictionaryToPrinter(const DictionaryValue& value) { |   63 std::unique_ptr<Printer> DictionaryToPrinter(const DictionaryValue& value) { | 
|   67   std::string id; |   64   std::string id; | 
|   68   if (!value.GetString(printing::kPrinterId, &id)) { |   65   if (!value.GetString(printing::kPrinterId, &id)) { | 
|   69     LOG(WARNING) << "Record id required"; |   66     LOG(WARNING) << "Record id required"; | 
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  147   const DictionaryValue* ppd; |  144   const DictionaryValue* ppd; | 
|  148   if (pref.GetDictionary(kPpdResource, &ppd)) { |  145   if (pref.GetDictionary(kPpdResource, &ppd)) { | 
|  149     *printer->mutable_ppd_reference() = DictionaryToPpdReference(ppd); |  146     *printer->mutable_ppd_reference() = DictionaryToPpdReference(ppd); | 
|  150   } |  147   } | 
|  151  |  148  | 
|  152   return printer; |  149   return printer; | 
|  153 } |  150 } | 
|  154  |  151  | 
|  155 }  // namespace printing |  152 }  // namespace printing | 
|  156 }  // namespace chromeos |  153 }  // namespace chromeos | 
| OLD | NEW |