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/string_split.h" | |
Lei Zhang
2012/09/05 00:32:32
not sure why these got added here.
gene
2012/09/05 21:04:10
Good catch, thanks!
I initially moved ppd parsing
| |
24 #include "base/string_util.h" | |
23 #include "base/synchronization/lock.h" | 25 #include "base/synchronization/lock.h" |
24 #include "base/values.h" | 26 #include "base/values.h" |
25 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
26 #include "printing/backend/cups_helper.h" | 28 #include "printing/backend/cups_helper.h" |
27 #include "printing/backend/print_backend_consts.h" | 29 #include "printing/backend/print_backend_consts.h" |
28 | 30 |
29 #if (defined(OS_MACOSX) && \ | 31 #if (defined(OS_MACOSX) && \ |
30 MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5) || \ | 32 MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5) || \ |
31 (defined(OS_LINUX) && \ | 33 (defined(OS_LINUX) && \ |
32 CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR < 4) | 34 CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR < 4) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 static const char kCUPSPrinterMakeModelOpt[] = "printer-make-and-model"; | 103 static const char kCUPSPrinterMakeModelOpt[] = "printer-make-and-model"; |
102 | 104 |
103 class PrintBackendCUPS : public PrintBackend { | 105 class PrintBackendCUPS : public PrintBackend { |
104 public: | 106 public: |
105 PrintBackendCUPS(const GURL& print_server_url, | 107 PrintBackendCUPS(const GURL& print_server_url, |
106 http_encryption_t encryption, bool blocking); | 108 http_encryption_t encryption, bool blocking); |
107 | 109 |
108 // PrintBackend implementation. | 110 // PrintBackend implementation. |
109 virtual bool EnumeratePrinters(PrinterList* printer_list) OVERRIDE; | 111 virtual bool EnumeratePrinters(PrinterList* printer_list) OVERRIDE; |
110 virtual std::string GetDefaultPrinterName() OVERRIDE; | 112 virtual std::string GetDefaultPrinterName() OVERRIDE; |
113 virtual bool GetPrinterSemanticCapsAndDefaults( | |
114 const std::string& printer_name, | |
115 PrinterSemanticCapsAndDefaults* printer_info) OVERRIDE; | |
111 virtual bool GetPrinterCapsAndDefaults( | 116 virtual bool GetPrinterCapsAndDefaults( |
112 const std::string& printer_name, | 117 const std::string& printer_name, |
113 PrinterCapsAndDefaults* printer_info) OVERRIDE; | 118 PrinterCapsAndDefaults* printer_info) OVERRIDE; |
114 virtual std::string GetPrinterDriverInfo( | 119 virtual std::string GetPrinterDriverInfo( |
115 const std::string& printer_name) OVERRIDE; | 120 const std::string& printer_name) OVERRIDE; |
116 virtual bool IsValidPrinter(const std::string& printer_name) OVERRIDE; | 121 virtual bool IsValidPrinter(const std::string& printer_name) OVERRIDE; |
117 | 122 |
118 protected: | 123 protected: |
119 virtual ~PrintBackendCUPS() {} | 124 virtual ~PrintBackendCUPS() {} |
120 | 125 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 } | 208 } |
204 | 209 |
205 std::string PrintBackendCUPS::GetDefaultPrinterName() { | 210 std::string PrintBackendCUPS::GetDefaultPrinterName() { |
206 // Not using cupsGetDefault() because it lies about the default printer. | 211 // Not using cupsGetDefault() because it lies about the default printer. |
207 cups_dest_t* dests; | 212 cups_dest_t* dests; |
208 int num_dests = GetDests(&dests); | 213 int num_dests = GetDests(&dests); |
209 cups_dest_t* dest = cupsGetDest(NULL, NULL, num_dests, dests); | 214 cups_dest_t* dest = cupsGetDest(NULL, NULL, num_dests, dests); |
210 return dest ? std::string(dest->name) : std::string(); | 215 return dest ? std::string(dest->name) : std::string(); |
211 } | 216 } |
212 | 217 |
218 bool PrintBackendCUPS::GetPrinterSemanticCapsAndDefaults( | |
219 const std::string& printer_name, | |
220 PrinterSemanticCapsAndDefaults* printer_info) { | |
221 PrinterCapsAndDefaults info; | |
222 if (!GetPrinterCapsAndDefaults(printer_name, &info) ) | |
223 return false; | |
224 | |
225 return parsePpdCapabilities( | |
226 printer_name, info.printer_capabilities, printer_info); | |
227 } | |
228 | |
213 bool PrintBackendCUPS::GetPrinterCapsAndDefaults( | 229 bool PrintBackendCUPS::GetPrinterCapsAndDefaults( |
214 const std::string& printer_name, | 230 const std::string& printer_name, |
215 PrinterCapsAndDefaults* printer_info) { | 231 PrinterCapsAndDefaults* printer_info) { |
216 DCHECK(printer_info); | 232 DCHECK(printer_info); |
217 | 233 |
218 VLOG(1) << "CUPS: Getting caps and defaults" | 234 VLOG(1) << "CUPS: Getting caps and defaults" |
219 << ", printer name: " << printer_name; | 235 << ", printer name: " << printer_name; |
220 | 236 |
221 FilePath ppd_path(GetPPD(printer_name.c_str())); | 237 FilePath ppd_path(GetPPD(printer_name.c_str())); |
222 // In some cases CUPS failed to get ppd file. | 238 // In some cases CUPS failed to get ppd file. |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 << ", HTTP error: " << http_error; | 369 << ", HTTP error: " << http_error; |
354 file_util::Delete(ppd_path, false); | 370 file_util::Delete(ppd_path, false); |
355 ppd_path.clear(); | 371 ppd_path.clear(); |
356 } | 372 } |
357 } | 373 } |
358 } | 374 } |
359 return ppd_path; | 375 return ppd_path; |
360 } | 376 } |
361 | 377 |
362 } // namespace printing | 378 } // namespace printing |
OLD | NEW |