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" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/string_split.h" | 12 #include "base/string_split.h" |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/common/cloud_print/cloud_print_helpers.h" | 16 #include "chrome/common/cloud_print/cloud_print_helpers.h" |
17 #include "chrome/service/cloud_print/cloud_print_consts.h" | 17 #include "chrome/service/cloud_print/cloud_print_consts.h" |
18 #include "chrome/service/cloud_print/cloud_print_helpers.h" | 18 #include "chrome/service/cloud_print/cloud_print_helpers.h" |
19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
21 | 21 |
| 22 const char kDeleteOnEnumFail[] = "delete_on_enum_fail"; |
| 23 |
22 CloudPrintConnector::CloudPrintConnector( | 24 CloudPrintConnector::CloudPrintConnector( |
23 Client* client, | 25 Client* client, |
24 const std::string& proxy_id, | 26 const std::string& proxy_id, |
25 const GURL& cloud_print_server_url, | 27 const GURL& cloud_print_server_url, |
26 const DictionaryValue* print_system_settings) | 28 const DictionaryValue* print_system_settings) |
27 : client_(client), | 29 : client_(client), |
28 proxy_id_(proxy_id), | 30 proxy_id_(proxy_id), |
29 cloud_print_server_url_(cloud_print_server_url), | 31 cloud_print_server_url_(cloud_print_server_url), |
30 next_response_handler_(NULL) { | 32 next_response_handler_(NULL), |
| 33 delete_on_enum_fail_(false) { |
31 if (print_system_settings) { | 34 if (print_system_settings) { |
32 // It is possible to have no print settings specified. | 35 // It is possible to have no print settings specified. |
33 print_system_settings_.reset(print_system_settings->DeepCopy()); | 36 print_system_settings_.reset(print_system_settings->DeepCopy()); |
34 } | 37 } |
35 } | 38 } |
36 | 39 |
37 bool CloudPrintConnector::InitPrintSystem() { | 40 bool CloudPrintConnector::InitPrintSystem() { |
38 if (print_system_.get()) | 41 if (print_system_.get()) |
39 return true; | 42 return true; |
40 print_system_ = cloud_print::PrintSystem::CreateInstance( | 43 print_system_ = cloud_print::PrintSystem::CreateInstance( |
41 print_system_settings_.get()); | 44 print_system_settings_.get()); |
42 if (!print_system_.get()) { | 45 if (!print_system_.get()) { |
43 NOTREACHED(); | 46 NOTREACHED(); |
44 return false; // No memory. | 47 return false; // No memory. |
45 } | 48 } |
| 49 if (print_system_settings_.get()) { |
| 50 bool delete_on_enum_fail = false; |
| 51 print_system_settings_->GetBoolean(kDeleteOnEnumFail, |
| 52 &delete_on_enum_fail); |
| 53 delete_on_enum_fail_ = delete_on_enum_fail; |
| 54 } |
46 cloud_print::PrintSystem::PrintSystemResult result = print_system_->Init(); | 55 cloud_print::PrintSystem::PrintSystemResult result = print_system_->Init(); |
47 if (!result.succeeded()) { | 56 if (!result.succeeded()) { |
48 print_system_.release(); | 57 print_system_.release(); |
49 // We could not initialize the print system. We need to notify the server. | 58 // We could not initialize the print system. We need to notify the server. |
50 ReportUserMessage(kPrintSystemFailedMessageId, result.message()); | 59 ReportUserMessage(kPrintSystemFailedMessageId, result.message()); |
51 return false; | 60 return false; |
52 } | 61 } |
53 return true; | 62 return true; |
54 } | 63 } |
55 | 64 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 DictionaryValue* printer_data = NULL; | 224 DictionaryValue* printer_data = NULL; |
216 if (printer_list->GetDictionary(index, &printer_data)) { | 225 if (printer_list->GetDictionary(index, &printer_data)) { |
217 std::string printer_name; | 226 std::string printer_name; |
218 printer_data->GetString(kNameValue, &printer_name); | 227 printer_data->GetString(kNameValue, &printer_name); |
219 if (RemovePrinterFromList(printer_name, &local_printers)) { | 228 if (RemovePrinterFromList(printer_name, &local_printers)) { |
220 InitJobHandlerForPrinter(printer_data); | 229 InitJobHandlerForPrinter(printer_data); |
221 } else { | 230 } else { |
222 // Cloud printer is not found on the local system. | 231 // Cloud printer is not found on the local system. |
223 std::string printer_id; | 232 std::string printer_id; |
224 printer_data->GetString(kIdValue, &printer_id); | 233 printer_data->GetString(kIdValue, &printer_id); |
225 if (full_list) { // Delete only if we get the full list of printer. | 234 if (full_list || delete_on_enum_fail_) { |
| 235 // Delete if we get the full list of printers or |
| 236 // |delete_on_enum_fail_| is set. |
| 237 VLOG(1) << "CP_CONNECTOR: Deleting " << printer_name << |
| 238 " id: " << printer_id << |
| 239 " full_list: " << full_list << |
| 240 " delete_on_enum_fail: " << delete_on_enum_fail_; |
226 AddPendingDeleteTask(printer_id); | 241 AddPendingDeleteTask(printer_id); |
227 } else { | 242 } else { |
228 LOG(ERROR) << "CP_CONNECTOR: Printer: " << printer_name << | 243 LOG(ERROR) << "CP_CONNECTOR: Printer: " << printer_name << |
229 " id: " << printer_id << | 244 " id: " << printer_id << |
230 " not found in print system and full printer list was" << | 245 " not found in print system and full printer list was" << |
231 " not received. Printer will not be able to process" << | 246 " not received. Printer will not be able to process" << |
232 " jobs."; | 247 " jobs."; |
233 } | 248 } |
234 } | 249 } |
235 } else { | 250 } else { |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 mime_type, | 582 mime_type, |
568 post_data, | 583 post_data, |
569 &CloudPrintConnector::HandleRegisterPrinterResponse); | 584 &CloudPrintConnector::HandleRegisterPrinterResponse); |
570 } | 585 } |
571 | 586 |
572 bool CloudPrintConnector::IsSamePrinter(const std::string& name1, | 587 bool CloudPrintConnector::IsSamePrinter(const std::string& name1, |
573 const std::string& name2) const { | 588 const std::string& name2) const { |
574 return (0 == base::strcasecmp(name1.c_str(), name2.c_str())); | 589 return (0 == base::strcasecmp(name1.c_str(), name2.c_str())); |
575 } | 590 } |
576 | 591 |
OLD | NEW |