| 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> |
| 11 #include <stddef.h> | 11 #include <stddef.h> |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <map> | 14 #include <map> |
| 15 #include <memory> | 15 #include <memory> |
| 16 | 16 |
| 17 #include "base/bind.h" | 17 #include "base/bind.h" |
| 18 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
| 19 #include "base/files/file_util.h" |
| 19 #include "base/json/json_reader.h" | 20 #include "base/json/json_reader.h" |
| 20 #include "base/location.h" | 21 #include "base/location.h" |
| 21 #include "base/logging.h" | 22 #include "base/logging.h" |
| 22 #include "base/macros.h" | 23 #include "base/macros.h" |
| 23 #include "base/md5.h" | 24 #include "base/md5.h" |
| 24 #include "base/rand_util.h" | 25 #include "base/rand_util.h" |
| 25 #include "base/single_thread_task_runner.h" | 26 #include "base/single_thread_task_runner.h" |
| 26 #include "base/strings/string_number_conversions.h" | 27 #include "base/strings/string_number_conversions.h" |
| 27 #include "base/strings/string_util.h" | 28 #include "base/strings/string_util.h" |
| 28 #include "base/strings/utf_string_conversions.h" | 29 #include "base/strings/utf_string_conversions.h" |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 | 713 |
| 713 scoped_refptr<PrintSystem> PrintSystem::CreateInstance( | 714 scoped_refptr<PrintSystem> PrintSystem::CreateInstance( |
| 714 const base::DictionaryValue* print_system_settings) { | 715 const base::DictionaryValue* print_system_settings) { |
| 715 return new PrintSystemCUPS(print_system_settings); | 716 return new PrintSystemCUPS(print_system_settings); |
| 716 } | 717 } |
| 717 | 718 |
| 718 int PrintSystemCUPS::PrintFile(const GURL& url, http_encryption_t encryption, | 719 int PrintSystemCUPS::PrintFile(const GURL& url, http_encryption_t encryption, |
| 719 const char* name, const char* filename, | 720 const char* name, const char* filename, |
| 720 const char* title, int num_options, | 721 const char* title, int num_options, |
| 721 cups_option_t* options) { | 722 cups_option_t* options) { |
| 722 if (url.is_empty()) { // Use default (local) print server. | 723 // Use default (local) print server. |
| 724 if (url.is_empty()) |
| 723 return cupsPrintFile(name, filename, title, num_options, options); | 725 return cupsPrintFile(name, filename, title, num_options, options); |
| 724 } else { | 726 |
| 725 printing::HttpConnectionCUPS http(url, encryption); | 727 printing::HttpConnectionCUPS http(url, encryption); |
| 726 http.SetBlocking(false); | 728 http.SetBlocking(false); |
| 727 return cupsPrintFile2(http.http(), name, filename, | 729 return cupsPrintFile2(http.http(), name, filename, title, num_options, |
| 728 title, num_options, options); | 730 options); |
| 729 } | |
| 730 } | 731 } |
| 731 | 732 |
| 732 int PrintSystemCUPS::GetJobs(cups_job_t** jobs, const GURL& url, | 733 int PrintSystemCUPS::GetJobs(cups_job_t** jobs, const GURL& url, |
| 733 http_encryption_t encryption, | 734 http_encryption_t encryption, |
| 734 const char* name, int myjobs, int whichjobs) { | 735 const char* name, int myjobs, int whichjobs) { |
| 735 if (url.is_empty()) { // Use default (local) print server. | 736 // Use default (local) print server. |
| 737 if (url.is_empty()) |
| 736 return cupsGetJobs(jobs, name, myjobs, whichjobs); | 738 return cupsGetJobs(jobs, name, myjobs, whichjobs); |
| 737 } else { | 739 |
| 738 printing::HttpConnectionCUPS http(url, encryption); | 740 printing::HttpConnectionCUPS http(url, encryption); |
| 739 http.SetBlocking(false); | 741 http.SetBlocking(false); |
| 740 return cupsGetJobs2(http.http(), jobs, name, myjobs, whichjobs); | 742 return cupsGetJobs2(http.http(), jobs, name, myjobs, whichjobs); |
| 741 } | |
| 742 } | 743 } |
| 743 | 744 |
| 744 PlatformJobId PrintSystemCUPS::SpoolPrintJob( | 745 PlatformJobId PrintSystemCUPS::SpoolPrintJob( |
| 745 const std::string& print_ticket, | 746 const std::string& print_ticket, |
| 746 const base::FilePath& print_data_file_path, | 747 const base::FilePath& print_data_file_path, |
| 747 const std::string& print_data_mime_type, | 748 const std::string& print_data_mime_type, |
| 748 const std::string& printer_name, | 749 const std::string& printer_name, |
| 749 const std::string& job_title, | 750 const std::string& job_title, |
| 750 const std::vector<std::string>& tags, | 751 const std::vector<std::string>& tags, |
| 751 bool* dry_run) { | 752 bool* dry_run) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 781 cups_option_t opt; | 782 cups_option_t opt; |
| 782 opt.name = const_cast<char*>(it.first.c_str()); | 783 opt.name = const_cast<char*>(it.first.c_str()); |
| 783 opt.value = const_cast<char*>(it.second.c_str()); | 784 opt.value = const_cast<char*>(it.second.c_str()); |
| 784 cups_options.push_back(opt); | 785 cups_options.push_back(opt); |
| 785 } | 786 } |
| 786 | 787 |
| 787 int job_id = | 788 int job_id = |
| 788 PrintFile(server_info->url, cups_encryption_, short_printer_name.c_str(), | 789 PrintFile(server_info->url, cups_encryption_, short_printer_name.c_str(), |
| 789 print_data_file_path.value().c_str(), job_title.c_str(), | 790 print_data_file_path.value().c_str(), job_title.c_str(), |
| 790 cups_options.size(), cups_options.data()); | 791 cups_options.size(), cups_options.data()); |
| 792 base::DeleteFile(print_data_file_path, false); |
| 791 | 793 |
| 792 // TODO(alexyu): Output printer id. | 794 // TODO(alexyu): Output printer id. |
| 793 VLOG(1) << "CP_CUPS: Job spooled" | 795 VLOG(1) << "CP_CUPS: Job spooled" |
| 794 << ", printer name: " << printer_name | 796 << ", printer name: " << printer_name |
| 795 << ", cups job id: " << job_id; | 797 << ", cups job id: " << job_id; |
| 796 | 798 |
| 797 return job_id; | 799 return job_id; |
| 798 } | 800 } |
| 799 | 801 |
| 800 std::string PrintSystemCUPS::MakeFullPrinterName( | 802 std::string PrintSystemCUPS::MakeFullPrinterName( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 | 844 |
| 843 void PrintSystemCUPS::RunCapsCallback( | 845 void PrintSystemCUPS::RunCapsCallback( |
| 844 const PrinterCapsAndDefaultsCallback& callback, | 846 const PrinterCapsAndDefaultsCallback& callback, |
| 845 bool succeeded, | 847 bool succeeded, |
| 846 const std::string& printer_name, | 848 const std::string& printer_name, |
| 847 const printing::PrinterCapsAndDefaults& printer_info) { | 849 const printing::PrinterCapsAndDefaults& printer_info) { |
| 848 callback.Run(succeeded, printer_name, printer_info); | 850 callback.Run(succeeded, printer_name, printer_info); |
| 849 } | 851 } |
| 850 | 852 |
| 851 } // namespace cloud_print | 853 } // namespace cloud_print |
| OLD | NEW |