Commit 7d12c3fa authored by Vladislav Kuzkokov's avatar Vladislav Kuzkokov Committed by Commit Bot

[CrOS Printing] Unify CUPS deleters usage.

Declare std::unique_ptr specializations for CUPS in one place.

Change-Id: Iffa00a1cfb4167ff4b46fdbffcfd4c367ffe1ac5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1782880
Auto-Submit: Vladislav Kuzkokov <vkuzkokov@chromium.org>
Reviewed-by: default avatarSean Kau <skau@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695683}
parent f5dfdfc6
......@@ -47,12 +47,10 @@ class DestinationEnumerator {
void store_dest(cups_dest_t* dest) { dests_.emplace_back(dest); }
// Returns the collected destinations.
std::vector<std::unique_ptr<cups_dest_t, DestinationDeleter>>& get_dests() {
return dests_;
}
std::vector<ScopedDestination>& get_dests() { return dests_; }
private:
std::vector<std::unique_ptr<cups_dest_t, DestinationDeleter>> dests_;
std::vector<ScopedDestination> dests_;
DISALLOW_COPY_AND_ASSIGN(DestinationEnumerator);
};
......@@ -139,8 +137,8 @@ std::unique_ptr<CupsPrinter> CupsConnection::GetPrinter(
if (!dest)
return nullptr;
return std::make_unique<CupsPrinter>(
cups_http_.get(), std::unique_ptr<cups_dest_t, DestinationDeleter>(dest));
return std::make_unique<CupsPrinter>(cups_http_.get(),
ScopedDestination(dest));
}
bool CupsConnection::GetJobs(const std::vector<std::string>& printer_ids,
......
......@@ -67,7 +67,7 @@ class PRINTING_EXPORT CupsConnection {
http_encryption_t cups_encryption_;
bool blocking_;
std::unique_ptr<http_t, HttpDeleter> cups_http_;
ScopedHttpPtr cups_http_;
DISALLOW_COPY_AND_ASSIGN(CupsConnection);
};
......
......@@ -23,10 +23,4 @@ void OptionDeleter::operator()(cups_option_t* option) const {
cupsFreeOptions(1, option);
}
JobsDeleter::JobsDeleter(int num_jobs) : num_jobs_(num_jobs) {}
void JobsDeleter::operator()(cups_job_t* jobs) const {
cupsFreeJobs(num_jobs_, jobs);
}
} // namespace printing
......@@ -6,8 +6,7 @@
#define PRINTING_BACKEND_CUPS_DELETERS_H_
#include <cups/cups.h>
#include "base/macros.h"
#include <memory>
namespace printing {
......@@ -27,16 +26,10 @@ struct OptionDeleter {
void operator()(cups_option_t* option) const;
};
class JobsDeleter {
public:
explicit JobsDeleter(int num_jobs);
void operator()(cups_job_t* jobs) const;
private:
int num_jobs_;
DISALLOW_COPY_AND_ASSIGN(JobsDeleter);
};
using ScopedHttpPtr = std::unique_ptr<http_t, HttpDeleter>;
using ScopedDestination = std::unique_ptr<cups_dest_t, DestinationDeleter>;
using ScopedDestInfo = std::unique_ptr<cups_dinfo_t, DestInfoDeleter>;
using ScopedCupsOption = std::unique_ptr<cups_option_t, OptionDeleter>;
} // namespace printing
......
......@@ -114,8 +114,6 @@ constexpr std::array<const char* const, 5> kPrinterInfo{
{kPrinterMakeAndModel, kIppVersionsSupported, kIppFeaturesSupported,
kDocumentFormatSupported, kPwgRasterDocumentResolutionSupported}};
using ScopedHttpPtr = std::unique_ptr<http_t, HttpDeleter>;
// Converts an IPP attribute |attr| to the appropriate JobState enum.
CupsJob::JobState ToJobState(ipp_attribute_t* attr) {
DCHECK_EQ(IPP_TAG_ENUM, ippGetValueTag(attr));
......
......@@ -23,8 +23,7 @@ const char kCUPSPrinterStateOpt[] = "printer-state";
namespace printing {
CupsPrinter::CupsPrinter(http_t* http,
std::unique_ptr<cups_dest_t, DestinationDeleter> dest)
CupsPrinter::CupsPrinter(http_t* http, ScopedDestination dest)
: cups_http_(http), destination_(std::move(dest)) {
DCHECK(cups_http_);
DCHECK(destination_);
......
......@@ -51,8 +51,7 @@ class PRINTING_EXPORT CupsOptionProvider {
class PRINTING_EXPORT CupsPrinter : public CupsOptionProvider {
public:
// Create a printer with a connection defined by |http| and |dest|.
CupsPrinter(http_t* http,
std::unique_ptr<cups_dest_t, DestinationDeleter> dest);
CupsPrinter(http_t* http, ScopedDestination dest);
CupsPrinter(CupsPrinter&& printer);
......@@ -126,10 +125,10 @@ class PRINTING_EXPORT CupsPrinter : public CupsOptionProvider {
http_t* const cups_http_;
// information to identify a printer
std::unique_ptr<cups_dest_t, DestinationDeleter> destination_;
ScopedDestination destination_;
// opaque object containing printer attributes and options
mutable std::unique_ptr<cups_dinfo_t, DestInfoDeleter> dest_info_;
mutable ScopedDestInfo dest_info_;
DISALLOW_COPY_AND_ASSIGN(CupsPrinter);
};
......
......@@ -29,8 +29,6 @@ namespace printing {
namespace {
using ScopedCupsOption = std::unique_ptr<cups_option_t, OptionDeleter>;
// convert from a ColorMode setting to a print-color-mode value from PWG 5100.13
const char* GetColorModelForMode(int color_mode) {
const char* mode_string;
......
......@@ -11,6 +11,7 @@
#include "base/macros.h"
#include "printing/backend/cups_connection.h"
#include "printing/backend/cups_deleters.h"
#include "printing/backend/cups_printer.h"
#include "printing/printing_context.h"
......@@ -42,8 +43,6 @@ class PRINTING_EXPORT PrintingContextChromeos : public PrintingContext {
Result StreamData(const std::vector<char>& buffer);
private:
using ScopedCupsOption = std::unique_ptr<cups_option_t, OptionDeleter>;
// Lazily initializes |printer_|.
Result InitializeDevice(const std::string& device);
......
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