OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <gcrypt.h> | 10 #include <gcrypt.h> |
| 11 #endif |
10 #include <pthread.h> | 12 #include <pthread.h> |
11 | 13 |
12 #include "base/file_util.h" | 14 #include "base/file_util.h" |
13 #include "base/lock.h" | 15 #include "base/lock.h" |
14 #include "base/logging.h" | 16 #include "base/logging.h" |
15 #include "base/singleton.h" | 17 #include "base/singleton.h" |
16 #include "base/string_number_conversions.h" | 18 #include "base/string_number_conversions.h" |
17 #include "base/values.h" | 19 #include "base/values.h" |
18 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
19 #include "printing/backend/cups_helper.h" | 21 #include "printing/backend/cups_helper.h" |
20 | 22 |
| 23 #if !defined(OS_MACOSX) |
21 GCRY_THREAD_OPTION_PTHREAD_IMPL; | 24 GCRY_THREAD_OPTION_PTHREAD_IMPL; |
22 | 25 |
23 namespace { | 26 namespace { |
24 | 27 |
25 // Init GCrypt library (needed for CUPS) using pthreads. | 28 // Init GCrypt library (needed for CUPS) using pthreads. |
26 // There exists a bug in CUPS library, where it crashed with: "ath.c:184: | 29 // There exists a bug in CUPS library, where it crashed with: "ath.c:184: |
27 // _gcry_ath_mutex_lock: Assertion `*lock == ((ath_mutex_t) 0)' failed." | 30 // _gcry_ath_mutex_lock: Assertion `*lock == ((ath_mutex_t) 0)' failed." |
28 // It happened when multiple threads tried printing simultaneously. | 31 // It happened when multiple threads tried printing simultaneously. |
29 // Google search for 'gnutls thread safety' provided a solution that | 32 // Google search for 'gnutls thread safety' provided a solution that |
30 // initialized gcrypt and gnutls. | 33 // initialized gcrypt and gnutls. |
(...skipping 26 matching lines...) Expand all Loading... |
57 LOG(ERROR) << "Could not find " << kGnuTlsInitFuncName | 60 LOG(ERROR) << "Could not find " << kGnuTlsInitFuncName |
58 << " in " << kGnuTlsFile; | 61 << " in " << kGnuTlsFile; |
59 return; | 62 return; |
60 } | 63 } |
61 if ((*pgnutls_global_init)() != 0) | 64 if ((*pgnutls_global_init)() != 0) |
62 LOG(ERROR) << "Gnutls initialization failed"; | 65 LOG(ERROR) << "Gnutls initialization failed"; |
63 } | 66 } |
64 }; | 67 }; |
65 | 68 |
66 } // namespace | 69 } // namespace |
| 70 #endif |
67 | 71 |
68 namespace printing { | 72 namespace printing { |
69 | 73 |
70 static const char kCUPSPrinterInfoOpt[] = "printer-info"; | 74 static const char kCUPSPrinterInfoOpt[] = "printer-info"; |
71 static const char kCUPSPrinterStateOpt[] = "printer-state"; | 75 static const char kCUPSPrinterStateOpt[] = "printer-state"; |
72 static const char kCUPSPrintServerURL[] = "print_server_url"; | 76 static const char kCUPSPrintServerURL[] = "print_server_url"; |
73 | 77 |
74 class PrintBackendCUPS : public PrintBackend { | 78 class PrintBackendCUPS : public PrintBackend { |
75 public: | 79 public: |
76 explicit PrintBackendCUPS(const GURL& print_server_url); | 80 explicit PrintBackendCUPS(const GURL& print_server_url); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 179 |
176 PrinterList::iterator it; | 180 PrinterList::iterator it; |
177 for (it = printer_list.begin(); it != printer_list.end(); ++it) | 181 for (it = printer_list.begin(); it != printer_list.end(); ++it) |
178 if (it->printer_name == printer_name) | 182 if (it->printer_name == printer_name) |
179 return true; | 183 return true; |
180 return false; | 184 return false; |
181 } | 185 } |
182 | 186 |
183 scoped_refptr<PrintBackend> PrintBackend::CreateInstance( | 187 scoped_refptr<PrintBackend> PrintBackend::CreateInstance( |
184 const DictionaryValue* print_backend_settings) { | 188 const DictionaryValue* print_backend_settings) { |
| 189 #if !defined(OS_MACOSX) |
185 // Initialize gcrypt library. | 190 // Initialize gcrypt library. |
186 Singleton<GcryptInitializer>::get(); | 191 Singleton<GcryptInitializer>::get(); |
| 192 #endif |
187 | 193 |
188 std::string print_server_url_str; | 194 std::string print_server_url_str; |
189 if (print_backend_settings) { | 195 if (print_backend_settings) { |
190 print_backend_settings->GetString(kCUPSPrintServerURL, | 196 print_backend_settings->GetString(kCUPSPrintServerURL, |
191 &print_server_url_str); | 197 &print_server_url_str); |
192 } | 198 } |
193 GURL print_server_url(print_server_url_str.c_str()); | 199 GURL print_server_url(print_server_url_str.c_str()); |
194 return new PrintBackendCUPS(print_server_url); | 200 return new PrintBackendCUPS(print_server_url); |
195 } | 201 } |
196 | 202 |
(...skipping 18 matching lines...) Expand all Loading... |
215 } else { | 221 } else { |
216 HttpConnectionCUPS http(print_server_url_); | 222 HttpConnectionCUPS http(print_server_url_); |
217 ppd_file_path = cupsGetPPD2(http.http(), name); | 223 ppd_file_path = cupsGetPPD2(http.http(), name); |
218 } | 224 } |
219 if (ppd_file_path) | 225 if (ppd_file_path) |
220 ppd_path = FilePath(ppd_file_path); | 226 ppd_path = FilePath(ppd_file_path); |
221 return ppd_path; | 227 return ppd_path; |
222 } | 228 } |
223 | 229 |
224 } // namespace printing | 230 } // namespace printing |
OLD | NEW |