| 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 #include <memory> |
| 16 | 17 |
| 17 #include "base/bind.h" | 18 #include "base/bind.h" |
| 18 #include "base/files/file_path.h" | 19 #include "base/files/file_path.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/rand_util.h" | 25 #include "base/rand_util.h" |
| 26 #include "base/single_thread_task_runner.h" | 26 #include "base/single_thread_task_runner.h" |
| 27 #include "base/strings/string_number_conversions.h" | 27 #include "base/strings/string_number_conversions.h" |
| 28 #include "base/strings/string_util.h" | 28 #include "base/strings/string_util.h" |
| 29 #include "base/strings/utf_string_conversions.h" | 29 #include "base/strings/utf_string_conversions.h" |
| 30 #include "base/thread_task_runner_handle.h" | 30 #include "base/thread_task_runner_handle.h" |
| 31 #include "base/values.h" | 31 #include "base/values.h" |
| 32 #include "chrome/common/cloud_print/cloud_print_constants.h" | 32 #include "chrome/common/cloud_print/cloud_print_constants.h" |
| 33 #include "chrome/common/crash_keys.h" | 33 #include "chrome/common/crash_keys.h" |
| 34 #include "chrome/service/cloud_print/cloud_print_service_helpers.h" | 34 #include "chrome/service/cloud_print/cloud_print_service_helpers.h" |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 | 528 |
| 529 bool PrintSystemCUPS::IsValidPrinter(const std::string& printer_name) { | 529 bool PrintSystemCUPS::IsValidPrinter(const std::string& printer_name) { |
| 530 return GetPrinterInfo(printer_name, NULL); | 530 return GetPrinterInfo(printer_name, NULL); |
| 531 } | 531 } |
| 532 | 532 |
| 533 bool PrintSystemCUPS::ValidatePrintTicket( | 533 bool PrintSystemCUPS::ValidatePrintTicket( |
| 534 const std::string& printer_name, | 534 const std::string& printer_name, |
| 535 const std::string& print_ticket_data, | 535 const std::string& print_ticket_data, |
| 536 const std::string& print_ticket_mime_type) { | 536 const std::string& print_ticket_mime_type) { |
| 537 DCHECK(initialized_); | 537 DCHECK(initialized_); |
| 538 scoped_ptr<base::Value> ticket_value( | 538 std::unique_ptr<base::Value> ticket_value( |
| 539 base::JSONReader::Read(print_ticket_data)); | 539 base::JSONReader::Read(print_ticket_data)); |
| 540 return ticket_value != NULL && | 540 return ticket_value != NULL && |
| 541 ticket_value->IsType(base::Value::TYPE_DICTIONARY); | 541 ticket_value->IsType(base::Value::TYPE_DICTIONARY); |
| 542 } | 542 } |
| 543 | 543 |
| 544 // Print ticket on linux is a JSON string containing only one dictionary. | 544 // Print ticket on linux is a JSON string containing only one dictionary. |
| 545 bool PrintSystemCUPS::ParsePrintTicket( | 545 bool PrintSystemCUPS::ParsePrintTicket( |
| 546 const std::string& print_ticket, | 546 const std::string& print_ticket, |
| 547 std::map<std::string, std::string>* options) { | 547 std::map<std::string, std::string>* options) { |
| 548 DCHECK(options); | 548 DCHECK(options); |
| 549 scoped_ptr<base::Value> ticket_value(base::JSONReader::Read(print_ticket)); | 549 std::unique_ptr<base::Value> ticket_value( |
| 550 base::JSONReader::Read(print_ticket)); |
| 550 if (ticket_value == NULL || | 551 if (ticket_value == NULL || |
| 551 !ticket_value->IsType(base::Value::TYPE_DICTIONARY)) { | 552 !ticket_value->IsType(base::Value::TYPE_DICTIONARY)) { |
| 552 return false; | 553 return false; |
| 553 } | 554 } |
| 554 | 555 |
| 555 options->clear(); | 556 options->clear(); |
| 556 base::DictionaryValue* ticket_dict = | 557 base::DictionaryValue* ticket_dict = |
| 557 static_cast<base::DictionaryValue*>(ticket_value.get()); | 558 static_cast<base::DictionaryValue*>(ticket_value.get()); |
| 558 for (base::DictionaryValue::Iterator it(*ticket_dict); !it.IsAtEnd(); | 559 for (base::DictionaryValue::Iterator it(*ticket_dict); !it.IsAtEnd(); |
| 559 it.Advance()) { | 560 it.Advance()) { |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 | 860 |
| 860 void PrintSystemCUPS::RunCapsCallback( | 861 void PrintSystemCUPS::RunCapsCallback( |
| 861 const PrinterCapsAndDefaultsCallback& callback, | 862 const PrinterCapsAndDefaultsCallback& callback, |
| 862 bool succeeded, | 863 bool succeeded, |
| 863 const std::string& printer_name, | 864 const std::string& printer_name, |
| 864 const printing::PrinterCapsAndDefaults& printer_info) { | 865 const printing::PrinterCapsAndDefaults& printer_info) { |
| 865 callback.Run(succeeded, printer_name, printer_info); | 866 callback.Run(succeeded, printer_name, printer_info); |
| 866 } | 867 } |
| 867 | 868 |
| 868 } // namespace cloud_print | 869 } // namespace cloud_print |
| OLD | NEW |