blob: 2b43b156debb9611a413514deb2bfc84e642b984 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/service/cloud_print/connector_settings.h"
#include "base/values.h"
#include "chrome/common/cloud_print/cloud_print_constants.h"
#include "chrome/common/pref_names.h"
#include "chrome/service/cloud_print/print_system.h"
#include "chrome/service/service_process_prefs.h"
namespace {
const char kDefaultCloudPrintServerUrl[] = "https://www.google.com/cloudprint";
const char kDeleteOnEnumFail[] = "delete_on_enum_fail";
} // namespace
namespace cloud_print {
ConnectorSettings::ConnectorSettings()
: delete_on_enum_fail_(false),
connect_new_printers_(true),
xmpp_ping_enabled_(false),
xmpp_ping_timeout_sec_(kDefaultXmppPingTimeoutSecs) {
}
ConnectorSettings::~ConnectorSettings() {
}
void ConnectorSettings::InitFrom(ServiceProcessPrefs* prefs) {
CopyFrom(ConnectorSettings());
proxy_id_ = prefs->GetString(prefs::kCloudPrintProxyId, "");
if (proxy_id_.empty()) {
proxy_id_ = PrintSystem::GenerateProxyId();
prefs->SetString(prefs::kCloudPrintProxyId, proxy_id_);
prefs->WritePrefs();
}
// Getting print system specific settings from the preferences.
const base::DictionaryValue* print_system_settings =
prefs->GetDictionary(prefs::kCloudPrintPrintSystemSettings);
if (print_system_settings) {
print_system_settings_.reset(print_system_settings->DeepCopy());
// TODO(vitalybuka) : Consider to rename and move out option from
// print_system_settings.
print_system_settings_->GetBoolean(kDeleteOnEnumFail,
&delete_on_enum_fail_);
}
// Check if there is an override for the cloud print server URL.
server_url_ = GURL(prefs->GetString(prefs::kCloudPrintServiceURL, ""));
DCHECK(server_url_.is_empty() || server_url_.is_valid());
if (server_url_.is_empty() || !server_url_.is_valid()) {
server_url_ = GURL(kDefaultCloudPrintServerUrl);
}
DCHECK(server_url_.is_valid());
connect_new_printers_ = prefs->GetBoolean(
prefs::kCloudPrintConnectNewPrinters, true);
xmpp_ping_enabled_ = prefs->GetBoolean(
prefs::kCloudPrintXmppPingEnabled, false);
int timeout = prefs->GetInt(
prefs::kCloudPrintXmppPingTimeout, kDefaultXmppPingTimeoutSecs);
SetXmppPingTimeoutSec(timeout);
const base::ListValue* printers = prefs->GetList(
prefs::kCloudPrintPrinterBlacklist);
if (printers) {
for (size_t i = 0; i < printers->GetSize(); ++i) {
std::string printer;
if (printers->GetString(i, &printer))
printer_blacklist_.insert(printer);
}
}
}
bool ConnectorSettings::IsPrinterBlacklisted(const std::string& name) const {
return printer_blacklist_.find(name) != printer_blacklist_.end();
};
void ConnectorSettings::CopyFrom(const ConnectorSettings& source) {
server_url_ = source.server_url();
proxy_id_ = source.proxy_id();
delete_on_enum_fail_ = source.delete_on_enum_fail();
connect_new_printers_ = source.connect_new_printers();
xmpp_ping_enabled_ = source.xmpp_ping_enabled();
xmpp_ping_timeout_sec_ = source.xmpp_ping_timeout_sec();
printer_blacklist_ = source.printer_blacklist_;
if (source.print_system_settings())
print_system_settings_.reset(source.print_system_settings()->DeepCopy());
}
void ConnectorSettings::SetXmppPingTimeoutSec(int timeout) {
xmpp_ping_timeout_sec_ = timeout;
if (xmpp_ping_timeout_sec_ < kMinimumXmppPingTimeoutSecs) {
LOG(WARNING) <<
"CP_CONNECTOR: XMPP ping timeout is less then minimal value";
xmpp_ping_timeout_sec_ = kMinimumXmppPingTimeoutSecs;
}
}
} // namespace cloud_print
|