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 "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> |
11 #include <pthread.h> | 11 #include <pthread.h> |
12 | 12 |
13 #if defined(OS_MACOSX) | 13 #if defined(OS_MACOSX) |
14 #include <AvailabilityMacros.h> | 14 #include <AvailabilityMacros.h> |
15 #else | 15 #else |
16 #include <gcrypt.h> | 16 #include <gcrypt.h> |
17 #endif | 17 #endif |
18 | 18 |
19 #include "base/file_util.h" | 19 #include "base/file_util.h" |
20 #include "base/lazy_instance.h" | 20 #include "base/lazy_instance.h" |
21 #include "base/logging.h" | 21 #include "base/logging.h" |
22 #include "base/string_number_conversions.h" | 22 #include "base/string_number_conversions.h" |
23 #include "base/synchronization/lock.h" | 23 #include "base/synchronization/lock.h" |
24 #include "base/values.h" | 24 #include "base/values.h" |
25 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
26 #include "printing/backend/cups_helper.h" | 26 #include "printing/backend/cups_helper.h" |
27 #include "printing/backend/print_backend_consts.h" | 27 #include "printing/backend/print_backend_consts.h" |
28 | 28 |
29 #if defined(OS_MACOSX) | 29 #if (defined(OS_MACOSX) && \ |
30 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5 | 30 MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5) || \ |
| 31 (defined(OS_LINUX) && \ |
| 32 CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR < 4) |
31 const int CUPS_PRINTER_SCANNER = 0x2000000; // Scanner-only device | 33 const int CUPS_PRINTER_SCANNER = 0x2000000; // Scanner-only device |
32 #endif // MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5 | 34 #endif |
33 #else | 35 |
| 36 #if !defined(OS_MACOSX) |
34 GCRY_THREAD_OPTION_PTHREAD_IMPL; | 37 GCRY_THREAD_OPTION_PTHREAD_IMPL; |
35 | 38 |
36 namespace { | 39 namespace { |
37 | 40 |
38 // Init GCrypt library (needed for CUPS) using pthreads. | 41 // Init GCrypt library (needed for CUPS) using pthreads. |
39 // There exists a bug in CUPS library, where it crashed with: "ath.c:184: | 42 // There exists a bug in CUPS library, where it crashed with: "ath.c:184: |
40 // _gcry_ath_mutex_lock: Assertion `*lock == ((ath_mutex_t) 0)' failed." | 43 // _gcry_ath_mutex_lock: Assertion `*lock == ((ath_mutex_t) 0)' failed." |
41 // It happened when multiple threads tried printing simultaneously. | 44 // It happened when multiple threads tried printing simultaneously. |
42 // Google search for 'gnutls thread safety' provided a solution that | 45 // Google search for 'gnutls thread safety' provided a solution that |
43 // initialized gcrypt and gnutls. | 46 // initialized gcrypt and gnutls. |
(...skipping 29 matching lines...) Expand all Loading... |
73 } | 76 } |
74 if ((*pgnutls_global_init)() != 0) | 77 if ((*pgnutls_global_init)() != 0) |
75 LOG(ERROR) << "Gnutls initialization failed"; | 78 LOG(ERROR) << "Gnutls initialization failed"; |
76 } | 79 } |
77 }; | 80 }; |
78 | 81 |
79 static base::LazyInstance<GcryptInitializer> g_gcrypt_initializer( | 82 static base::LazyInstance<GcryptInitializer> g_gcrypt_initializer( |
80 base::LINKER_INITIALIZED); | 83 base::LINKER_INITIALIZED); |
81 | 84 |
82 } // namespace | 85 } // namespace |
83 #endif // defined(OS_MACOSX) | 86 #endif // !defined(OS_MACOSX) |
84 | 87 |
85 namespace printing { | 88 namespace printing { |
86 | 89 |
87 static const char kCUPSPrinterInfoOpt[] = "printer-info"; | 90 static const char kCUPSPrinterInfoOpt[] = "printer-info"; |
88 static const char kCUPSPrinterStateOpt[] = "printer-state"; | 91 static const char kCUPSPrinterStateOpt[] = "printer-state"; |
89 static const char kCUPSPrinterTypeOpt[] = "printer-type"; | 92 static const char kCUPSPrinterTypeOpt[] = "printer-type"; |
90 | 93 |
91 class PrintBackendCUPS : public PrintBackend { | 94 class PrintBackendCUPS : public PrintBackend { |
92 public: | 95 public: |
93 PrintBackendCUPS(const GURL& print_server_url, bool blocking); | 96 PrintBackendCUPS(const GURL& print_server_url, bool blocking); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 << ", HTTP error: " << http_error; | 301 << ", HTTP error: " << http_error; |
299 file_util::Delete(ppd_path, false); | 302 file_util::Delete(ppd_path, false); |
300 ppd_path.clear(); | 303 ppd_path.clear(); |
301 } | 304 } |
302 } | 305 } |
303 } | 306 } |
304 return ppd_path; | 307 return ppd_path; |
305 } | 308 } |
306 | 309 |
307 } // namespace printing | 310 } // namespace printing |
OLD | NEW |