Use new facilities for base::expected: chrome/
Bug: 1424513
Change-Id: I0d6a701fe937569287fa8a642902d829d1b07e23
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4755226
Reviewed-by: Ted Choc <tedchoc@chromium.org>
Code-Coverage: Findit <findit-for-me@appspot.gserviceaccount.com>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1180537}
diff --git a/chrome/services/printing/print_backend_service_impl.cc b/chrome/services/printing/print_backend_service_impl.cc
index 9abf8b8..23cc3d31 100644
--- a/chrome/services/printing/print_backend_service_impl.cc
+++ b/chrome/services/printing/print_backend_service_impl.cc
@@ -20,6 +20,7 @@
#include "base/task/thread_pool.h"
#include "base/threading/sequence_bound.h"
#include "base/types/expected.h"
+#include "base/types/expected_macros.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
@@ -564,15 +565,14 @@
#if BUILDFLAG(IS_WIN)
if (xml_parser_remote_.is_bound() &&
base::FeatureList::IsEnabled(features::kReadPrinterCapabilitiesWithXps)) {
- base::expected<XpsCapabilities, mojom::ResultCode> xps_capabilities =
- GetXpsCapabilities(printer_name);
- if (!xps_capabilities.has_value()) {
- std::move(callback).Run(mojom::PrinterCapsAndInfoResult::NewResultCode(
- xps_capabilities.error()));
- return;
- }
+ ASSIGN_OR_RETURN(
+ XpsCapabilities xps_capabilities, GetXpsCapabilities(printer_name),
+ [&](mojom::ResultCode error) {
+ return std::move(callback).Run(
+ mojom::PrinterCapsAndInfoResult::NewResultCode(error));
+ });
- MergeXpsCapabilities(std::move(xps_capabilities.value()), caps);
+ MergeXpsCapabilities(std::move(xps_capabilities), caps);
}
#endif // BUILDFLAG(IS_WIN)
@@ -946,17 +946,17 @@
#if BUILDFLAG(IS_WIN)
base::expected<XpsCapabilities, mojom::ResultCode>
PrintBackendServiceImpl::GetXpsCapabilities(const std::string& printer_name) {
- base::expected<std::string, mojom::ResultCode> xml =
- print_backend_->GetXmlPrinterCapabilitiesForXpsDriver(printer_name);
- if (!xml.has_value()) {
- DLOG(ERROR) << "Failure getting XPS capabilities of printer "
- << printer_name << ", error: " << xml.error();
- return base::unexpected(xml.error());
- }
+ ASSIGN_OR_RETURN(
+ std::string xml,
+ print_backend_->GetXmlPrinterCapabilitiesForXpsDriver(printer_name),
+ [&](mojom::ResultCode error) {
+ DLOG(ERROR) << "Failure getting XPS capabilities of printer "
+ << printer_name << ", error: " << error;
+ return error;
+ });
mojom::PrinterCapabilitiesValueResultPtr value_result;
- xml_parser_remote_->ParseXmlForPrinterCapabilities(xml.value(),
- &value_result);
+ xml_parser_remote_->ParseXmlForPrinterCapabilities(xml, &value_result);
if (value_result->is_result_code()) {
DLOG(ERROR) << "Failure parsing XML of XPS capabilities of printer "
<< printer_name