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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 DCHECK(printer_ids); | 81 DCHECK(printer_ids); |
82 printer_ids->clear(); | 82 printer_ids->clear(); |
83 for (JobHandlerMap::const_iterator iter = job_handler_map_.begin(); | 83 for (JobHandlerMap::const_iterator iter = job_handler_map_.begin(); |
84 iter != job_handler_map_.end(); ++iter) { | 84 iter != job_handler_map_.end(); ++iter) { |
85 printer_ids->push_back(iter->first); | 85 printer_ids->push_back(iter->first); |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 void CloudPrintConnector::RegisterPrinters( | 89 void CloudPrintConnector::RegisterPrinters( |
90 const printing::PrinterList& printers) { | 90 const printing::PrinterList& printers) { |
91 if (!IsRunning()) | 91 if (!settings_.connect_new_printers() || !IsRunning()) |
92 return; | 92 return; |
93 printing::PrinterList::const_iterator it; | 93 printing::PrinterList::const_iterator it; |
94 for (it = printers.begin(); it != printers.end(); ++it) { | 94 for (it = printers.begin(); it != printers.end(); ++it) { |
95 AddPendingRegisterTask(*it); | 95 if (!settings_.IsPrinterBlacklisted(it->printer_name)) |
| 96 AddPendingRegisterTask(*it); |
96 } | 97 } |
97 } | 98 } |
98 | 99 |
99 // Check for jobs for specific printer | 100 // Check for jobs for specific printer |
100 void CloudPrintConnector::CheckForJobs(const std::string& reason, | 101 void CloudPrintConnector::CheckForJobs(const std::string& reason, |
101 const std::string& printer_id) { | 102 const std::string& printer_id) { |
102 if (!IsRunning()) | 103 if (!IsRunning()) |
103 return; | 104 return; |
104 if (!printer_id.empty()) { | 105 if (!printer_id.empty()) { |
105 JobHandlerMap::iterator index = job_handler_map_.find(printer_id); | 106 JobHandlerMap::iterator index = job_handler_map_.find(printer_id); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 // Go through the list of the cloud printers and init print job handlers. | 202 // Go through the list of the cloud printers and init print job handlers. |
202 ListValue* printer_list = NULL; | 203 ListValue* printer_list = NULL; |
203 // There may be no "printers" value in the JSON | 204 // There may be no "printers" value in the JSON |
204 if (json_data->GetList(cloud_print::kPrinterListValue, &printer_list) | 205 if (json_data->GetList(cloud_print::kPrinterListValue, &printer_list) |
205 && printer_list) { | 206 && printer_list) { |
206 for (size_t index = 0; index < printer_list->GetSize(); index++) { | 207 for (size_t index = 0; index < printer_list->GetSize(); index++) { |
207 DictionaryValue* printer_data = NULL; | 208 DictionaryValue* printer_data = NULL; |
208 if (printer_list->GetDictionary(index, &printer_data)) { | 209 if (printer_list->GetDictionary(index, &printer_data)) { |
209 std::string printer_name; | 210 std::string printer_name; |
210 printer_data->GetString(kNameValue, &printer_name); | 211 printer_data->GetString(kNameValue, &printer_name); |
211 if (RemovePrinterFromList(printer_name, &local_printers)) { | 212 std::string printer_id; |
| 213 printer_data->GetString(kIdValue, &printer_id); |
| 214 if (settings_.IsPrinterBlacklisted(printer_name)) { |
| 215 VLOG(1) << "CP_CONNECTOR: Deleting " << printer_name << |
| 216 " id: " << printer_id << " as blacklisted"; |
| 217 AddPendingDeleteTask(printer_id); |
| 218 } else if (RemovePrinterFromList(printer_name, &local_printers)) { |
212 InitJobHandlerForPrinter(printer_data); | 219 InitJobHandlerForPrinter(printer_data); |
213 } else { | 220 } else { |
214 // Cloud printer is not found on the local system. | 221 // Cloud printer is not found on the local system. |
215 std::string printer_id; | |
216 printer_data->GetString(kIdValue, &printer_id); | |
217 if (full_list || settings_.delete_on_enum_fail()) { | 222 if (full_list || settings_.delete_on_enum_fail()) { |
218 // Delete if we get the full list of printers or | 223 // Delete if we get the full list of printers or |
219 // |delete_on_enum_fail_| is set. | 224 // |delete_on_enum_fail_| is set. |
220 VLOG(1) << "CP_CONNECTOR: Deleting " << printer_name << | 225 VLOG(1) << "CP_CONNECTOR: Deleting " << printer_name << |
221 " id: " << printer_id << | 226 " id: " << printer_id << |
222 " full_list: " << full_list << | 227 " full_list: " << full_list << |
223 " delete_on_enum_fail: " << settings_.delete_on_enum_fail(); | 228 " delete_on_enum_fail: " << settings_.delete_on_enum_fail(); |
224 AddPendingDeleteTask(printer_id); | 229 AddPendingDeleteTask(printer_id); |
225 } else { | 230 } else { |
226 LOG(ERROR) << "CP_CONNECTOR: Printer: " << printer_name << | 231 LOG(ERROR) << "CP_CONNECTOR: Printer: " << printer_name << |
227 " id: " << printer_id << | 232 " id: " << printer_id << |
228 " not found in print system and full printer list was" << | 233 " not found in print system and full printer list was" << |
229 " not received. Printer will not be able to process" << | 234 " not received. Printer will not be able to process" << |
230 " jobs."; | 235 " jobs."; |
231 } | 236 } |
232 } | 237 } |
233 } else { | 238 } else { |
234 NOTREACHED(); | 239 NOTREACHED(); |
235 } | 240 } |
236 } | 241 } |
237 } | 242 } |
238 | 243 |
239 request_ = NULL; | 244 request_ = NULL; |
240 if (!local_printers.empty()) { | 245 |
241 // In the future we might want to notify frontend about available printers | 246 RegisterPrinters(local_printers); |
242 // and let user choose which printers to register. | |
243 // Here is a good place to notify client about available printers. | |
244 RegisterPrinters(local_printers); | |
245 } | |
246 ContinuePendingTaskProcessing(); // Continue processing background tasks. | 247 ContinuePendingTaskProcessing(); // Continue processing background tasks. |
247 return CloudPrintURLFetcher::STOP_PROCESSING; | 248 return CloudPrintURLFetcher::STOP_PROCESSING; |
248 } | 249 } |
249 | 250 |
250 CloudPrintURLFetcher::ResponseAction | 251 CloudPrintURLFetcher::ResponseAction |
251 CloudPrintConnector::HandlePrinterDeleteResponse( | 252 CloudPrintConnector::HandlePrinterDeleteResponse( |
252 const net::URLFetcher* source, | 253 const net::URLFetcher* source, |
253 const GURL& url, | 254 const GURL& url, |
254 DictionaryValue* json_data, | 255 DictionaryValue* json_data, |
255 bool succeeded) { | 256 bool succeeded) { |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 kCloudPrintAPIMaxRetryCount, | 560 kCloudPrintAPIMaxRetryCount, |
560 mime_type, | 561 mime_type, |
561 post_data, | 562 post_data, |
562 &CloudPrintConnector::HandleRegisterPrinterResponse); | 563 &CloudPrintConnector::HandleRegisterPrinterResponse); |
563 } | 564 } |
564 | 565 |
565 bool CloudPrintConnector::IsSamePrinter(const std::string& name1, | 566 bool CloudPrintConnector::IsSamePrinter(const std::string& name1, |
566 const std::string& name2) const { | 567 const std::string& name2) const { |
567 return (0 == base::strcasecmp(name1.c_str(), name2.c_str())); | 568 return (0 == base::strcasecmp(name1.c_str(), name2.c_str())); |
568 } | 569 } |
OLD | NEW |