Commit 81d0d7fc authored by Jimmy Gong's avatar Jimmy Gong Committed by Commit Bot

Change detected_printer_ppd_references_ to use an optional value

- Previous implementation of detected_printer_ppd_references_ used UniquePtrs
  to simulate optional PpdReference values to a map.
- This change changes the UniquePtr to base::Optional.

Bug: 932202
Test: browser_tests --gtest_filter=CrSettingsPrinting*
Change-Id: I9131bef5140ea0c3cb115c489975fae959bea21e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1560494
Commit-Queue: jimmy gong <jimmyxgong@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarBailey Berro <baileyberro@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#650527}
parent edb465a6
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/optional.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
...@@ -452,14 +453,14 @@ class CupsPrintersManagerImpl : public CupsPrintersManager, ...@@ -452,14 +453,14 @@ class CupsPrintersManagerImpl : public CupsPrintersManager,
const Printer::PpdReference& ref) { const Printer::PpdReference& ref) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_);
inflight_ppd_reference_resolutions_.erase(printer_id); inflight_ppd_reference_resolutions_.erase(printer_id);
// Create the entry.
std::unique_ptr<Printer::PpdReference>& value = // Create the entry. If we got something, populate the entry. Otherwise let
detected_printer_ppd_references_[printer_id]; // it just remain empty.
if (code == PpdProvider::SUCCESS) { detected_printer_ppd_references_[printer_id] =
// If we got something, populate the entry. Otherwise let it (code == PpdProvider::SUCCESS)
// just remain null. ? ref
value = std::make_unique<Printer::PpdReference>(ref); : base::Optional<Printer::PpdReference>();
}
RebuildDetectedLists(); RebuildDetectedLists();
} }
...@@ -495,10 +496,10 @@ class CupsPrintersManagerImpl : public CupsPrintersManager, ...@@ -495,10 +496,10 @@ class CupsPrintersManagerImpl : public CupsPrintersManager,
// This is a dual-purpose structure. The keys in the map are printer ids. // This is a dual-purpose structure. The keys in the map are printer ids.
// If an entry exists in this map it means we have received a response from // If an entry exists in this map it means we have received a response from
// PpdProvider about a PpdReference for the given printer. A null value // PpdProvider about a PpdReference for the given printer. An empty value
// means we don't have a PpdReference (and so can't set up this printer // means we don't have a PpdReference (and so can't set up this printer
// automatically). // automatically).
std::unordered_map<std::string, std::unique_ptr<Printer::PpdReference>> std::unordered_map<std::string, base::Optional<Printer::PpdReference>>
detected_printer_ppd_references_; detected_printer_ppd_references_;
// Printer ids for which we have sent off a request to PpdProvider for a ppd // Printer ids for which we have sent off a request to PpdProvider for a ppd
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment