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