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

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

Issue 9693064: ScopedPrinterInfoSetter on crash prone blocks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "printing/backend/print_backend.h" 5 #include "printing/backend/print_backend.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <dlfcn.h> 9 #include <dlfcn.h>
10 #include <errno.h> 10 #include <errno.h>
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 LAZY_INSTANCE_INITIALIZER; 91 LAZY_INSTANCE_INITIALIZER;
92 92
93 } // namespace 93 } // namespace
94 #endif // !defined(OS_MACOSX) 94 #endif // !defined(OS_MACOSX)
95 95
96 namespace printing { 96 namespace printing {
97 97
98 static const char kCUPSPrinterInfoOpt[] = "printer-info"; 98 static const char kCUPSPrinterInfoOpt[] = "printer-info";
99 static const char kCUPSPrinterStateOpt[] = "printer-state"; 99 static const char kCUPSPrinterStateOpt[] = "printer-state";
100 static const char kCUPSPrinterTypeOpt[] = "printer-type"; 100 static const char kCUPSPrinterTypeOpt[] = "printer-type";
101 static const char kCUPSPrinterMakeModelOpt[] = "printer-make-and-model";
101 102
102 class PrintBackendCUPS : public PrintBackend { 103 class PrintBackendCUPS : public PrintBackend {
103 public: 104 public:
104 PrintBackendCUPS(const GURL& print_server_url, bool blocking); 105 PrintBackendCUPS(const GURL& print_server_url, bool blocking);
105 virtual ~PrintBackendCUPS() {} 106 virtual ~PrintBackendCUPS() {}
106 107
107 // PrintBackend implementation. 108 // PrintBackend implementation.
108 virtual bool EnumeratePrinters(PrinterList* printer_list) OVERRIDE; 109 virtual bool EnumeratePrinters(PrinterList* printer_list) OVERRIDE;
109 110
110 virtual std::string GetDefaultPrinterName() OVERRIDE; 111 virtual std::string GetDefaultPrinterName() OVERRIDE;
111 112
112 virtual bool GetPrinterCapsAndDefaults( 113 virtual bool GetPrinterCapsAndDefaults(
113 const std::string& printer_name, 114 const std::string& printer_name,
114 PrinterCapsAndDefaults* printer_info) OVERRIDE; 115 PrinterCapsAndDefaults* printer_info) OVERRIDE;
115 116
116 virtual bool GetPrinterDriverInfo(const std::string& printer_name, 117 virtual std::string GetPrinterDriverInfo(
117 std::string* driver_info) OVERRIDE; 118 const std::string& printer_name) OVERRIDE;
118 119
119 virtual bool IsValidPrinter(const std::string& printer_name) OVERRIDE; 120 virtual bool IsValidPrinter(const std::string& printer_name) OVERRIDE;
120 121
121 private: 122 private:
122 // Following functions are wrappers around corresponding CUPS functions. 123 // Following functions are wrappers around corresponding CUPS functions.
123 // <functions>2() are called when print server is specified, and plain 124 // <functions>2() are called when print server is specified, and plain
124 // version in another case. There is an issue specifing CUPS_HTTP_DEFAULT 125 // version in another case. There is an issue specifing CUPS_HTTP_DEFAULT
125 // in the <functions>2(), it does not work in CUPS prior to 1.4. 126 // in the <functions>2(), it does not work in CUPS prior to 1.4.
126 int GetDests(cups_dest_t** dests); 127 int GetDests(cups_dest_t** dests);
127 FilePath GetPPD(const char* name); 128 FilePath GetPPD(const char* name);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 printer_info->printer_capabilities.swap(content); 222 printer_info->printer_capabilities.swap(content);
222 printer_info->caps_mime_type = "application/pagemaker"; 223 printer_info->caps_mime_type = "application/pagemaker";
223 // In CUPS, printer defaults is a part of PPD file. Nothing to upload here. 224 // In CUPS, printer defaults is a part of PPD file. Nothing to upload here.
224 printer_info->printer_defaults.clear(); 225 printer_info->printer_defaults.clear();
225 printer_info->defaults_mime_type.clear(); 226 printer_info->defaults_mime_type.clear();
226 } 227 }
227 228
228 return res; 229 return res;
229 } 230 }
230 231
231 bool PrintBackendCUPS::GetPrinterDriverInfo(const std::string& printer_name, 232 std::string PrintBackendCUPS::GetPrinterDriverInfo(
232 std::string* driver_info) { 233 const std::string& printer_name) {
233 // TODO(vitalybuka): MAC implementation. http://crbug.com/108194 234 cups_dest_t* destinations = NULL;
234 return false; 235 int num_dests = GetDests(&destinations);
236 if ((num_dests == 0) && (cupsLastError() > IPP_OK_EVENTS_COMPLETE)) {
237 VLOG(1) << "CP_CUPS: Error getting printers from CUPS server. Server: "
238 << print_server_url_
239 << " Error: "
240 << static_cast<int>(cupsLastError());
241 return false;
242 }
243
244 std::string result;
245 for (int printer_index = 0; printer_index < num_dests; printer_index++) {
246 const cups_dest_t& printer = destinations[printer_index];
247
248 if (printer_name = printer.name) {
249 const char* info = cupsGetOption(kCUPSPrinterMakeModelOpt, printer.num_opt ions,
Albert Bodenhamer 2012/03/13 23:57:39 80 chars
Vitaly Buka (NO REVIEWS) 2012/03/14 00:11:20 Done.
250 printer.options);
251 if (info)
252 result = *info;
253 }
254 }
255
256 cupsFreeDests(num_dests, destinations);
257 return result;
235 } 258 }
236 259
237 bool PrintBackendCUPS::IsValidPrinter(const std::string& printer_name) { 260 bool PrintBackendCUPS::IsValidPrinter(const std::string& printer_name) {
238 // This is not very efficient way to get specific printer info. CUPS 1.4 261 // This is not very efficient way to get specific printer info. CUPS 1.4
239 // supports cupsGetNamedDest() function. However, CUPS 1.4 is not available 262 // supports cupsGetNamedDest() function. However, CUPS 1.4 is not available
240 // everywhere (for example, it supported from Mac OS 10.6 only). 263 // everywhere (for example, it supported from Mac OS 10.6 only).
241 PrinterList printer_list; 264 PrinterList printer_list;
242 EnumeratePrinters(&printer_list); 265 EnumeratePrinters(&printer_list);
243 266
244 PrinterList::iterator it; 267 PrinterList::iterator it;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 << ", HTTP error: " << http_error; 342 << ", HTTP error: " << http_error;
320 file_util::Delete(ppd_path, false); 343 file_util::Delete(ppd_path, false);
321 ppd_path.clear(); 344 ppd_path.clear();
322 } 345 }
323 } 346 }
324 } 347 }
325 return ppd_path; 348 return ppd_path;
326 } 349 }
327 350
328 } // namespace printing 351 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698