| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR < 4) |
| 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) | |
| 33 const int CUPS_PRINTER_SCANNER = 0x2000000; // Scanner-only device | 30 const int CUPS_PRINTER_SCANNER = 0x2000000; // Scanner-only device |
| 34 #endif | 31 #endif |
| 35 | 32 |
| 36 #if !defined(OS_MACOSX) | 33 #if !defined(OS_MACOSX) |
| 37 GCRY_THREAD_OPTION_PTHREAD_IMPL; | 34 GCRY_THREAD_OPTION_PTHREAD_IMPL; |
| 38 | 35 |
| 39 namespace { | 36 namespace { |
| 40 | 37 |
| 41 // Init GCrypt library (needed for CUPS) using pthreads. | 38 // Init GCrypt library (needed for CUPS) using pthreads. |
| 42 // 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: |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 << ", server: " << print_server_url_ | 200 << ", server: " << print_server_url_ |
| 204 << ", # of printers: " << printer_list->size(); | 201 << ", # of printers: " << printer_list->size(); |
| 205 return true; | 202 return true; |
| 206 } | 203 } |
| 207 | 204 |
| 208 std::string PrintBackendCUPS::GetDefaultPrinterName() { | 205 std::string PrintBackendCUPS::GetDefaultPrinterName() { |
| 209 // Not using cupsGetDefault() because it lies about the default printer. | 206 // Not using cupsGetDefault() because it lies about the default printer. |
| 210 cups_dest_t* dests; | 207 cups_dest_t* dests; |
| 211 int num_dests = GetDests(&dests); | 208 int num_dests = GetDests(&dests); |
| 212 cups_dest_t* dest = cupsGetDest(NULL, NULL, num_dests, dests); | 209 cups_dest_t* dest = cupsGetDest(NULL, NULL, num_dests, dests); |
| 213 return dest ? std::string(dest->name) : std::string(); | 210 std::string name = dest ? std::string(dest->name) : std::string(); |
| 211 cupsFreeDests(num_dests, dests); |
| 212 return name; |
| 214 } | 213 } |
| 215 | 214 |
| 216 bool PrintBackendCUPS::GetPrinterSemanticCapsAndDefaults( | 215 bool PrintBackendCUPS::GetPrinterSemanticCapsAndDefaults( |
| 217 const std::string& printer_name, | 216 const std::string& printer_name, |
| 218 PrinterSemanticCapsAndDefaults* printer_info) { | 217 PrinterSemanticCapsAndDefaults* printer_info) { |
| 219 PrinterCapsAndDefaults info; | 218 PrinterCapsAndDefaults info; |
| 220 if (!GetPrinterCapsAndDefaults(printer_name, &info) ) | 219 if (!GetPrinterCapsAndDefaults(printer_name, &info) ) |
| 221 return false; | 220 return false; |
| 222 | 221 |
| 223 return parsePpdCapabilities( | 222 return parsePpdCapabilities( |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 << ", HTTP error: " << http_error; | 366 << ", HTTP error: " << http_error; |
| 368 file_util::Delete(ppd_path, false); | 367 file_util::Delete(ppd_path, false); |
| 369 ppd_path.clear(); | 368 ppd_path.clear(); |
| 370 } | 369 } |
| 371 } | 370 } |
| 372 } | 371 } |
| 373 return ppd_path; | 372 return ppd_path; |
| 374 } | 373 } |
| 375 | 374 |
| 376 } // namespace printing | 375 } // namespace printing |
| OLD | NEW |