Index: chrome/browser/chromeos/printing/printers_manager.cc |
diff --git a/chrome/browser/chromeos/printing/printers_manager.cc b/chrome/browser/chromeos/printing/printers_manager.cc |
index 4bcef70c45e7664922e193bd3c1ed25789cbb832..4e6684fe36b53b349d39a8a83ce06a52ac5946c2 100644 |
--- a/chrome/browser/chromeos/printing/printers_manager.cc |
+++ b/chrome/browser/chromeos/printing/printers_manager.cc |
@@ -90,13 +90,9 @@ std::vector<std::unique_ptr<Printer>> PrintersManager::GetRecommendedPrinters() |
std::vector<std::unique_ptr<Printer>> printers; |
for (const std::string& key : recommended_printer_ids_) { |
- const base::DictionaryValue& printer_dictionary = |
- *(recommended_printers_.at(key)); |
- std::unique_ptr<Printer> printer = |
- printing::RecommendedPrinterToPrinter(printer_dictionary); |
- if (printer) { |
- printer->set_source(Printer::SRC_POLICY); |
- printers.push_back(std::move(printer)); |
+ auto printer = recommended_printers_.find(key); |
+ if (printer != recommended_printers_.end()) { |
+ printers.push_back(base::MakeUnique<Printer>(*printer->second)); |
} |
} |
@@ -108,8 +104,10 @@ std::unique_ptr<Printer> PrintersManager::GetPrinter( |
// check for a policy printer first |
const auto& policy_printers = recommended_printers_; |
auto found = policy_printers.find(printer_id); |
- if (found != policy_printers.end()) |
- return printing::RecommendedPrinterToPrinter(*(found->second)); |
+ if (found != policy_printers.end()) { |
+ // Copy a printer. |
+ return base::MakeUnique<Printer>(*(found->second)); |
+ } |
base::Optional<sync_pb::PrinterSpecifics> printer = |
sync_bridge_->GetPrinter(printer_id); |
@@ -176,6 +174,7 @@ void PrintersManager::UpdateRecommendedPrinters() { |
const base::ListValue* values = |
prefs->GetList(prefs::kRecommendedNativePrinters); |
+ int64_t timestamp = base::Time::Now().ToJavaTime(); |
recommended_printer_ids_.clear(); |
for (const auto& value : *values) { |
@@ -202,8 +201,27 @@ void PrintersManager::UpdateRecommendedPrinters() { |
printer_dictionary->SetString(printing::kPrinterId, id); |
recommended_printer_ids_.push_back(id); |
Carlson
2017/05/05 23:59:16
Does this mean we're happy to push the same printe
skau
2017/05/08 18:38:02
It's cleared on line 179. We save the ids to keep
Carlson
2017/05/08 18:49:25
I'm still a little confused by this, sorry.
In th
|
- recommended_printers_[id] = std::move(printer_dictionary); |
+ if (!base::ContainsKey(recommended_printers_, id)) { |
+ auto printer = |
+ printing::RecommendedPrinterToPrinter(*printer_dictionary, timestamp); |
+ printer->set_source(Printer::SRC_POLICY); |
+ |
+ recommended_printers_[id] = std::move(printer); |
+ } |
} |
} |
+void PrintersManager::PrinterInstalled(const Printer& printer) { |
+ DCHECK_GT(printer.last_updated(), 0); |
+ installed_printer_timestamps_[printer.id()] = printer.last_updated(); |
+} |
+ |
+bool PrintersManager::IsConfigurationCurrent(const Printer& printer) { |
+ auto found = installed_printer_timestamps_.find(printer.id()); |
+ if (found == installed_printer_timestamps_.end()) |
+ return false; |
+ |
+ return found->second == printer.last_updated(); |
+} |
+ |
} // namespace chromeos |