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