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