| 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 19 matching lines...) Expand all Loading... |
| 30 const char kDescription[] = "description"; | 30 const char kDescription[] = "description"; |
| 31 const char kManufacturer[] = "manufacturer"; | 31 const char kManufacturer[] = "manufacturer"; |
| 32 const char kModel[] = "model"; | 32 const char kModel[] = "model"; |
| 33 const char kUri[] = "uri"; | 33 const char kUri[] = "uri"; |
| 34 const char kPPD[] = "ppd"; | 34 const char kPPD[] = "ppd"; |
| 35 const char kUUID[] = "uuid"; | 35 const char kUUID[] = "uuid"; |
| 36 | 36 |
| 37 std::unique_ptr<Printer::PPDFile> DictionaryToPPDFile( | 37 std::unique_ptr<Printer::PPDFile> DictionaryToPPDFile( |
| 38 const base::DictionaryValue* value) { | 38 const base::DictionaryValue* value) { |
| 39 std::unique_ptr<Printer::PPDFile> ppd = base::MakeUnique<Printer::PPDFile>(); | 39 std::unique_ptr<Printer::PPDFile> ppd = base::MakeUnique<Printer::PPDFile>(); |
| 40 int id = -1; | 40 // struct PPDFile defines default values for these fields so there is no need |
| 41 value->GetInteger(kPPDid, &id); | 41 // to check return values. |
| 42 ppd->id = id; | 42 value->GetInteger(kPPDid, &ppd->id); |
| 43 | 43 value->GetString(kFileName, &ppd->file_name); |
| 44 std::string file_name; | 44 value->GetInteger(kVersionNumber, &ppd->version_number); |
| 45 if (value->GetString(kFileName, &file_name)) | 45 value->GetBoolean(kFromQuirks, &ppd->from_quirks_server); |
| 46 ppd->file_name = file_name; | |
| 47 | |
| 48 int version_number = 0; | |
| 49 if (value->GetInteger(kVersionNumber, &version_number)) | |
| 50 ppd->version_number = version_number; | |
| 51 | |
| 52 bool from_quirks; | |
| 53 if (value->GetBoolean(kFromQuirks, &from_quirks)) | |
| 54 ppd->from_quirks_server = from_quirks; | |
| 55 | |
| 56 return ppd; | 46 return ppd; |
| 57 } | 47 } |
| 58 | 48 |
| 59 std::unique_ptr<base::DictionaryValue> PPDFileToDictionary( | 49 std::unique_ptr<base::DictionaryValue> PPDFileToDictionary( |
| 60 const Printer::PPDFile& ppd) { | 50 const Printer::PPDFile& ppd) { |
| 61 std::unique_ptr<base::DictionaryValue> dictionary = | 51 std::unique_ptr<base::DictionaryValue> dictionary = |
| 62 base::MakeUnique<base::DictionaryValue>(); | 52 base::MakeUnique<base::DictionaryValue>(); |
| 63 dictionary->SetInteger(kPPDid, ppd.id); | 53 dictionary->SetInteger(kPPDid, ppd.id); |
| 64 dictionary->SetString(kFileName, ppd.file_name); | 54 dictionary->SetString(kFileName, ppd.file_name); |
| 65 dictionary->SetInteger(kVersionNumber, ppd.version_number); | 55 dictionary->SetInteger(kVersionNumber, ppd.version_number); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 dictionary->SetString(kUUID, printer.uuid()); | 116 dictionary->SetString(kUUID, printer.uuid()); |
| 127 | 117 |
| 128 dictionary->Set(kPPD, PPDFileToDictionary(printer.ppd())); | 118 dictionary->Set(kPPD, PPDFileToDictionary(printer.ppd())); |
| 129 | 119 |
| 130 return dictionary; | 120 return dictionary; |
| 131 } | 121 } |
| 132 | 122 |
| 133 } // namespace printing | 123 } // namespace printing |
| 134 | 124 |
| 135 } // namespace chromeos | 125 } // namespace chromeos |
| OLD | NEW |