Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Side by Side Diff: printing/backend/print_backend_cups_ipp.cc

Issue 2105463002: Create a new print backend for the updated CUPS APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix printing gyp file. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #include "printing/backend/print_backend_cups_ipp.h"
6
7 #include <cups/cups.h>
8 #include <dlfcn.h>
9 #include <errno.h>
10 #include <pthread.h>
11
12 #include <vector>
13
14 #include "base/debug/leak_annotations.h"
15 #include "base/files/file_util.h"
16 #include "base/lazy_instance.h"
17 #include "base/logging.h"
18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_split.h"
20 #include "base/strings/string_util.h"
21 #include "base/synchronization/lock.h"
22 #include "base/values.h"
23 #include "printing/backend/cups_connection.h"
24 #include "printing/backend/cups_ipp_util.h"
25 #include "printing/backend/print_backend_consts.h"
26 #include "printing/units.h"
27 #include "url/gurl.h"
28
29 namespace printing {
30
31 PrintBackendCupsIpp::PrintBackendCupsIpp(CupsConnection&& cups_connection)
32 : cups_connection_(std::move(cups_connection)) {}
33
34 bool PrintBackendCupsIpp::EnumeratePrinters(PrinterList* printer_list) {
35 DCHECK(printer_list);
36 printer_list->clear();
37
38 std::vector<CupsPrinter> printers = cups_connection_.GetDests();
39 if (printers.empty()) {
40 LOG(WARNING) << "CUPS: Error getting printers from CUPS server"
41 << ", server: " << cups_connection_.server_name()
42 << ", error: "
43 << static_cast<int>(cups_connection_.last_error());
44
45 return false;
46 }
47
48 for (const auto& printer : printers) {
49 PrinterBasicInfo basic_info;
50 if (printer.ToPrinterInfo(&basic_info)) {
51 printer_list->push_back(std::move(basic_info));
Lei Zhang 2016/07/13 01:08:43 I don't think the std::move() works here. You stil
skau 2016/07/14 20:43:06 Yes. PrintBasicInfo doesn't have a move construct
52 }
53 }
54
55 return true;
56 }
57
58 std::string PrintBackendCupsIpp::GetDefaultPrinterName() {
59 std::vector<CupsPrinter> printers = cups_connection_.GetDests();
60 for (const auto& printer : printers) {
61 if (printer.is_default()) {
62 return printer.GetName();
63 }
64 }
65
66 return "";
Lei Zhang 2016/07/13 01:08:43 return std::string();
skau 2016/07/14 20:43:06 Done.
67 }
68
69 bool PrintBackendCupsIpp::GetPrinterBasicInfo(const std::string& printer_name,
70 PrinterBasicInfo* printer_info) {
71 std::unique_ptr<CupsPrinter> printer(
72 cups_connection_.GetPrinter(printer_name));
73 if (!printer || !printer->IsAvailable())
74 return false;
75
76 DCHECK_EQ(printer_name, printer->GetName());
77
78 return printer->ToPrinterInfo(printer_info);
79 }
80
81 bool PrintBackendCupsIpp::GetPrinterSemanticCapsAndDefaults(
82 const std::string& printer_name,
83 PrinterSemanticCapsAndDefaults* printer_info) {
84 std::unique_ptr<CupsPrinter> printer(
85 cups_connection_.GetPrinter(printer_name));
86 if (!printer)
87 return false;
88
89 ExtractCollate(*printer, printer_info);
90 ExtractCopies(*printer, printer_info);
91 ExtractDuplex(*printer, printer_info);
92 ExtractColor(*printer, printer_info);
93 ExtractPaper(*printer, printer_info);
94
95 // TODO(skau): Add dpi and default_dpi
96
97 return true;
98 }
99
100 bool PrintBackendCupsIpp::GetPrinterCapsAndDefaults(
101 const std::string& printer_name,
102 PrinterCapsAndDefaults* printer_info) {
103 DCHECK(printer_info);
104
105 // Read the ppd file for Cloud Print. We don't use PPD anymore otherwise.
106 std::unique_ptr<CupsPrinter> printer(
107 cups_connection_.GetPrinter(printer_name));
108 if (!printer)
109 return false;
110
111 base::FilePath ppd_path(printer->GetPPD());
112 // In some cases CUPS failed to get ppd file.
113 if (ppd_path.empty()) {
114 LOG(ERROR) << "CUPS: Failed to get PPD, printer name: " << printer_name;
115 return false;
116 }
117
118 std::string content;
119 bool res = base::ReadFileToString(ppd_path, &content);
120
121 base::DeleteFile(ppd_path, false);
122
123 if (res) {
124 printer_info->printer_capabilities.swap(content);
125 printer_info->caps_mime_type = "application/pagemaker";
126 // In CUPS, printer defaults is a part of PPD file. Nothing to upload here.
127 printer_info->printer_defaults.clear();
128 printer_info->defaults_mime_type.clear();
129 }
130
131 return res;
132 }
133
134 std::string PrintBackendCupsIpp::GetPrinterDriverInfo(
135 const std::string& printer_name) {
136 std::unique_ptr<CupsPrinter> printer(
137 cups_connection_.GetPrinter(printer_name));
138 if (!printer || !printer->IsAvailable())
139 return std::string();
140
141 DCHECK_EQ(printer_name, printer->GetName());
142 return printer->GetMakeAndModel();
143 }
144
145 bool PrintBackendCupsIpp::IsValidPrinter(const std::string& printer_name) {
146 std::unique_ptr<CupsPrinter> printer(
147 cups_connection_.GetPrinter(printer_name));
148 if (!printer)
149 return false;
150
151 return printer->IsAvailable();
152 }
153
154 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698