Commit b2299f90 authored by Bailey Berro's avatar Bailey Berro Committed by Commit Bot

Switch CupsPrintersManager::GetPrinter to returning an optional

Previously, we were constructing and returning a unique_ptr solely for
the purpose of being able to return a nullptr if a printer was not found.
Instead, let's just return an optional which makes more sense for this.

Change-Id: I14db20b6f7ffc8855ee48de2eda622fb78ec6b57
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1572263
Commit-Queue: Bailey Berro <baileyberro@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652894}
parent 21699e36
...@@ -238,21 +238,20 @@ class PrinterDiscoverySessionHostImpl ...@@ -238,21 +238,20 @@ class PrinterDiscoverySessionHostImpl
} }
void StartPrinterStateTracking(const std::string& printer_id) override { void StartPrinterStateTracking(const std::string& printer_id) override {
std::unique_ptr<chromeos::Printer> printer = base::Optional<chromeos::Printer> printer =
printers_manager_->GetPrinter(printer_id); printers_manager_->GetPrinter(printer_id);
if (!printer) { if (!printer) {
RemovePrinter(printer_id); RemovePrinter(printer_id);
return; return;
} }
if (printers_manager_->IsPrinterInstalled(*printer)) { if (printers_manager_->IsPrinterInstalled(*printer)) {
PrinterInstalled(std::move(printer), chromeos::kSuccess); PrinterInstalled(*printer, chromeos::kSuccess);
return; return;
} }
const chromeos::Printer& printer_ref = *printer;
configurer_->SetUpPrinter( configurer_->SetUpPrinter(
printer_ref, *printer,
base::BindOnce(&PrinterDiscoverySessionHostImpl::PrinterInstalled, base::BindOnce(&PrinterDiscoverySessionHostImpl::PrinterInstalled,
weak_ptr_factory_.GetWeakPtr(), std::move(printer))); weak_ptr_factory_.GetWeakPtr(), *printer));
} }
void StopPrinterStateTracking(const std::string& printer_id) override { void StopPrinterStateTracking(const std::string& printer_id) override {
...@@ -281,19 +280,19 @@ class PrinterDiscoverySessionHostImpl ...@@ -281,19 +280,19 @@ class PrinterDiscoverySessionHostImpl
} }
// Fetch capabilities for newly installed printer. // Fetch capabilities for newly installed printer.
void PrinterInstalled(std::unique_ptr<chromeos::Printer> printer, void PrinterInstalled(const chromeos::Printer& printer,
chromeos::PrinterSetupResult result) { chromeos::PrinterSetupResult result) {
if (result != chromeos::kSuccess) { if (result != chromeos::kSuccess) {
RemovePrinter(printer->id()); RemovePrinter(printer.id());
return; return;
} }
printers_manager_->PrinterInstalled(*printer, true /*is_automatic*/); printers_manager_->PrinterInstalled(printer, true /*is_automatic*/);
const std::string& printer_id = printer->id(); const std::string& printer_id = printer.id();
base::PostTaskWithTraitsAndReplyWithResult( base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {base::MayBlock()}, FROM_HERE, {base::MayBlock()},
base::BindOnce(&FetchCapabilitiesOnBlockingTaskRunner, printer_id), base::BindOnce(&FetchCapabilitiesOnBlockingTaskRunner, printer_id),
base::BindOnce(&PrinterDiscoverySessionHostImpl::CapabilitiesReceived, base::BindOnce(&PrinterDiscoverySessionHostImpl::CapabilitiesReceived,
weak_ptr_factory_.GetWeakPtr(), std::move(printer))); weak_ptr_factory_.GetWeakPtr(), printer));
} }
// Remove from the list of available printers. // Remove from the list of available printers.
...@@ -303,14 +302,14 @@ class PrinterDiscoverySessionHostImpl ...@@ -303,14 +302,14 @@ class PrinterDiscoverySessionHostImpl
// Transform printer capabilities to mojo type and send to container. // Transform printer capabilities to mojo type and send to container.
void CapabilitiesReceived( void CapabilitiesReceived(
std::unique_ptr<chromeos::Printer> printer, const chromeos::Printer& printer,
std::unique_ptr<printing::PrinterSemanticCapsAndDefaults> caps) { std::unique_ptr<printing::PrinterSemanticCapsAndDefaults> caps) {
if (!caps) { if (!caps) {
RemovePrinter(printer->id()); RemovePrinter(printer.id());
return; return;
} }
std::vector<mojom::PrinterInfoPtr> arc_printers; std::vector<mojom::PrinterInfoPtr> arc_printers;
arc_printers.emplace_back(ToArcPrinter(*printer, std::move(caps))); arc_printers.push_back(ToArcPrinter(printer, std::move(caps)));
instance_->AddPrinters(std::move(arc_printers)); instance_->AddPrinters(std::move(arc_printers));
} }
......
...@@ -197,7 +197,7 @@ class CupsPrintersManagerImpl : public CupsPrintersManager, ...@@ -197,7 +197,7 @@ class CupsPrintersManagerImpl : public CupsPrintersManager,
// Note this is linear in the number of printers. If the number of printers // Note this is linear in the number of printers. If the number of printers
// gets so large that a linear search is prohibative, we'll have to rethink // gets so large that a linear search is prohibative, we'll have to rethink
// more than just this function. // more than just this function.
std::unique_ptr<Printer> GetPrinter(const std::string& id) const override { base::Optional<Printer> GetPrinter(const std::string& id) const override {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_);
if (!native_printers_allowed_.GetValue()) { if (!native_printers_allowed_.GetValue()) {
LOG(WARNING) << "UserNativePrintersAllowed is disabled - only searching " LOG(WARNING) << "UserNativePrintersAllowed is disabled - only searching "
...@@ -208,11 +208,11 @@ class CupsPrintersManagerImpl : public CupsPrintersManager, ...@@ -208,11 +208,11 @@ class CupsPrintersManagerImpl : public CupsPrintersManager,
for (const auto& printer_list : printers_) { for (const auto& printer_list : printers_) {
for (const auto& printer : printer_list) { for (const auto& printer : printer_list) {
if (printer.id() == id) { if (printer.id() == id) {
return std::make_unique<Printer>(printer); return printer;
} }
} }
} }
return std::unique_ptr<Printer>(); return base::nullopt;
} }
// SyncedPrintersManager::Observer implementation // SyncedPrintersManager::Observer implementation
...@@ -256,13 +256,13 @@ class CupsPrintersManagerImpl : public CupsPrintersManager, ...@@ -256,13 +256,13 @@ class CupsPrintersManagerImpl : public CupsPrintersManager,
} }
private: private:
std::unique_ptr<Printer> GetEnterprisePrinter(const std::string& id) const { base::Optional<Printer> GetEnterprisePrinter(const std::string& id) const {
for (const auto& printer : printers_[kEnterprise]) { for (const auto& printer : printers_[kEnterprise]) {
if (printer.id() == id) { if (printer.id() == id) {
return std::make_unique<Printer>(printer); return printer;
} }
} }
return nullptr; return base::nullopt;
} }
// Notify observers on the given classes the the relevant lists have changed. // Notify observers on the given classes the the relevant lists have changed.
......
...@@ -113,8 +113,8 @@ class CupsPrintersManager : public KeyedService { ...@@ -113,8 +113,8 @@ class CupsPrintersManager : public KeyedService {
virtual bool IsPrinterInstalled(const Printer& printer) const = 0; virtual bool IsPrinterInstalled(const Printer& printer) const = 0;
// Look for a printer with the given id in any class. Returns a copy of the // Look for a printer with the given id in any class. Returns a copy of the
// printer if found, null if not found. // printer if found, base::nullopt if not found.
virtual std::unique_ptr<Printer> GetPrinter(const std::string& id) const = 0; virtual base::Optional<Printer> GetPrinter(const std::string& id) const = 0;
// Log an event that the user started trying to set up the given printer, // Log an event that the user started trying to set up the given printer,
// but setup was not completed for some reason. // but setup was not completed for some reason.
......
...@@ -475,13 +475,13 @@ TEST_F(CupsPrintersManagerTest, GetPrinter) { ...@@ -475,13 +475,13 @@ TEST_F(CupsPrintersManagerTest, GetPrinter) {
for (const std::string& id : for (const std::string& id :
{"Saved", "Enterprise", "Discovered", "Automatic"}) { {"Saved", "Enterprise", "Discovered", "Automatic"}) {
std::unique_ptr<Printer> printer = manager_->GetPrinter(id); base::Optional<Printer> printer = manager_->GetPrinter(id);
ASSERT_NE(printer, nullptr); ASSERT_TRUE(printer);
EXPECT_EQ(printer->id(), id); EXPECT_EQ(printer->id(), id);
} }
std::unique_ptr<Printer> printer = manager_->GetPrinter("Nope"); base::Optional<Printer> printer = manager_->GetPrinter("Nope");
EXPECT_EQ(printer, nullptr); EXPECT_FALSE(printer);
} }
// Test that if |UserNativePrintersAllowed| pref is set to false, then // Test that if |UserNativePrintersAllowed| pref is set to false, then
...@@ -577,12 +577,13 @@ TEST_F(CupsPrintersManagerTest, GetPrinterUserNativePrintersDisabled) { ...@@ -577,12 +577,13 @@ TEST_F(CupsPrintersManagerTest, GetPrinterUserNativePrintersDisabled) {
// Diable the use of non-enterprise printers. // Diable the use of non-enterprise printers.
UpdatePolicyValue(prefs::kUserNativePrintersAllowed, false); UpdatePolicyValue(prefs::kUserNativePrintersAllowed, false);
std::unique_ptr<Printer> saved_ptr = manager_->GetPrinter("Saved"); base::Optional<Printer> saved_printer = manager_->GetPrinter("Saved");
EXPECT_EQ(saved_ptr, nullptr); EXPECT_FALSE(saved_printer);
std::unique_ptr<Printer> enterprise_ptr = manager_->GetPrinter("Enterprise"); base::Optional<Printer> enterprise_printer =
ASSERT_NE(enterprise_ptr, nullptr); manager_->GetPrinter("Enterprise");
EXPECT_EQ(enterprise_ptr->id(), "Enterprise"); ASSERT_TRUE(enterprise_printer);
EXPECT_EQ(enterprise_printer->id(), "Enterprise");
} }
} // namespace } // namespace
......
...@@ -77,19 +77,19 @@ void CapabilitiesFetched(base::Value policies, ...@@ -77,19 +77,19 @@ void CapabilitiesFetched(base::Value policies,
std::move(cb).Run(std::move(printer_info)); std::move(cb).Run(std::move(printer_info));
} }
void FetchCapabilities(std::unique_ptr<chromeos::Printer> printer, void FetchCapabilities(const chromeos::Printer& printer,
base::Value policies, base::Value policies,
LocalPrinterHandlerChromeos::GetCapabilityCallback cb) { LocalPrinterHandlerChromeos::GetCapabilityCallback cb) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
PrinterBasicInfo basic_info = ToBasicInfo(*printer); PrinterBasicInfo basic_info = ToBasicInfo(printer);
bool has_secure_protocol = !printer->HasNetworkProtocol() || bool has_secure_protocol = !printer.HasNetworkProtocol() ||
printer->GetProtocol() == chromeos::Printer::kIpps; printer.GetProtocol() == chromeos::Printer::kIpps;
// USER_VISIBLE because the result is displayed in the print preview dialog. // USER_VISIBLE because the result is displayed in the print preview dialog.
base::PostTaskWithTraitsAndReplyWithResult( base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE}, FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE},
base::BindOnce(&GetSettingsOnBlockingPool, printer->id(), basic_info, base::BindOnce(&GetSettingsOnBlockingPool, printer.id(), basic_info,
PrinterSemanticCapsAndDefaults::Papers(), PrinterSemanticCapsAndDefaults::Papers(),
has_secure_protocol, nullptr), has_secure_protocol, nullptr),
base::BindOnce(&CapabilitiesFetched, std::move(policies), std::move(cb))); base::BindOnce(&CapabilitiesFetched, std::move(policies), std::move(cb)));
...@@ -181,7 +181,7 @@ void LocalPrinterHandlerChromeos::StartGetCapability( ...@@ -181,7 +181,7 @@ void LocalPrinterHandlerChromeos::StartGetCapability(
GetCapabilityCallback cb) { GetCapabilityCallback cb) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
std::unique_ptr<chromeos::Printer> printer = base::Optional<chromeos::Printer> printer =
printers_manager_->GetPrinter(printer_name); printers_manager_->GetPrinter(printer_name);
if (!printer) { if (!printer) {
// If the printer was removed, the lookup will fail. // If the printer was removed, the lookup will fail.
...@@ -197,32 +197,29 @@ void LocalPrinterHandlerChromeos::StartGetCapability( ...@@ -197,32 +197,29 @@ void LocalPrinterHandlerChromeos::StartGetCapability(
if (printers_manager_->IsPrinterInstalled(*printer)) { if (printers_manager_->IsPrinterInstalled(*printer)) {
// Skip setup if the printer is already installed. // Skip setup if the printer is already installed.
HandlePrinterSetup(std::move(printer), std::move(cb), chromeos::kSuccess); HandlePrinterSetup(*printer, std::move(cb), chromeos::kSuccess);
return; return;
} }
const chromeos::Printer& printer_ref = *printer;
printer_configurer_->SetUpPrinter( printer_configurer_->SetUpPrinter(
printer_ref, *printer,
base::BindOnce(&LocalPrinterHandlerChromeos::HandlePrinterSetup, base::BindOnce(&LocalPrinterHandlerChromeos::HandlePrinterSetup,
weak_factory_.GetWeakPtr(), std::move(printer), weak_factory_.GetWeakPtr(), *printer, std::move(cb)));
std::move(cb)));
} }
void LocalPrinterHandlerChromeos::HandlePrinterSetup( void LocalPrinterHandlerChromeos::HandlePrinterSetup(
std::unique_ptr<chromeos::Printer> printer, const chromeos::Printer& printer,
GetCapabilityCallback cb, GetCapabilityCallback cb,
chromeos::PrinterSetupResult result) { chromeos::PrinterSetupResult result) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
switch (result) { switch (result) {
case chromeos::PrinterSetupResult::kSuccess: { case chromeos::PrinterSetupResult::kSuccess: {
VLOG(1) << "Printer setup successful for " << printer->id() VLOG(1) << "Printer setup successful for " << printer.id()
<< " fetching properties"; << " fetching properties";
printers_manager_->PrinterInstalled(*printer, true /*is_automatic*/); printers_manager_->PrinterInstalled(printer, true /*is_automatic*/);
// fetch settings on the blocking pool and invoke callback. // fetch settings on the blocking pool and invoke callback.
FetchCapabilities(std::move(printer), GetNativePrinterPolicies(), FetchCapabilities(printer, GetNativePrinterPolicies(), std::move(cb));
std::move(cb));
return; return;
} }
case chromeos::PrinterSetupResult::kPpdNotFound: case chromeos::PrinterSetupResult::kPpdNotFound:
......
...@@ -65,7 +65,7 @@ class LocalPrinterHandlerChromeos : public PrinterHandler { ...@@ -65,7 +65,7 @@ class LocalPrinterHandlerChromeos : public PrinterHandler {
// |profile_|. // |profile_|.
base::Value GetNativePrinterPolicies() const; base::Value GetNativePrinterPolicies() const;
void HandlePrinterSetup(std::unique_ptr<chromeos::Printer> printer, void HandlePrinterSetup(const chromeos::Printer& printer,
GetCapabilityCallback cb, GetCapabilityCallback cb,
chromeos::PrinterSetupResult result); chromeos::PrinterSetupResult result);
......
...@@ -90,15 +90,17 @@ class FakeCupsPrintersManager : public CupsPrintersManager { ...@@ -90,15 +90,17 @@ class FakeCupsPrintersManager : public CupsPrintersManager {
return installed_.contains(printer.id()); return installed_.contains(printer.id());
} }
std::unique_ptr<Printer> GetPrinter(const std::string& id) const override { base::Optional<Printer> GetPrinter(const std::string& id) const override {
// Search through each class of printers and find a printer with a
// matching id.
for (const std::vector<Printer>& v : printers_) { for (const std::vector<Printer>& v : printers_) {
auto iter = std::find_if( auto iter = std::find_if(
v.begin(), v.end(), [&id](const Printer& p) { return p.id() == id; }); v.begin(), v.end(), [&id](const Printer& p) { return p.id() == id; });
if (iter != v.end()) { if (iter != v.end()) {
return std::make_unique<Printer>(*iter); return *iter;
} }
} }
return nullptr; return base::nullopt;
} }
// Add |printer| to the corresponding list in |printers_| bases on the given // Add |printer| to the corresponding list in |printers_| bases on the given
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/json/json_string_value_serializer.h" #include "base/json/json_string_value_serializer.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/optional.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
...@@ -478,7 +479,7 @@ void CupsPrintersHandler::HandleGetPrinterInfo(const base::ListValue* args) { ...@@ -478,7 +479,7 @@ void CupsPrintersHandler::HandleGetPrinterInfo(const base::ListValue* args) {
} }
void CupsPrintersHandler::OnAutoconfQueriedDiscovered( void CupsPrintersHandler::OnAutoconfQueriedDiscovered(
std::unique_ptr<Printer> printer, Printer printer,
bool success, bool success,
const std::string& make, const std::string& make,
const std::string& model, const std::string& model,
...@@ -495,9 +496,9 @@ void CupsPrintersHandler::OnAutoconfQueriedDiscovered( ...@@ -495,9 +496,9 @@ void CupsPrintersHandler::OnAutoconfQueriedDiscovered(
// manufacturer and model are set with make_and_model because they are // manufacturer and model are set with make_and_model because they are
// derived from make_and_model for compatability and are slated for // derived from make_and_model for compatability and are slated for
// removal. // removal.
printer->set_manufacturer(make); printer.set_manufacturer(make);
printer->set_model(model); printer.set_model(model);
printer->set_make_and_model(make_and_model); printer.set_make_and_model(make_and_model);
PRINTER_LOG(DEBUG) << "Printer queried for make and model " PRINTER_LOG(DEBUG) << "Printer queried for make and model "
<< make_and_model; << make_and_model;
} }
...@@ -505,10 +506,11 @@ void CupsPrintersHandler::OnAutoconfQueriedDiscovered( ...@@ -505,10 +506,11 @@ void CupsPrintersHandler::OnAutoconfQueriedDiscovered(
// Autoconfig available, use it. // Autoconfig available, use it.
if (ipp_everywhere) { if (ipp_everywhere) {
PRINTER_LOG(DEBUG) << "Performing autoconf setup"; PRINTER_LOG(DEBUG) << "Performing autoconf setup";
printer->mutable_ppd_reference()->autoconf = true; printer.mutable_ppd_reference()->autoconf = true;
printer_configurer_->SetUpPrinter( printer_configurer_->SetUpPrinter(
*printer, base::Bind(&CupsPrintersHandler::OnAddedDiscoveredPrinter, printer,
weak_factory_.GetWeakPtr(), *printer)); base::BindOnce(&CupsPrintersHandler::OnAddedDiscoveredPrinter,
weak_factory_.GetWeakPtr(), printer));
return; return;
} }
} }
...@@ -517,7 +519,7 @@ void CupsPrintersHandler::OnAutoconfQueriedDiscovered( ...@@ -517,7 +519,7 @@ void CupsPrintersHandler::OnAutoconfQueriedDiscovered(
// much information as we can about the printer, and ask the user to supply // much information as we can about the printer, and ask the user to supply
// the rest. // the rest.
PRINTER_LOG(EVENT) << "Could not query printer. Fallback to asking the user"; PRINTER_LOG(EVENT) << "Could not query printer. Fallback to asking the user";
FireManuallyAddDiscoveredPrinter(*printer); FireManuallyAddDiscoveredPrinter(printer);
} }
void CupsPrintersHandler::OnAutoconfQueried( void CupsPrintersHandler::OnAutoconfQueried(
...@@ -635,7 +637,7 @@ void CupsPrintersHandler::AddOrReconfigurePrinter(const base::ListValue* args, ...@@ -635,7 +637,7 @@ void CupsPrintersHandler::AddOrReconfigurePrinter(const base::ListValue* args,
return; return;
} }
std::unique_ptr<Printer> existing_printer_object = base::Optional<Printer> existing_printer_object =
printers_manager_->GetPrinter(printer->id()); printers_manager_->GetPrinter(printer->id());
if (existing_printer_object) { if (existing_printer_object) {
if (!IsValidUriChange(*existing_printer_object, *printer)) { if (!IsValidUriChange(*existing_printer_object, *printer)) {
...@@ -1009,8 +1011,8 @@ void CupsPrintersHandler::HandleAddDiscoveredPrinter( ...@@ -1009,8 +1011,8 @@ void CupsPrintersHandler::HandleAddDiscoveredPrinter(
CHECK(args->GetString(0, &printer_id)); CHECK(args->GetString(0, &printer_id));
PRINTER_LOG(USER) << "Adding discovered printer"; PRINTER_LOG(USER) << "Adding discovered printer";
std::unique_ptr<Printer> printer = printers_manager_->GetPrinter(printer_id); base::Optional<Printer> printer = printers_manager_->GetPrinter(printer_id);
if (printer == nullptr) { if (!printer) {
PRINTER_LOG(ERROR) << "Discovered printer disappeared"; PRINTER_LOG(ERROR) << "Discovered printer disappeared";
// Printer disappeared, so we don't have information about it anymore and // Printer disappeared, so we don't have information about it anymore and
// can't really do much. Fail the add. // can't really do much. Fail the add.
...@@ -1049,7 +1051,7 @@ void CupsPrintersHandler::HandleAddDiscoveredPrinter( ...@@ -1049,7 +1051,7 @@ void CupsPrintersHandler::HandleAddDiscoveredPrinter(
} }
endpoint_resolver_->Start( endpoint_resolver_->Start(
address, base::BindOnce(&CupsPrintersHandler::OnIpResolved, address, base::BindOnce(&CupsPrintersHandler::OnIpResolved,
weak_factory_.GetWeakPtr(), std::move(printer))); weak_factory_.GetWeakPtr(), std::move(*printer)));
} }
void CupsPrintersHandler::HandleGetPrinterPpdManufacturerAndModel( void CupsPrintersHandler::HandleGetPrinterPpdManufacturerAndModel(
...@@ -1094,32 +1096,32 @@ void CupsPrintersHandler::FireManuallyAddDiscoveredPrinter( ...@@ -1094,32 +1096,32 @@ void CupsPrintersHandler::FireManuallyAddDiscoveredPrinter(
*GetCupsPrinterInfo(printer)); *GetCupsPrinterInfo(printer));
} }
void CupsPrintersHandler::OnIpResolved(std::unique_ptr<Printer> printer, void CupsPrintersHandler::OnIpResolved(const Printer& printer,
const net::IPEndPoint& endpoint) { const net::IPEndPoint& endpoint) {
bool address_resolved = endpoint.address().IsValid(); bool address_resolved = endpoint.address().IsValid();
UMA_HISTOGRAM_BOOLEAN("Printing.CUPS.AddressResolutionResult", UMA_HISTOGRAM_BOOLEAN("Printing.CUPS.AddressResolutionResult",
address_resolved); address_resolved);
if (!address_resolved) { if (!address_resolved) {
PRINTER_LOG(ERROR) << printer->make_and_model() << " IP Resolution failed"; PRINTER_LOG(ERROR) << printer.make_and_model() << " IP Resolution failed";
OnAddedDiscoveredPrinter(*printer, PrinterSetupResult::kPrinterUnreachable); OnAddedDiscoveredPrinter(printer, PrinterSetupResult::kPrinterUnreachable);
return; return;
} }
PRINTER_LOG(EVENT) << printer->make_and_model() << " IP Resolution succeeded"; PRINTER_LOG(EVENT) << printer.make_and_model() << " IP Resolution succeeded";
std::string resolved_uri = printer->ReplaceHostAndPort(endpoint); std::string resolved_uri = printer.ReplaceHostAndPort(endpoint);
if (IsIppUri(resolved_uri)) { if (IsIppUri(resolved_uri)) {
PRINTER_LOG(EVENT) << "Query printer for IPP attributes"; PRINTER_LOG(EVENT) << "Query printer for IPP attributes";
QueryAutoconf(resolved_uri, QueryAutoconf(
base::BindRepeating( resolved_uri,
&CupsPrintersHandler::OnAutoconfQueriedDiscovered, base::BindRepeating(&CupsPrintersHandler::OnAutoconfQueriedDiscovered,
weak_factory_.GetWeakPtr(), base::Passed(&printer))); weak_factory_.GetWeakPtr(), printer));
return; return;
} }
PRINTER_LOG(EVENT) << "Request make and model from user"; PRINTER_LOG(EVENT) << "Request make and model from user";
// If it's not an IPP printer, the user must choose a PPD. // If it's not an IPP printer, the user must choose a PPD.
FireManuallyAddDiscoveredPrinter(*printer); FireManuallyAddDiscoveredPrinter(printer);
} }
} // namespace settings } // namespace settings
......
...@@ -88,7 +88,7 @@ class CupsPrintersHandler : public ::settings::SettingsPageUIHandler, ...@@ -88,7 +88,7 @@ class CupsPrintersHandler : public ::settings::SettingsPageUIHandler,
// Handles the callback for HandleGetPrinterInfo for a discovered printer. // Handles the callback for HandleGetPrinterInfo for a discovered printer.
void OnAutoconfQueriedDiscovered( void OnAutoconfQueriedDiscovered(
std::unique_ptr<Printer> printer, Printer printer,
bool success, bool success,
const std::string& make, const std::string& make,
const std::string& model, const std::string& model,
...@@ -191,8 +191,7 @@ class CupsPrintersHandler : public ::settings::SettingsPageUIHandler, ...@@ -191,8 +191,7 @@ class CupsPrintersHandler : public ::settings::SettingsPageUIHandler,
// parameters. See https://crbug.com/835476 // parameters. See https://crbug.com/835476
void FireManuallyAddDiscoveredPrinter(const Printer& printer); void FireManuallyAddDiscoveredPrinter(const Printer& printer);
void OnIpResolved(std::unique_ptr<Printer> printer, void OnIpResolved(const Printer& printer, const net::IPEndPoint& endpoint);
const net::IPEndPoint& endpoint);
Profile* profile_; Profile* profile_;
......
...@@ -72,8 +72,8 @@ class FakeCupsPrintersManager : public CupsPrintersManager { ...@@ -72,8 +72,8 @@ class FakeCupsPrintersManager : public CupsPrintersManager {
return false; return false;
} }
std::unique_ptr<Printer> GetPrinter(const std::string& id) const override { base::Optional<Printer> GetPrinter(const std::string& id) const override {
return std::make_unique<Printer>(); return Printer();
} }
}; };
......
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