| 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 <list> | 14 #include <list> |
| 15 #include <map> | 15 #include <map> |
| 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/memory/scoped_ptr.h" | 25 #include "base/memory/scoped_ptr.h" |
| 25 #include "base/rand_util.h" | 26 #include "base/rand_util.h" |
| 26 #include "base/single_thread_task_runner.h" | 27 #include "base/single_thread_task_runner.h" |
| 27 #include "base/strings/string_number_conversions.h" | 28 #include "base/strings/string_number_conversions.h" |
| 28 #include "base/strings/string_util.h" | 29 #include "base/strings/string_util.h" |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 | 725 |
| 725 scoped_refptr<PrintSystem> PrintSystem::CreateInstance( | 726 scoped_refptr<PrintSystem> PrintSystem::CreateInstance( |
| 726 const base::DictionaryValue* print_system_settings) { | 727 const base::DictionaryValue* print_system_settings) { |
| 727 return new PrintSystemCUPS(print_system_settings); | 728 return new PrintSystemCUPS(print_system_settings); |
| 728 } | 729 } |
| 729 | 730 |
| 730 int PrintSystemCUPS::PrintFile(const GURL& url, http_encryption_t encryption, | 731 int PrintSystemCUPS::PrintFile(const GURL& url, http_encryption_t encryption, |
| 731 const char* name, const char* filename, | 732 const char* name, const char* filename, |
| 732 const char* title, int num_options, | 733 const char* title, int num_options, |
| 733 cups_option_t* options) { | 734 cups_option_t* options) { |
| 734 if (url.is_empty()) { // Use default (local) print server. | 735 // Use default (local) print server. |
| 736 if (url.is_empty()) |
| 735 return cupsPrintFile(name, filename, title, num_options, options); | 737 return cupsPrintFile(name, filename, title, num_options, options); |
| 736 } else { | 738 |
| 737 printing::HttpConnectionCUPS http(url, encryption); | 739 printing::HttpConnectionCUPS http(url, encryption); |
| 738 http.SetBlocking(false); | 740 http.SetBlocking(false); |
| 739 return cupsPrintFile2(http.http(), name, filename, | 741 return cupsPrintFile2(http.http(), name, filename, title, num_options, |
| 740 title, num_options, options); | 742 options); |
| 741 } | |
| 742 } | 743 } |
| 743 | 744 |
| 744 int PrintSystemCUPS::GetJobs(cups_job_t** jobs, const GURL& url, | 745 int PrintSystemCUPS::GetJobs(cups_job_t** jobs, const GURL& url, |
| 745 http_encryption_t encryption, | 746 http_encryption_t encryption, |
| 746 const char* name, int myjobs, int whichjobs) { | 747 const char* name, int myjobs, int whichjobs) { |
| 747 if (url.is_empty()) { // Use default (local) print server. | 748 // Use default (local) print server. |
| 749 if (url.is_empty()) |
| 748 return cupsGetJobs(jobs, name, myjobs, whichjobs); | 750 return cupsGetJobs(jobs, name, myjobs, whichjobs); |
| 749 } else { | 751 |
| 750 printing::HttpConnectionCUPS http(url, encryption); | 752 printing::HttpConnectionCUPS http(url, encryption); |
| 751 http.SetBlocking(false); | 753 http.SetBlocking(false); |
| 752 return cupsGetJobs2(http.http(), jobs, name, myjobs, whichjobs); | 754 return cupsGetJobs2(http.http(), jobs, name, myjobs, whichjobs); |
| 753 } | |
| 754 } | 755 } |
| 755 | 756 |
| 756 PlatformJobId PrintSystemCUPS::SpoolPrintJob( | 757 PlatformJobId PrintSystemCUPS::SpoolPrintJob( |
| 757 const std::string& print_ticket, | 758 const std::string& print_ticket, |
| 758 const base::FilePath& print_data_file_path, | 759 const base::FilePath& print_data_file_path, |
| 759 const std::string& print_data_mime_type, | 760 const std::string& print_data_mime_type, |
| 760 const std::string& printer_name, | 761 const std::string& printer_name, |
| 761 const std::string& job_title, | 762 const std::string& job_title, |
| 762 const std::vector<std::string>& tags, | 763 const std::vector<std::string>& tags, |
| 763 bool* dry_run) { | 764 bool* dry_run) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 790 std::vector<cups_option_t> cups_options; | 791 std::vector<cups_option_t> cups_options; |
| 791 std::map<std::string, std::string>::iterator it; | 792 std::map<std::string, std::string>::iterator it; |
| 792 | 793 |
| 793 for (it = options.begin(); it != options.end(); ++it) { | 794 for (it = options.begin(); it != options.end(); ++it) { |
| 794 cups_option_t opt; | 795 cups_option_t opt; |
| 795 opt.name = const_cast<char*>(it->first.c_str()); | 796 opt.name = const_cast<char*>(it->first.c_str()); |
| 796 opt.value = const_cast<char*>(it->second.c_str()); | 797 opt.value = const_cast<char*>(it->second.c_str()); |
| 797 cups_options.push_back(opt); | 798 cups_options.push_back(opt); |
| 798 } | 799 } |
| 799 | 800 |
| 800 int job_id = PrintFile(server_info->url, | 801 int job_id = |
| 801 cups_encryption_, | 802 PrintFile(server_info->url, cups_encryption_, short_printer_name.c_str(), |
| 802 short_printer_name.c_str(), | 803 print_data_file_path.value().c_str(), job_title.c_str(), |
| 803 print_data_file_path.value().c_str(), | 804 cups_options.size(), cups_options.data()); |
| 804 job_title.c_str(), | 805 base::DeleteFile(print_data_file_path, false); |
| 805 cups_options.size(), | |
| 806 &(cups_options[0])); | |
| 807 | 806 |
| 808 // TODO(alexyu): Output printer id. | 807 // TODO(alexyu): Output printer id. |
| 809 VLOG(1) << "CP_CUPS: Job spooled" | 808 VLOG(1) << "CP_CUPS: Job spooled" |
| 810 << ", printer name: " << printer_name | 809 << ", printer name: " << printer_name |
| 811 << ", cups job id: " << job_id; | 810 << ", cups job id: " << job_id; |
| 812 | 811 |
| 813 return job_id; | 812 return job_id; |
| 814 } | 813 } |
| 815 | 814 |
| 816 std::string PrintSystemCUPS::MakeFullPrinterName( | 815 std::string PrintSystemCUPS::MakeFullPrinterName( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 | 858 |
| 860 void PrintSystemCUPS::RunCapsCallback( | 859 void PrintSystemCUPS::RunCapsCallback( |
| 861 const PrinterCapsAndDefaultsCallback& callback, | 860 const PrinterCapsAndDefaultsCallback& callback, |
| 862 bool succeeded, | 861 bool succeeded, |
| 863 const std::string& printer_name, | 862 const std::string& printer_name, |
| 864 const printing::PrinterCapsAndDefaults& printer_info) { | 863 const printing::PrinterCapsAndDefaults& printer_info) { |
| 865 callback.Run(succeeded, printer_name, printer_info); | 864 callback.Run(succeeded, printer_name, printer_info); |
| 866 } | 865 } |
| 867 | 866 |
| 868 } // namespace cloud_print | 867 } // namespace cloud_print |
| OLD | NEW |