OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef PRINTING_BACKEND_CUPS_PRINTER_H_ | |
6 #define PRINTING_BACKEND_CUPS_PRINTER_H_ | |
7 | |
8 #include <cups/cups.h> | |
9 | |
10 #include <memory> | |
11 #include <string> | |
12 #include <vector> | |
13 | |
14 #include "printing/backend/cups_deleters.h" | |
15 #include "printing/printing_export.h" | |
16 #include "url/gurl.h" | |
17 | |
18 namespace base { | |
19 class FilePath; | |
20 } | |
21 | |
22 namespace printing { | |
23 | |
24 struct PrinterBasicInfo; | |
25 | |
26 // Provides information regarding cups options. | |
27 class PRINTING_EXPORT CupsOptionProvider { | |
28 public: | |
29 virtual ~CupsOptionProvider() = default; | |
30 | |
31 // Returns the supported ipp attributes for the given |option_name|. | |
32 // ipp_attribute_t* is owned by CupsOptionProvider. | |
33 virtual ipp_attribute_t* GetSupportedOptionValues( | |
34 base::StringPiece option_name) const = 0; | |
35 | |
36 // Returns supported attribute values for |option_name| where the value can be | |
37 // convered to a string. | |
38 virtual std::vector<base::StringPiece> GetSupportedOptionValueStrings( | |
39 base::StringPiece option_name) const = 0; | |
40 | |
41 // Returns the default ipp attributes for the given |option_name|. | |
42 // ipp_attribute_t* is owned by CupsOptionProvider. | |
43 virtual ipp_attribute_t* GetDefaultOptionValue( | |
44 base::StringPiece option_name) const = 0; | |
45 | |
46 // Returns true if the |value| is supported by option |name|. | |
47 virtual bool CheckOptionSupported(base::StringPiece name, | |
48 base::StringPiece value) const = 0; | |
49 }; | |
50 | |
51 // Represents a CUPS printer. | |
52 // Retrieves information from CUPS printer objects as requested. This class | |
53 // is only valid as long as the CupsConnection which created it exists as they | |
54 // share an http connection which the CupsConnection closes on destruction. | |
55 class PRINTING_EXPORT CupsPrinter : public CupsOptionProvider { | |
56 public: | |
57 // 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.
| |
58 CupsPrinter(http_t* http, | |
59 std::unique_ptr<cups_dest_t, DestinationDeleter> dest, | |
60 std::unique_ptr<cups_dinfo_t, DestInfoDeleter> info); | |
61 | |
62 CupsPrinter(CupsPrinter&& printer); | |
63 | |
64 ~CupsPrinter() override; | |
65 | |
66 // Returns true if this is the default printer | |
67 bool is_default() const; | |
68 | |
69 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.
| |
70 base::StringPiece option_name) const override; | |
71 | |
72 std::vector<base::StringPiece> GetSupportedOptionValueStrings( | |
73 base::StringPiece option_name) const override; | |
74 | |
75 ipp_attribute_t* GetDefaultOptionValue( | |
76 base::StringPiece option_name) const override; | |
77 | |
78 bool CheckOptionSupported(base::StringPiece name, | |
79 base::StringPiece value) const override; | |
80 | |
81 // Returns the file name for the PPD retrieved from the print server. | |
82 base::FilePath GetPPD() const; | |
83 | |
84 // Returns the name of the printer as configured in CUPS | |
85 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.
| |
86 | |
87 const std::string GetMakeAndModel() const; | |
88 | |
89 // Returns true if the printer is currently reachable and working. | |
90 bool IsAvailable() const; | |
91 | |
92 // Populates |basic_info| with the relevant information about the printer | |
93 bool ToPrinterInfo(PrinterBasicInfo* basic_info) const; | |
94 | |
95 ipp_status_t CreateJob(int* job_id, | |
96 base::StringPiece job_title, | |
97 const std::vector<cups_option_t>& options); | |
98 | |
99 bool StartDocument(int job_id, | |
100 base::StringPiece document_name, | |
101 bool last_doc, | |
102 const std::vector<cups_option_t>& options); | |
103 | |
104 bool StreamData(const std::vector<char>& buffer); | |
105 | |
106 bool FinishDocument(); | |
107 | |
108 ipp_status_t CloseJob(int job_id); | |
109 | |
110 private: | |
111 // Lazily initialize dest info as it can require a network call | |
112 bool InitializeDestInfo() const; | |
113 | |
114 // http connection owned by the CupsConnection which created this object | |
115 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.
| |
116 | |
117 // information to identify a printer | |
118 std::unique_ptr<cups_dest_t, DestinationDeleter> destination_; | |
119 | |
120 // opaque object containing printer attributes and options | |
121 mutable std::unique_ptr<cups_dinfo_t, DestInfoDeleter> dest_info_; | |
122 | |
123 DISALLOW_COPY_AND_ASSIGN(CupsPrinter); | |
124 }; | |
125 | |
126 } // namespace printing | |
127 | |
128 #endif // PRINTING_BACKEND_CUPS_PRINTER_H_ | |
OLD | NEW |