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

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

Issue 7569028: CUPS printing: Do not add scanners to the printer list. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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 | « no previous file | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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"
8
7 #include <dlfcn.h> 9 #include <dlfcn.h>
8 #include <errno.h> 10 #include <errno.h>
9 #if !defined(OS_MACOSX) 11 #include <pthread.h>
12
13 #if defined(OS_MACOSX)
14 #include <AvailabilityMacros.h>
15 #else
10 #include <gcrypt.h> 16 #include <gcrypt.h>
11 #endif 17 #endif
12 #include <pthread.h>
13 18
14 #include "base/file_util.h" 19 #include "base/file_util.h"
15 #include "base/lazy_instance.h" 20 #include "base/lazy_instance.h"
16 #include "base/logging.h" 21 #include "base/logging.h"
17 #include "base/string_number_conversions.h" 22 #include "base/string_number_conversions.h"
18 #include "base/synchronization/lock.h" 23 #include "base/synchronization/lock.h"
19 #include "base/values.h" 24 #include "base/values.h"
20 #include "googleurl/src/gurl.h" 25 #include "googleurl/src/gurl.h"
21 #include "printing/backend/cups_helper.h" 26 #include "printing/backend/cups_helper.h"
22 #include "printing/backend/print_backend_consts.h" 27 #include "printing/backend/print_backend_consts.h"
23 28
24 #if !defined(OS_MACOSX) 29 #if defined(OS_MACOSX)
30 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5
31 const int CUPS_PRINTER_SCANNER = 0x2000000; // Scanner-only device
32 #endif // MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5
33 #else
25 GCRY_THREAD_OPTION_PTHREAD_IMPL; 34 GCRY_THREAD_OPTION_PTHREAD_IMPL;
26 35
27 namespace { 36 namespace {
28 37
29 // Init GCrypt library (needed for CUPS) using pthreads. 38 // Init GCrypt library (needed for CUPS) using pthreads.
30 // There exists a bug in CUPS library, where it crashed with: "ath.c:184: 39 // There exists a bug in CUPS library, where it crashed with: "ath.c:184:
31 // _gcry_ath_mutex_lock: Assertion `*lock == ((ath_mutex_t) 0)' failed." 40 // _gcry_ath_mutex_lock: Assertion `*lock == ((ath_mutex_t) 0)' failed."
32 // It happened when multiple threads tried printing simultaneously. 41 // It happened when multiple threads tried printing simultaneously.
33 // Google search for 'gnutls thread safety' provided a solution that 42 // Google search for 'gnutls thread safety' provided a solution that
34 // initialized gcrypt and gnutls. 43 // initialized gcrypt and gnutls.
(...skipping 29 matching lines...) Expand all
64 } 73 }
65 if ((*pgnutls_global_init)() != 0) 74 if ((*pgnutls_global_init)() != 0)
66 LOG(ERROR) << "Gnutls initialization failed"; 75 LOG(ERROR) << "Gnutls initialization failed";
67 } 76 }
68 }; 77 };
69 78
70 static base::LazyInstance<GcryptInitializer> g_gcrypt_initializer( 79 static base::LazyInstance<GcryptInitializer> g_gcrypt_initializer(
71 base::LINKER_INITIALIZED); 80 base::LINKER_INITIALIZED);
72 81
73 } // namespace 82 } // namespace
74 #endif 83 #endif // defined(OS_MACOSX)
75 84
76 namespace printing { 85 namespace printing {
77 86
78 static const char kCUPSPrinterInfoOpt[] = "printer-info"; 87 static const char kCUPSPrinterInfoOpt[] = "printer-info";
79 static const char kCUPSPrinterStateOpt[] = "printer-state"; 88 static const char kCUPSPrinterStateOpt[] = "printer-state";
89 static const char kCUPSPrinterTypeOpt[] = "printer-type";
80 90
81 class PrintBackendCUPS : public PrintBackend { 91 class PrintBackendCUPS : public PrintBackend {
82 public: 92 public:
83 PrintBackendCUPS(const GURL& print_server_url, bool blocking); 93 PrintBackendCUPS(const GURL& print_server_url, bool blocking);
84 virtual ~PrintBackendCUPS() {} 94 virtual ~PrintBackendCUPS() {}
85 95
86 // PrintBackend implementation. 96 // PrintBackend implementation.
87 virtual bool EnumeratePrinters(PrinterList* printer_list); 97 virtual bool EnumeratePrinters(PrinterList* printer_list);
88 98
89 virtual std::string GetDefaultPrinterName(); 99 virtual std::string GetDefaultPrinterName();
(...skipping 29 matching lines...) Expand all
119 VLOG(1) << "CP_CUPS: Error getting printers from CUPS server. Server: " 129 VLOG(1) << "CP_CUPS: Error getting printers from CUPS server. Server: "
120 << print_server_url_ 130 << print_server_url_
121 << " Error: " 131 << " Error: "
122 << static_cast<int>(cupsLastError()); 132 << static_cast<int>(cupsLastError());
123 return false; 133 return false;
124 } 134 }
125 135
126 for (int printer_index = 0; printer_index < num_dests; printer_index++) { 136 for (int printer_index = 0; printer_index < num_dests; printer_index++) {
127 const cups_dest_t& printer = destinations[printer_index]; 137 const cups_dest_t& printer = destinations[printer_index];
128 138
139 // CUPS can have 'printers' that are actually scanners. (not MFC)
140 // At least on Mac. Check for scanners and skip them.
141 const char* type_str = cupsGetOption(kCUPSPrinterTypeOpt,
142 printer.num_options, printer.options);
143 if (type_str != NULL) {
144 int type;
145 if (base::StringToInt(type_str, &type) && (type & CUPS_PRINTER_SCANNER))
146 continue;
147 }
148
129 PrinterBasicInfo printer_info; 149 PrinterBasicInfo printer_info;
130 printer_info.printer_name = printer.name; 150 printer_info.printer_name = printer.name;
131 printer_info.is_default = printer.is_default; 151 printer_info.is_default = printer.is_default;
132 152
133 const char* info = cupsGetOption(kCUPSPrinterInfoOpt, 153 const char* info = cupsGetOption(kCUPSPrinterInfoOpt,
134 printer.num_options, printer.options); 154 printer.num_options, printer.options);
135 if (info != NULL) 155 if (info != NULL)
136 printer_info.printer_description = info; 156 printer_info.printer_description = info;
137 157
138 const char* state = cupsGetOption(kCUPSPrinterStateOpt, 158 const char* state = cupsGetOption(kCUPSPrinterStateOpt,
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 << ", HTTP error: " << http_error; 298 << ", HTTP error: " << http_error;
279 file_util::Delete(ppd_path, false); 299 file_util::Delete(ppd_path, false);
280 ppd_path.clear(); 300 ppd_path.clear();
281 } 301 }
282 } 302 }
283 } 303 }
284 return ppd_path; 304 return ppd_path;
285 } 305 }
286 306
287 } // namespace printing 307 } // namespace printing
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698