Index: chromeos/printing/printer_translator.cc |
diff --git a/chromeos/printing/printer_translator.cc b/chromeos/printing/printer_translator.cc |
index 017d5e435404430c43d20c9c26d8d870aec0f8e9..d6fa3d4b41308d31a7f54f726deefe563f410683 100644 |
--- a/chromeos/printing/printer_translator.cc |
+++ b/chromeos/printing/printer_translator.cc |
@@ -32,24 +32,16 @@ const char kUri[] = "uri"; |
const char kUUID[] = "uuid"; |
const char kPpdResource[] = "ppd_resource"; |
-// Converts |value| into a Printer object for the fields that are shared |
-// between pref printers and policy printers. |
-std::unique_ptr<Printer> DictionaryToPrinter(const DictionaryValue& value) { |
- std::string id; |
- if (!value.GetString(printing::kPrinterId, &id)) { |
- LOG(WARNING) << "Record id required"; |
- return nullptr; |
- } |
- |
- std::unique_ptr<Printer> printer = base::MakeUnique<Printer>(id); |
- |
+// Populates the |printer| object with cooresponding fields from |value|. |
Lei Zhang
2017/05/09 01:14:39
corresponding
skau
2017/05/09 19:39:27
Done.
|
+// Returns false if |value| is missing a required field. |
+bool DictionaryToPrinter(const DictionaryValue& value, Printer* printer) { |
// Mandatory fields |
std::string display_name; |
if (value.GetString(kDisplayName, &display_name)) { |
printer->set_display_name(display_name); |
} else { |
LOG(WARNING) << "Display name required"; |
- return nullptr; |
+ return false; |
} |
std::string uri; |
@@ -57,7 +49,7 @@ std::unique_ptr<Printer> DictionaryToPrinter(const DictionaryValue& value) { |
printer->set_uri(uri); |
} else { |
LOG(WARNING) << "Uri required"; |
- return nullptr; |
+ return false; |
} |
// Optional fields |
@@ -77,7 +69,7 @@ std::unique_ptr<Printer> DictionaryToPrinter(const DictionaryValue& value) { |
if (value.GetString(kUUID, &uuid)) |
printer->set_uuid(uuid); |
- return printer; |
+ return true; |
} |
} // namespace |
@@ -87,9 +79,18 @@ namespace printing { |
const char kPrinterId[] = "id"; |
std::unique_ptr<Printer> RecommendedPrinterToPrinter( |
- const base::DictionaryValue& pref) { |
- std::unique_ptr<Printer> printer = DictionaryToPrinter(pref); |
- if (!printer) { |
+ const base::DictionaryValue& pref, |
+ const base::Time& timestamp) { |
+ DCHECK(!timestamp.is_null()); |
+ |
+ std::string id; |
+ if (!pref.GetString(printing::kPrinterId, &id)) { |
+ LOG(WARNING) << "Record id required"; |
+ return nullptr; |
+ } |
+ |
+ std::unique_ptr<Printer> printer = base::MakeUnique<Printer>(id, timestamp); |
+ if (!DictionaryToPrinter(pref, printer.get())) { |
LOG(WARNING) << "Failed to parse policy printer."; |
return nullptr; |
} |