| 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/pref_names.h" | 8 #include "chrome/common/pref_names.h" |
| 9 #include "chrome/service/cloud_print/cloud_print_consts.h" | 9 #include "chrome/service/cloud_print/cloud_print_consts.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 | 17 |
| 18 } // namespace | 18 } // namespace |
| 19 | 19 |
| 20 ConnectorSettings::ConnectorSettings() | 20 ConnectorSettings::ConnectorSettings() |
| 21 : delete_on_enum_fail_(false), | 21 : delete_on_enum_fail_(false), |
| 22 connect_new_printers_(true) { | 22 connect_new_printers_(true), |
| 23 xmpp_ping_enabled_(false), |
| 24 xmpp_ping_timeout_sec_(kDefaultXmppPingTimeoutSecs) { |
| 23 } | 25 } |
| 24 | 26 |
| 25 ConnectorSettings::~ConnectorSettings() { | 27 ConnectorSettings::~ConnectorSettings() { |
| 26 } | 28 } |
| 27 | 29 |
| 28 void ConnectorSettings::InitFrom(ServiceProcessPrefs* prefs) { | 30 void ConnectorSettings::InitFrom(ServiceProcessPrefs* prefs) { |
| 29 CopyFrom(ConnectorSettings()); | 31 CopyFrom(ConnectorSettings()); |
| 30 | 32 |
| 31 proxy_id_ = prefs->GetString(prefs::kCloudPrintProxyId, ""); | 33 proxy_id_ = prefs->GetString(prefs::kCloudPrintProxyId, ""); |
| 32 if (proxy_id_.empty()) { | 34 if (proxy_id_.empty()) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 49 // Check if there is an override for the cloud print server URL. | 51 // Check if there is an override for the cloud print server URL. |
| 50 server_url_ = GURL(prefs->GetString(prefs::kCloudPrintServiceURL, "")); | 52 server_url_ = GURL(prefs->GetString(prefs::kCloudPrintServiceURL, "")); |
| 51 DCHECK(server_url_.is_empty() || server_url_.is_valid()); | 53 DCHECK(server_url_.is_empty() || server_url_.is_valid()); |
| 52 if (server_url_.is_empty() || !server_url_.is_valid()) { | 54 if (server_url_.is_empty() || !server_url_.is_valid()) { |
| 53 server_url_ = GURL(kDefaultCloudPrintServerUrl); | 55 server_url_ = GURL(kDefaultCloudPrintServerUrl); |
| 54 } | 56 } |
| 55 DCHECK(server_url_.is_valid()); | 57 DCHECK(server_url_.is_valid()); |
| 56 | 58 |
| 57 connect_new_printers_ = prefs->GetBoolean( | 59 connect_new_printers_ = prefs->GetBoolean( |
| 58 prefs::kCloudPrintConnectNewPrinters, true); | 60 prefs::kCloudPrintConnectNewPrinters, true); |
| 61 |
| 62 xmpp_ping_enabled_ = prefs->GetBoolean( |
| 63 prefs::kCloudPrintXmppPingEnabled, false); |
| 64 int timeout = prefs->GetInt( |
| 65 prefs::kCloudPrintXmppPingTimeout, kDefaultXmppPingTimeoutSecs); |
| 66 SetXmppPingTimeoutSec(timeout); |
| 67 |
| 59 const base::ListValue* printers = prefs->GetList( | 68 const base::ListValue* printers = prefs->GetList( |
| 60 prefs::kCloudPrintPrinterBlacklist); | 69 prefs::kCloudPrintPrinterBlacklist); |
| 61 if (printers) { | 70 if (printers) { |
| 62 for (size_t i = 0; i < printers->GetSize(); ++i) { | 71 for (size_t i = 0; i < printers->GetSize(); ++i) { |
| 63 std::string printer; | 72 std::string printer; |
| 64 if (printers->GetString(i, &printer)) | 73 if (printers->GetString(i, &printer)) |
| 65 printer_blacklist_.insert(printer); | 74 printer_blacklist_.insert(printer); |
| 66 } | 75 } |
| 67 } | 76 } |
| 68 } | 77 } |
| 69 | 78 |
| 70 bool ConnectorSettings::IsPrinterBlacklisted(const std::string& name) const { | 79 bool ConnectorSettings::IsPrinterBlacklisted(const std::string& name) const { |
| 71 return printer_blacklist_.find(name) != printer_blacklist_.end(); | 80 return printer_blacklist_.find(name) != printer_blacklist_.end(); |
| 72 }; | 81 }; |
| 73 | 82 |
| 74 void ConnectorSettings::CopyFrom(const ConnectorSettings& source) { | 83 void ConnectorSettings::CopyFrom(const ConnectorSettings& source) { |
| 75 server_url_ = source.server_url(); | 84 server_url_ = source.server_url(); |
| 76 proxy_id_ = source.proxy_id(); | 85 proxy_id_ = source.proxy_id(); |
| 77 delete_on_enum_fail_ = source.delete_on_enum_fail(); | 86 delete_on_enum_fail_ = source.delete_on_enum_fail(); |
| 78 connect_new_printers_ = source.connect_new_printers(); | 87 connect_new_printers_ = source.connect_new_printers(); |
| 88 xmpp_ping_enabled_ = source.xmpp_ping_enabled(); |
| 89 xmpp_ping_timeout_sec_ = source.xmpp_ping_timeout_sec(); |
| 79 printer_blacklist_ = source.printer_blacklist_; | 90 printer_blacklist_ = source.printer_blacklist_; |
| 80 if (source.print_system_settings()) | 91 if (source.print_system_settings()) |
| 81 print_system_settings_.reset(source.print_system_settings()->DeepCopy()); | 92 print_system_settings_.reset(source.print_system_settings()->DeepCopy()); |
| 82 } | 93 } |
| 83 | 94 |
| 95 void ConnectorSettings::SetXmppPingTimeoutSec(int timeout) { |
| 96 xmpp_ping_timeout_sec_ = timeout; |
| 97 if (xmpp_ping_timeout_sec_ < kMinimumXmppPingTimeoutSecs) { |
| 98 LOG(WARNING) << |
| 99 "CP_CONNECTOR: XMPP ping timeout is less then minimal value"; |
| 100 xmpp_ping_timeout_sec_ = kMinimumXmppPingTimeoutSecs; |
| 101 } |
| 102 } |
| OLD | NEW |