Index: printing/backend/cups_printer.h |
diff --git a/printing/backend/cups_printer.h b/printing/backend/cups_printer.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9bf6c8504f74012b1674105dcd6992cac90663bb |
--- /dev/null |
+++ b/printing/backend/cups_printer.h |
@@ -0,0 +1,128 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef PRINTING_BACKEND_CUPS_PRINTER_H_ |
+#define PRINTING_BACKEND_CUPS_PRINTER_H_ |
+ |
+#include <cups/cups.h> |
+ |
+#include <memory> |
+#include <string> |
+#include <vector> |
+ |
+#include "printing/backend/cups_deleters.h" |
+#include "printing/printing_export.h" |
+#include "url/gurl.h" |
+ |
+namespace base { |
+class FilePath; |
+} |
+ |
+namespace printing { |
+ |
+struct PrinterBasicInfo; |
+ |
+// Provides information regarding cups options. |
+class PRINTING_EXPORT CupsOptionProvider { |
+ public: |
+ virtual ~CupsOptionProvider() = default; |
+ |
+ // Returns the supported ipp attributes for the given |option_name|. |
+ // ipp_attribute_t* is owned by CupsOptionProvider. |
+ virtual ipp_attribute_t* GetSupportedOptionValues( |
+ base::StringPiece option_name) const = 0; |
+ |
+ // Returns supported attribute values for |option_name| where the value can be |
+ // convered to a string. |
+ virtual std::vector<base::StringPiece> GetSupportedOptionValueStrings( |
+ base::StringPiece option_name) const = 0; |
+ |
+ // Returns the default ipp attributes for the given |option_name|. |
+ // ipp_attribute_t* is owned by CupsOptionProvider. |
+ virtual ipp_attribute_t* GetDefaultOptionValue( |
+ base::StringPiece option_name) const = 0; |
+ |
+ // Returns true if the |value| is supported by option |name|. |
+ virtual bool CheckOptionSupported(base::StringPiece name, |
+ base::StringPiece value) const = 0; |
+}; |
+ |
+// Represents a CUPS printer. |
+// Retrieves information from CUPS printer objects as requested. This class |
+// is only valid as long as the CupsConnection which created it exists as they |
+// share an http connection which the CupsConnection closes on destruction. |
+class PRINTING_EXPORT CupsPrinter : public CupsOptionProvider { |
+ public: |
+ // This object now owns |dest| and |info|. |
Lei Zhang
2016/07/21 00:46:20
No need to explain std::unique_ptr semantics.
skau
2016/07/21 20:07:34
Done.
|
+ CupsPrinter(http_t* http, |
+ std::unique_ptr<cups_dest_t, DestinationDeleter> dest, |
+ std::unique_ptr<cups_dinfo_t, DestInfoDeleter> info); |
+ |
+ CupsPrinter(CupsPrinter&& printer); |
+ |
+ ~CupsPrinter() override; |
+ |
+ // Returns true if this is the default printer |
+ bool is_default() const; |
+ |
+ ipp_attribute_t* GetSupportedOptionValues( |
Lei Zhang
2016/07/21 00:46:20
Bunch up all the overrides:
// CupsOptionProvider
skau
2016/07/21 20:07:33
Done.
|
+ base::StringPiece option_name) const override; |
+ |
+ std::vector<base::StringPiece> GetSupportedOptionValueStrings( |
+ base::StringPiece option_name) const override; |
+ |
+ ipp_attribute_t* GetDefaultOptionValue( |
+ base::StringPiece option_name) const override; |
+ |
+ bool CheckOptionSupported(base::StringPiece name, |
+ base::StringPiece value) const override; |
+ |
+ // Returns the file name for the PPD retrieved from the print server. |
+ base::FilePath GetPPD() const; |
+ |
+ // Returns the name of the printer as configured in CUPS |
+ const std::string GetName() const; |
Lei Zhang
2016/07/21 00:46:20
If you are returning a copy of the string, there's
skau
2016/07/21 20:07:33
Done.
|
+ |
+ const std::string GetMakeAndModel() const; |
+ |
+ // Returns true if the printer is currently reachable and working. |
+ bool IsAvailable() const; |
+ |
+ // Populates |basic_info| with the relevant information about the printer |
+ bool ToPrinterInfo(PrinterBasicInfo* basic_info) const; |
+ |
+ ipp_status_t CreateJob(int* job_id, |
+ base::StringPiece job_title, |
+ const std::vector<cups_option_t>& options); |
+ |
+ bool StartDocument(int job_id, |
+ base::StringPiece document_name, |
+ bool last_doc, |
+ const std::vector<cups_option_t>& options); |
+ |
+ bool StreamData(const std::vector<char>& buffer); |
+ |
+ bool FinishDocument(); |
+ |
+ ipp_status_t CloseJob(int job_id); |
+ |
+ private: |
+ // Lazily initialize dest info as it can require a network call |
+ bool InitializeDestInfo() const; |
+ |
+ // http connection owned by the CupsConnection which created this object |
+ http_t* cups_http_; |
Lei Zhang
2016/07/21 00:46:20
This can be: http_t* const cups_http_; since the p
skau
2016/07/21 20:07:33
Done.
|
+ |
+ // information to identify a printer |
+ std::unique_ptr<cups_dest_t, DestinationDeleter> destination_; |
+ |
+ // opaque object containing printer attributes and options |
+ mutable std::unique_ptr<cups_dinfo_t, DestInfoDeleter> dest_info_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(CupsPrinter); |
+}; |
+ |
+} // namespace printing |
+ |
+#endif // PRINTING_BACKEND_CUPS_PRINTER_H_ |