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

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
« no previous file with comments | « printing/backend/print_backend_chromeos.cc ('k') | printing/backend/print_backend_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 std::string result;
237 for (int printer_index = 0; printer_index < num_dests; printer_index++) {
238 const cups_dest_t& printer = destinations[printer_index];
239 if (printer_name == printer.name) {
240 const char* info = cupsGetOption(kCUPSPrinterMakeModelOpt,
241 printer.num_options,
242 printer.options);
243 if (info)
244 result = *info;
245 }
246 }
247
248 cupsFreeDests(num_dests, destinations);
249 return result;
235 } 250 }
236 251
237 bool PrintBackendCUPS::IsValidPrinter(const std::string& printer_name) { 252 bool PrintBackendCUPS::IsValidPrinter(const std::string& printer_name) {
238 // This is not very efficient way to get specific printer info. CUPS 1.4 253 // 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 254 // supports cupsGetNamedDest() function. However, CUPS 1.4 is not available
240 // everywhere (for example, it supported from Mac OS 10.6 only). 255 // everywhere (for example, it supported from Mac OS 10.6 only).
241 PrinterList printer_list; 256 PrinterList printer_list;
242 EnumeratePrinters(&printer_list); 257 EnumeratePrinters(&printer_list);
243 258
244 PrinterList::iterator it; 259 PrinterList::iterator it;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 << ", HTTP error: " << http_error; 334 << ", HTTP error: " << http_error;
320 file_util::Delete(ppd_path, false); 335 file_util::Delete(ppd_path, false);
321 ppd_path.clear(); 336 ppd_path.clear();
322 } 337 }
323 } 338 }
324 } 339 }
325 return ppd_path; 340 return ppd_path;
326 } 341 }
327 342
328 } // namespace printing 343 } // namespace printing
OLDNEW
« no previous file with comments | « printing/backend/print_backend_chromeos.cc ('k') | printing/backend/print_backend_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698