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/connector_settings.h" | 5 #include "chrome/service/cloud_print/connector_settings.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/common/cloud_print/cloud_print_constants.h" | 8 #include "chrome/common/cloud_print/cloud_print_constants.h" |
9 #include "chrome/common/pref_names.h" | 9 #include "chrome/common/pref_names.h" |
10 #include "chrome/service/cloud_print/print_system.h" | 10 #include "chrome/service/cloud_print/print_system.h" |
11 #include "chrome/service/service_process_prefs.h" | 11 #include "chrome/service/service_process_prefs.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 const char kDefaultCloudPrintServerUrl[] = "https://www.google.com/cloudprint"; | 15 const char kDefaultCloudPrintServerUrl[] = "https://www.google.com/cloudprint"; |
16 const char kDeleteOnEnumFail[] = "delete_on_enum_fail"; | 16 const char kDeleteOnEnumFail[] = "delete_on_enum_fail"; |
| 17 const char kName[] = "name"; |
| 18 const char kConnect[] = "connect"; |
17 | 19 |
18 } // namespace | 20 } // namespace |
19 | 21 |
20 namespace cloud_print { | 22 namespace cloud_print { |
21 | 23 |
22 ConnectorSettings::ConnectorSettings() | 24 ConnectorSettings::ConnectorSettings() |
23 : delete_on_enum_fail_(false), | 25 : delete_on_enum_fail_(false), |
24 connect_new_printers_(true), | 26 connect_new_printers_(true), |
25 xmpp_ping_enabled_(false), | 27 xmpp_ping_enabled_(false), |
26 xmpp_ping_timeout_sec_(kDefaultXmppPingTimeoutSecs) { | 28 xmpp_ping_timeout_sec_(kDefaultXmppPingTimeoutSecs) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 63 |
62 connect_new_printers_ = prefs->GetBoolean( | 64 connect_new_printers_ = prefs->GetBoolean( |
63 prefs::kCloudPrintConnectNewPrinters, true); | 65 prefs::kCloudPrintConnectNewPrinters, true); |
64 | 66 |
65 xmpp_ping_enabled_ = prefs->GetBoolean( | 67 xmpp_ping_enabled_ = prefs->GetBoolean( |
66 prefs::kCloudPrintXmppPingEnabled, false); | 68 prefs::kCloudPrintXmppPingEnabled, false); |
67 int timeout = prefs->GetInt( | 69 int timeout = prefs->GetInt( |
68 prefs::kCloudPrintXmppPingTimeout, kDefaultXmppPingTimeoutSecs); | 70 prefs::kCloudPrintXmppPingTimeout, kDefaultXmppPingTimeoutSecs); |
69 SetXmppPingTimeoutSec(timeout); | 71 SetXmppPingTimeoutSec(timeout); |
70 | 72 |
71 const base::ListValue* printers = prefs->GetList( | 73 const base::ListValue* printers = prefs->GetList(prefs::kCloudPrintPrinters); |
72 prefs::kCloudPrintPrinterBlacklist); | |
73 if (printers) { | 74 if (printers) { |
74 for (size_t i = 0; i < printers->GetSize(); ++i) { | 75 for (size_t i = 0; i < printers->GetSize(); ++i) { |
75 std::string printer; | 76 const base::DictionaryValue* dictionary = NULL; |
76 if (printers->GetString(i, &printer)) | 77 if (printers->GetDictionary(i, &dictionary) && dictionary) { |
77 printer_blacklist_.insert(printer); | 78 std::string name; |
| 79 dictionary->GetString(kName, &name); |
| 80 if (!name.empty()) { |
| 81 bool connect = connect_new_printers_; |
| 82 dictionary->GetBoolean(kConnect, &connect); |
| 83 if (connect != connect_new_printers_) |
| 84 printers_.insert(name); |
| 85 } |
| 86 } |
78 } | 87 } |
79 } | 88 } |
80 } | 89 } |
81 | 90 |
82 bool ConnectorSettings::IsPrinterBlacklisted(const std::string& name) const { | 91 bool ConnectorSettings::ShouldConnect(const std::string& printer_name) const { |
83 return printer_blacklist_.find(name) != printer_blacklist_.end(); | 92 Printers::const_iterator printer = printers_.find(printer_name); |
84 }; | 93 if (printer != printers_.end()) |
| 94 return !connect_new_printers_; |
| 95 return connect_new_printers_; |
| 96 } |
85 | 97 |
86 void ConnectorSettings::CopyFrom(const ConnectorSettings& source) { | 98 void ConnectorSettings::CopyFrom(const ConnectorSettings& source) { |
87 server_url_ = source.server_url(); | 99 server_url_ = source.server_url(); |
88 proxy_id_ = source.proxy_id(); | 100 proxy_id_ = source.proxy_id(); |
89 delete_on_enum_fail_ = source.delete_on_enum_fail(); | 101 delete_on_enum_fail_ = source.delete_on_enum_fail(); |
90 connect_new_printers_ = source.connect_new_printers(); | 102 connect_new_printers_ = source.connect_new_printers_; |
91 xmpp_ping_enabled_ = source.xmpp_ping_enabled(); | 103 xmpp_ping_enabled_ = source.xmpp_ping_enabled(); |
92 xmpp_ping_timeout_sec_ = source.xmpp_ping_timeout_sec(); | 104 xmpp_ping_timeout_sec_ = source.xmpp_ping_timeout_sec(); |
93 printer_blacklist_ = source.printer_blacklist_; | 105 printers_ = source.printers_; |
94 if (source.print_system_settings()) | 106 if (source.print_system_settings()) |
95 print_system_settings_.reset(source.print_system_settings()->DeepCopy()); | 107 print_system_settings_.reset(source.print_system_settings()->DeepCopy()); |
96 } | 108 } |
97 | 109 |
98 void ConnectorSettings::SetXmppPingTimeoutSec(int timeout) { | 110 void ConnectorSettings::SetXmppPingTimeoutSec(int timeout) { |
99 xmpp_ping_timeout_sec_ = timeout; | 111 xmpp_ping_timeout_sec_ = timeout; |
100 if (xmpp_ping_timeout_sec_ < kMinimumXmppPingTimeoutSecs) { | 112 if (xmpp_ping_timeout_sec_ < kMinimumXmppPingTimeoutSecs) { |
101 LOG(WARNING) << | 113 LOG(WARNING) << |
102 "CP_CONNECTOR: XMPP ping timeout is less then minimal value"; | 114 "CP_CONNECTOR: XMPP ping timeout is less then minimal value"; |
103 xmpp_ping_timeout_sec_ = kMinimumXmppPingTimeoutSecs; | 115 xmpp_ping_timeout_sec_ = kMinimumXmppPingTimeoutSecs; |
104 } | 116 } |
105 } | 117 } |
106 | 118 |
107 } // namespace cloud_print | 119 } // namespace cloud_print |
OLD | NEW |