| 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/cloud_print_connector.h" | 5 #include "chrome/service/cloud_print/cloud_print_connector.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/md5.h" | 9 #include "base/md5.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 DCHECK(printer_ids); | 83 DCHECK(printer_ids); |
| 84 printer_ids->clear(); | 84 printer_ids->clear(); |
| 85 for (JobHandlerMap::const_iterator iter = job_handler_map_.begin(); | 85 for (JobHandlerMap::const_iterator iter = job_handler_map_.begin(); |
| 86 iter != job_handler_map_.end(); ++iter) { | 86 iter != job_handler_map_.end(); ++iter) { |
| 87 printer_ids->push_back(iter->first); | 87 printer_ids->push_back(iter->first); |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 | 90 |
| 91 void CloudPrintConnector::RegisterPrinters( | 91 void CloudPrintConnector::RegisterPrinters( |
| 92 const printing::PrinterList& printers) { | 92 const printing::PrinterList& printers) { |
| 93 if (!settings_.connect_new_printers() || !IsRunning()) | 93 if (!IsRunning()) |
| 94 return; | 94 return; |
| 95 printing::PrinterList::const_iterator it; | 95 printing::PrinterList::const_iterator it; |
| 96 for (it = printers.begin(); it != printers.end(); ++it) { | 96 for (it = printers.begin(); it != printers.end(); ++it) { |
| 97 if (!settings_.IsPrinterBlacklisted(it->printer_name)) | 97 if (settings_.ShouldConnect(it->printer_name)) |
| 98 AddPendingRegisterTask(*it); | 98 AddPendingRegisterTask(*it); |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Check for jobs for specific printer | 102 // Check for jobs for specific printer |
| 103 void CloudPrintConnector::CheckForJobs(const std::string& reason, | 103 void CloudPrintConnector::CheckForJobs(const std::string& reason, |
| 104 const std::string& printer_id) { | 104 const std::string& printer_id) { |
| 105 if (!IsRunning()) | 105 if (!IsRunning()) |
| 106 return; | 106 return; |
| 107 if (!printer_id.empty()) { | 107 if (!printer_id.empty()) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 ListValue* printer_list = NULL; | 205 ListValue* printer_list = NULL; |
| 206 // There may be no "printers" value in the JSON | 206 // There may be no "printers" value in the JSON |
| 207 if (json_data->GetList(kPrinterListValue, &printer_list) && printer_list) { | 207 if (json_data->GetList(kPrinterListValue, &printer_list) && printer_list) { |
| 208 for (size_t index = 0; index < printer_list->GetSize(); index++) { | 208 for (size_t index = 0; index < printer_list->GetSize(); index++) { |
| 209 DictionaryValue* printer_data = NULL; | 209 DictionaryValue* printer_data = NULL; |
| 210 if (printer_list->GetDictionary(index, &printer_data)) { | 210 if (printer_list->GetDictionary(index, &printer_data)) { |
| 211 std::string printer_name; | 211 std::string printer_name; |
| 212 printer_data->GetString(kNameValue, &printer_name); | 212 printer_data->GetString(kNameValue, &printer_name); |
| 213 std::string printer_id; | 213 std::string printer_id; |
| 214 printer_data->GetString(kIdValue, &printer_id); | 214 printer_data->GetString(kIdValue, &printer_id); |
| 215 if (settings_.IsPrinterBlacklisted(printer_name)) { | 215 |
| 216 if (!settings_.ShouldConnect(printer_name)) { |
| 216 VLOG(1) << "CP_CONNECTOR: Deleting " << printer_name << | 217 VLOG(1) << "CP_CONNECTOR: Deleting " << printer_name << |
| 217 " id: " << printer_id << " as blacklisted"; | 218 " id: " << printer_id << " as blacklisted"; |
| 218 AddPendingDeleteTask(printer_id); | 219 AddPendingDeleteTask(printer_id); |
| 219 } else if (RemovePrinterFromList(printer_name, &local_printers)) { | 220 } else if (RemovePrinterFromList(printer_name, &local_printers)) { |
| 220 InitJobHandlerForPrinter(printer_data); | 221 InitJobHandlerForPrinter(printer_data); |
| 221 } else { | 222 } else { |
| 222 // Cloud printer is not found on the local system. | 223 // Cloud printer is not found on the local system. |
| 223 if (full_list || settings_.delete_on_enum_fail()) { | 224 if (full_list || settings_.delete_on_enum_fail()) { |
| 224 // Delete if we get the full list of printers or | 225 // Delete if we get the full list of printers or |
| 225 // |delete_on_enum_fail_| is set. | 226 // |delete_on_enum_fail_| is set. |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 post_data, | 561 post_data, |
| 561 &CloudPrintConnector::HandleRegisterPrinterResponse); | 562 &CloudPrintConnector::HandleRegisterPrinterResponse); |
| 562 } | 563 } |
| 563 | 564 |
| 564 bool CloudPrintConnector::IsSamePrinter(const std::string& name1, | 565 bool CloudPrintConnector::IsSamePrinter(const std::string& name1, |
| 565 const std::string& name2) const { | 566 const std::string& name2) const { |
| 566 return (0 == base::strcasecmp(name1.c_str(), name2.c_str())); | 567 return (0 == base::strcasecmp(name1.c_str(), name2.c_str())); |
| 567 } | 568 } |
| 568 | 569 |
| 569 } // namespace cloud_print | 570 } // namespace cloud_print |
| OLD | NEW |