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 "chrome/service/cloud_print/print_system.h" | 5 #include "chrome/service/cloud_print/print_system.h" |
6 | 6 |
7 #include <cups/cups.h> | 7 #include <cups/cups.h> |
8 #include <dlfcn.h> | 8 #include <dlfcn.h> |
9 #include <errno.h> | 9 #include <errno.h> |
10 #include <pthread.h> | 10 #include <pthread.h> |
(...skipping 27 matching lines...) Expand all Loading... |
38 namespace { | 38 namespace { |
39 | 39 |
40 // CUPS specific options. | 40 // CUPS specific options. |
41 const char kCUPSPrinterInfoOpt[] = "printer-info"; | 41 const char kCUPSPrinterInfoOpt[] = "printer-info"; |
42 const char kCUPSPrinterStateOpt[] = "printer-state"; | 42 const char kCUPSPrinterStateOpt[] = "printer-state"; |
43 | 43 |
44 // Print system config options. | 44 // Print system config options. |
45 const char kCUPSPrintServerURLs[] = "print_server_urls"; | 45 const char kCUPSPrintServerURLs[] = "print_server_urls"; |
46 const char kCUPSUpdateTimeoutMs[] = "update_timeout_ms"; | 46 const char kCUPSUpdateTimeoutMs[] = "update_timeout_ms"; |
47 const char kCUPSNotifyDelete[] = "notify_delete"; | 47 const char kCUPSNotifyDelete[] = "notify_delete"; |
| 48 const char kCUPSSupportedMimeTipes[] = "supported_mime_types"; |
| 49 |
| 50 // Default mime types supported by CUPS |
| 51 // http://www.cups.org/articles.php?L205+TFAQ+Q |
| 52 const char kCUPSDefaultSupportedTypes[] = |
| 53 "application/pdf,application/postscript,image/jpeg,image/png,image/gif"; |
48 | 54 |
49 // Default port for IPP print servers. | 55 // Default port for IPP print servers. |
50 const int kDefaultIPPServerPort = 631; | 56 const int kDefaultIPPServerPort = 631; |
51 | 57 |
52 // Time interval to check for printer's updates. | 58 // Time interval to check for printer's updates. |
53 const int kCheckForPrinterUpdatesMinutes = 5; | 59 const int kCheckForPrinterUpdatesMinutes = 5; |
54 | 60 |
55 // Job update timeout | 61 // Job update timeout |
56 const int kJobUpdateTimeoutSeconds = 5; | 62 const int kJobUpdateTimeoutSeconds = 5; |
57 | 63 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // PrintServerList contains information about all print servers and backends | 168 // PrintServerList contains information about all print servers and backends |
163 // this proxy is connected to. | 169 // this proxy is connected to. |
164 typedef std::list<PrintServerInfoCUPS> PrintServerList; | 170 typedef std::list<PrintServerInfoCUPS> PrintServerList; |
165 PrintServerList print_servers_; | 171 PrintServerList print_servers_; |
166 | 172 |
167 base::TimeDelta update_timeout_; | 173 base::TimeDelta update_timeout_; |
168 bool initialized_; | 174 bool initialized_; |
169 bool printer_enum_succeeded_; | 175 bool printer_enum_succeeded_; |
170 bool notify_delete_; | 176 bool notify_delete_; |
171 http_encryption_t cups_encryption_; | 177 http_encryption_t cups_encryption_; |
| 178 std::string supported_mime_types_; |
172 }; | 179 }; |
173 | 180 |
174 class PrintServerWatcherCUPS | 181 class PrintServerWatcherCUPS |
175 : public PrintSystem::PrintServerWatcher { | 182 : public PrintSystem::PrintServerWatcher { |
176 public: | 183 public: |
177 explicit PrintServerWatcherCUPS(PrintSystemCUPS* print_system) | 184 explicit PrintServerWatcherCUPS(PrintSystemCUPS* print_system) |
178 : print_system_(print_system), | 185 : print_system_(print_system), |
179 delegate_(NULL) { | 186 delegate_(NULL) { |
180 } | 187 } |
181 | 188 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 413 |
407 DISALLOW_COPY_AND_ASSIGN(JobSpoolerCUPS); | 414 DISALLOW_COPY_AND_ASSIGN(JobSpoolerCUPS); |
408 }; | 415 }; |
409 | 416 |
410 PrintSystemCUPS::PrintSystemCUPS(const DictionaryValue* print_system_settings) | 417 PrintSystemCUPS::PrintSystemCUPS(const DictionaryValue* print_system_settings) |
411 : update_timeout_(base::TimeDelta::FromMinutes( | 418 : update_timeout_(base::TimeDelta::FromMinutes( |
412 kCheckForPrinterUpdatesMinutes)), | 419 kCheckForPrinterUpdatesMinutes)), |
413 initialized_(false), | 420 initialized_(false), |
414 printer_enum_succeeded_(false), | 421 printer_enum_succeeded_(false), |
415 notify_delete_(true), | 422 notify_delete_(true), |
416 cups_encryption_(HTTP_ENCRYPT_NEVER) { | 423 cups_encryption_(HTTP_ENCRYPT_NEVER), |
| 424 supported_mime_types_(kCUPSDefaultSupportedTypes) { |
417 if (print_system_settings) { | 425 if (print_system_settings) { |
418 int timeout; | 426 int timeout; |
419 if (print_system_settings->GetInteger(kCUPSUpdateTimeoutMs, &timeout)) | 427 if (print_system_settings->GetInteger(kCUPSUpdateTimeoutMs, &timeout)) |
420 update_timeout_ = base::TimeDelta::FromMilliseconds(timeout); | 428 update_timeout_ = base::TimeDelta::FromMilliseconds(timeout); |
421 | 429 |
422 int encryption; | 430 int encryption; |
423 if (print_system_settings->GetInteger(kCUPSEncryption, &encryption)) | 431 if (print_system_settings->GetInteger(kCUPSEncryption, &encryption)) |
424 cups_encryption_ = | 432 cups_encryption_ = |
425 static_cast<http_encryption_t>(encryption); | 433 static_cast<http_encryption_t>(encryption); |
426 | 434 |
427 bool notify_delete = true; | 435 bool notify_delete = true; |
428 if (print_system_settings->GetBoolean(kCUPSNotifyDelete, ¬ify_delete)) | 436 if (print_system_settings->GetBoolean(kCUPSNotifyDelete, ¬ify_delete)) |
429 notify_delete_ = notify_delete; | 437 notify_delete_ = notify_delete; |
| 438 |
| 439 std::string types; |
| 440 if (print_system_settings->GetString(kCUPSSupportedMimeTipes, &types)) |
| 441 supported_mime_types_ = types; |
430 } | 442 } |
431 | 443 |
432 InitPrintBackends(print_system_settings); | 444 InitPrintBackends(print_system_settings); |
433 } | 445 } |
434 | 446 |
435 void PrintSystemCUPS::InitPrintBackends( | 447 void PrintSystemCUPS::InitPrintBackends( |
436 const DictionaryValue* print_system_settings) { | 448 const DictionaryValue* print_system_settings) { |
437 const ListValue* url_list; | 449 const ListValue* url_list; |
438 if (print_system_settings && | 450 if (print_system_settings && |
439 print_system_settings->GetList(kCUPSPrintServerURLs, &url_list)) { | 451 print_system_settings->GetList(kCUPSPrintServerURLs, &url_list)) { |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 DCHECK(!printer_name.empty()); | 717 DCHECK(!printer_name.empty()); |
706 return new PrinterWatcherCUPS(this, printer_name); | 718 return new PrinterWatcherCUPS(this, printer_name); |
707 } | 719 } |
708 | 720 |
709 PrintSystem::JobSpooler* PrintSystemCUPS::CreateJobSpooler() { | 721 PrintSystem::JobSpooler* PrintSystemCUPS::CreateJobSpooler() { |
710 DCHECK(initialized_); | 722 DCHECK(initialized_); |
711 return new JobSpoolerCUPS(this); | 723 return new JobSpoolerCUPS(this); |
712 } | 724 } |
713 | 725 |
714 std::string PrintSystemCUPS::GetSupportedMimeTypes() { | 726 std::string PrintSystemCUPS::GetSupportedMimeTypes() { |
715 // Since we hand off the document to the CUPS server directly, list some types | 727 return supported_mime_types_; |
716 // that we know CUPS supports (http://www.cups.org/articles.php?L205+TFAQ+Q) | |
717 // TODO(sanjeevr): Determine this dynamically (http://crbug.com/73240). | |
718 return | |
719 "application/pdf,application/postscript,image/jpeg,image/png,image/gif"; | |
720 } | 728 } |
721 | 729 |
722 std::string PrintSystem::GenerateProxyId() { | 730 std::string PrintSystem::GenerateProxyId() { |
723 // TODO(gene): This code should generate a unique id for proxy. ID should be | 731 // TODO(gene): This code should generate a unique id for proxy. ID should be |
724 // unique for this user. Rand may return the same number. We'll need to change | 732 // unique for this user. Rand may return the same number. We'll need to change |
725 // this in the future. | 733 // this in the future. |
726 std::string id("CP_PROXY_"); | 734 std::string id("CP_PROXY_"); |
727 id += base::Uint64ToString(base::RandUint64()); | 735 id += base::Uint64ToString(base::RandUint64()); |
728 return id; | 736 return id; |
729 } | 737 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 | 873 |
866 void PrintSystemCUPS::RunCapsCallback( | 874 void PrintSystemCUPS::RunCapsCallback( |
867 const PrinterCapsAndDefaultsCallback& callback, | 875 const PrinterCapsAndDefaultsCallback& callback, |
868 bool succeeded, | 876 bool succeeded, |
869 const std::string& printer_name, | 877 const std::string& printer_name, |
870 const printing::PrinterCapsAndDefaults& printer_info) { | 878 const printing::PrinterCapsAndDefaults& printer_info) { |
871 callback.Run(succeeded, printer_name, printer_info); | 879 callback.Run(succeeded, printer_name, printer_info); |
872 } | 880 } |
873 | 881 |
874 } // namespace cloud_print | 882 } // namespace cloud_print |
OLD | NEW |