Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: chrome/browser/chromeos/proxy_cros_settings_provider.cc

Issue 8091002: PART2: Make SignedSettings use proper Value types instead of string all around the place. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments and rebased on a the current PART1 version. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/browser/chromeos/proxy_cros_settings_provider.h" 5 #include "chrome/browser/chromeos/proxy_cros_settings_provider.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/chromeos/cros_settings.h" 9 #include "chrome/browser/chromeos/cros_settings.h"
10 #include "chrome/browser/ui/browser_list.h" 10 #include "chrome/browser/ui/browser_list.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 bool ProxyCrosSettingsProvider::IsUsingSharedProxies() const { 64 bool ProxyCrosSettingsProvider::IsUsingSharedProxies() const {
65 return GetConfigService()->use_shared_proxies(); 65 return GetConfigService()->use_shared_proxies();
66 } 66 }
67 67
68 const std::string& ProxyCrosSettingsProvider::GetCurrentNetworkName() const { 68 const std::string& ProxyCrosSettingsProvider::GetCurrentNetworkName() const {
69 return GetConfigService()->current_network_name(); 69 return GetConfigService()->current_network_name();
70 } 70 }
71 71
72 void ProxyCrosSettingsProvider::DoSet(const std::string& path, 72 void ProxyCrosSettingsProvider::DoSet(const std::string& path,
73 Value* in_value) { 73 const base::Value& in_value) {
74 if (!in_value) {
75 return;
76 }
77
78 chromeos::ProxyConfigServiceImpl* config_service = GetConfigService(); 74 chromeos::ProxyConfigServiceImpl* config_service = GetConfigService();
79 // Retrieve proxy config. 75 // Retrieve proxy config.
80 chromeos::ProxyConfigServiceImpl::ProxyConfig config; 76 chromeos::ProxyConfigServiceImpl::ProxyConfig config;
81 config_service->UIGetProxyConfig(&config); 77 config_service->UIGetProxyConfig(&config);
82 78
83 if (path == kProxyPacUrl) { 79 if (path == kProxyPacUrl) {
84 std::string val; 80 std::string val;
85 if (in_value->GetAsString(&val)) { 81 if (in_value.GetAsString(&val)) {
86 GURL url(val); 82 GURL url(val);
87 if (url.is_valid()) 83 if (url.is_valid())
88 config_service->UISetProxyConfigToPACScript(url); 84 config_service->UISetProxyConfigToPACScript(url);
89 else 85 else
90 config_service->UISetProxyConfigToAutoDetect(); 86 config_service->UISetProxyConfigToAutoDetect();
91 } 87 }
92 } else if (path == kProxySingleHttp) { 88 } else if (path == kProxySingleHttp) {
93 std::string val; 89 std::string val;
94 if (in_value->GetAsString(&val)) { 90 if (in_value.GetAsString(&val)) {
95 config_service->UISetProxyConfigToSingleProxy(CreateProxyServerFromHost( 91 config_service->UISetProxyConfigToSingleProxy(CreateProxyServerFromHost(
96 val, config.single_proxy, net::ProxyServer::SCHEME_HTTP)); 92 val, config.single_proxy, net::ProxyServer::SCHEME_HTTP));
97 } 93 }
98 } else if (path == kProxySingleHttpPort) { 94 } else if (path == kProxySingleHttpPort) {
99 int val; 95 int val;
100 if (in_value->GetAsInteger(&val)) { 96 if (in_value.GetAsInteger(&val)) {
101 config_service->UISetProxyConfigToSingleProxy(CreateProxyServerFromPort( 97 config_service->UISetProxyConfigToSingleProxy(CreateProxyServerFromPort(
102 val, config.single_proxy, net::ProxyServer::SCHEME_HTTP)); 98 val, config.single_proxy, net::ProxyServer::SCHEME_HTTP));
103 } 99 }
104 } else if (path == kProxyHttpUrl) { 100 } else if (path == kProxyHttpUrl) {
105 std::string val; 101 std::string val;
106 if (in_value->GetAsString(&val)) { 102 if (in_value.GetAsString(&val)) {
107 config_service->UISetProxyConfigToProxyPerScheme("http", 103 config_service->UISetProxyConfigToProxyPerScheme("http",
108 CreateProxyServerFromHost( 104 CreateProxyServerFromHost(
109 val, config.http_proxy, net::ProxyServer::SCHEME_HTTP)); 105 val, config.http_proxy, net::ProxyServer::SCHEME_HTTP));
110 } 106 }
111 } else if (path == kProxyHttpPort) { 107 } else if (path == kProxyHttpPort) {
112 int val; 108 int val;
113 if (in_value->GetAsInteger(&val)) { 109 if (in_value.GetAsInteger(&val)) {
114 config_service->UISetProxyConfigToProxyPerScheme("http", 110 config_service->UISetProxyConfigToProxyPerScheme("http",
115 CreateProxyServerFromPort( 111 CreateProxyServerFromPort(
116 val, config.http_proxy, net::ProxyServer::SCHEME_HTTP)); 112 val, config.http_proxy, net::ProxyServer::SCHEME_HTTP));
117 } 113 }
118 } else if (path == kProxyHttpsUrl) { 114 } else if (path == kProxyHttpsUrl) {
119 std::string val; 115 std::string val;
120 if (in_value->GetAsString(&val)) { 116 if (in_value.GetAsString(&val)) {
121 config_service->UISetProxyConfigToProxyPerScheme("https", 117 config_service->UISetProxyConfigToProxyPerScheme("https",
122 CreateProxyServerFromHost( 118 CreateProxyServerFromHost(
123 val, config.https_proxy, net::ProxyServer::SCHEME_HTTP)); 119 val, config.https_proxy, net::ProxyServer::SCHEME_HTTP));
124 } 120 }
125 } else if (path == kProxyHttpsPort) { 121 } else if (path == kProxyHttpsPort) {
126 int val; 122 int val;
127 if (in_value->GetAsInteger(&val)) { 123 if (in_value.GetAsInteger(&val)) {
128 config_service->UISetProxyConfigToProxyPerScheme("https", 124 config_service->UISetProxyConfigToProxyPerScheme("https",
129 CreateProxyServerFromPort( 125 CreateProxyServerFromPort(
130 val, config.https_proxy, net::ProxyServer::SCHEME_HTTP)); 126 val, config.https_proxy, net::ProxyServer::SCHEME_HTTP));
131 } 127 }
132 } else if (path == kProxyType) { 128 } else if (path == kProxyType) {
133 int val; 129 int val;
134 if (in_value->GetAsInteger(&val)) { 130 if (in_value.GetAsInteger(&val)) {
135 if (val == 3) { 131 if (val == 3) {
136 if (config.automatic_proxy.pac_url.is_valid()) 132 if (config.automatic_proxy.pac_url.is_valid())
137 config_service->UISetProxyConfigToPACScript( 133 config_service->UISetProxyConfigToPACScript(
138 config.automatic_proxy.pac_url); 134 config.automatic_proxy.pac_url);
139 else 135 else
140 config_service->UISetProxyConfigToAutoDetect(); 136 config_service->UISetProxyConfigToAutoDetect();
141 } else if (val == 2) { 137 } else if (val == 2) {
142 if (config.single_proxy.server.is_valid()) { 138 if (config.single_proxy.server.is_valid()) {
143 config_service->UISetProxyConfigToSingleProxy( 139 config_service->UISetProxyConfigToSingleProxy(
144 config.single_proxy.server); 140 config.single_proxy.server);
(...skipping 23 matching lines...) Expand all
168 config_service->UISetProxyConfigToProxyPerScheme("http", 164 config_service->UISetProxyConfigToProxyPerScheme("http",
169 net::ProxyServer()); 165 net::ProxyServer());
170 } 166 }
171 } 167 }
172 } else { 168 } else {
173 config_service->UISetProxyConfigToDirect(); 169 config_service->UISetProxyConfigToDirect();
174 } 170 }
175 } 171 }
176 } else if (path == kProxySingle) { 172 } else if (path == kProxySingle) {
177 bool val; 173 bool val;
178 if (in_value->GetAsBoolean(&val)) { 174 if (in_value.GetAsBoolean(&val)) {
179 if (val) 175 if (val)
180 config_service->UISetProxyConfigToSingleProxy( 176 config_service->UISetProxyConfigToSingleProxy(
181 config.single_proxy.server); 177 config.single_proxy.server);
182 else 178 else
183 config_service->UISetProxyConfigToProxyPerScheme("http", 179 config_service->UISetProxyConfigToProxyPerScheme("http",
184 config.http_proxy.server); 180 config.http_proxy.server);
185 } 181 }
186 } else if (path == kProxyFtpUrl) { 182 } else if (path == kProxyFtpUrl) {
187 std::string val; 183 std::string val;
188 if (in_value->GetAsString(&val)) { 184 if (in_value.GetAsString(&val)) {
189 config_service->UISetProxyConfigToProxyPerScheme("ftp", 185 config_service->UISetProxyConfigToProxyPerScheme("ftp",
190 CreateProxyServerFromHost( 186 CreateProxyServerFromHost(
191 val, config.ftp_proxy, net::ProxyServer::SCHEME_HTTP)); 187 val, config.ftp_proxy, net::ProxyServer::SCHEME_HTTP));
192 } 188 }
193 } else if (path == kProxyFtpPort) { 189 } else if (path == kProxyFtpPort) {
194 int val; 190 int val;
195 if (in_value->GetAsInteger(&val)) { 191 if (in_value.GetAsInteger(&val)) {
196 config_service->UISetProxyConfigToProxyPerScheme("ftp", 192 config_service->UISetProxyConfigToProxyPerScheme("ftp",
197 CreateProxyServerFromPort( 193 CreateProxyServerFromPort(
198 val, config.ftp_proxy, net::ProxyServer::SCHEME_HTTP)); 194 val, config.ftp_proxy, net::ProxyServer::SCHEME_HTTP));
199 } 195 }
200 } else if (path == kProxySocks) { 196 } else if (path == kProxySocks) {
201 std::string val; 197 std::string val;
202 if (in_value->GetAsString(&val)) { 198 if (in_value.GetAsString(&val)) {
203 config_service->UISetProxyConfigToProxyPerScheme("socks", 199 config_service->UISetProxyConfigToProxyPerScheme("socks",
204 CreateProxyServerFromHost(val, config.socks_proxy, 200 CreateProxyServerFromHost(val, config.socks_proxy,
205 StartsWithASCII(val, "socks5://", false) ? 201 StartsWithASCII(val, "socks5://", false) ?
206 net::ProxyServer::SCHEME_SOCKS5 : 202 net::ProxyServer::SCHEME_SOCKS5 :
207 net::ProxyServer::SCHEME_SOCKS4)); 203 net::ProxyServer::SCHEME_SOCKS4));
208 } 204 }
209 } else if (path == kProxySocksPort) { 205 } else if (path == kProxySocksPort) {
210 int val; 206 int val;
211 if (in_value->GetAsInteger(&val)) { 207 if (in_value.GetAsInteger(&val)) {
212 std::string host = config.socks_proxy.server.host_port_pair().host(); 208 std::string host = config.socks_proxy.server.host_port_pair().host();
213 config_service->UISetProxyConfigToProxyPerScheme("socks", 209 config_service->UISetProxyConfigToProxyPerScheme("socks",
214 CreateProxyServerFromPort(val, config.socks_proxy, 210 CreateProxyServerFromPort(val, config.socks_proxy,
215 StartsWithASCII(host, "socks5://", false) ? 211 StartsWithASCII(host, "socks5://", false) ?
216 net::ProxyServer::SCHEME_SOCKS5 : 212 net::ProxyServer::SCHEME_SOCKS5 :
217 net::ProxyServer::SCHEME_SOCKS4)); 213 net::ProxyServer::SCHEME_SOCKS4));
218 } 214 }
219 } else if (path == kProxyIgnoreList) { 215 } else if (path == kProxyIgnoreList) {
220 net::ProxyBypassRules bypass_rules; 216 net::ProxyBypassRules bypass_rules;
221 if (in_value->GetType() == Value::TYPE_LIST) { 217 if (in_value.GetType() == base::Value::TYPE_LIST) {
222 const ListValue* list_value = static_cast<const ListValue*>(in_value); 218 const base::ListValue& list_value =
223 for (size_t x = 0; x < list_value->GetSize(); x++) { 219 static_cast<const base::ListValue&>(in_value);
220 for (size_t x = 0; x < list_value.GetSize(); x++) {
224 std::string val; 221 std::string val;
225 if (list_value->GetString(x, &val)) { 222 if (list_value.GetString(x, &val)) {
226 bypass_rules.AddRuleFromString(val); 223 bypass_rules.AddRuleFromString(val);
227 } 224 }
228 } 225 }
229 config_service->UISetProxyConfigBypassRules(bypass_rules); 226 config_service->UISetProxyConfigBypassRules(bypass_rules);
230 } 227 }
231 } 228 }
232 } 229 }
233 230
234 const Value* ProxyCrosSettingsProvider::Get(const std::string& path) const { 231 const Value* ProxyCrosSettingsProvider::Get(const std::string& path) const {
235 bool found = false; 232 bool found = false;
236 Value* data = NULL; 233 base::Value* data = NULL;
237 chromeos::ProxyConfigServiceImpl* config_service = GetConfigService(); 234 chromeos::ProxyConfigServiceImpl* config_service = GetConfigService();
238 chromeos::ProxyConfigServiceImpl::ProxyConfig config; 235 chromeos::ProxyConfigServiceImpl::ProxyConfig config;
239 config_service->UIGetProxyConfig(&config); 236 config_service->UIGetProxyConfig(&config);
240 237
241 if (path == kProxyPacUrl) { 238 if (path == kProxyPacUrl) {
242 // Only show pacurl for pac-script mode. 239 // Only show pacurl for pac-script mode.
243 if (config.mode == 240 if (config.mode ==
244 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT && 241 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT &&
245 config.automatic_proxy.pac_url.is_valid()) { 242 config.automatic_proxy.pac_url.is_valid()) {
246 data = Value::CreateStringValue(config.automatic_proxy.pac_url.spec()); 243 data = Value::CreateStringValue(config.automatic_proxy.pac_url.spec());
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } 364 }
368 365
369 Value* ProxyCrosSettingsProvider::CreateServerPortValue( 366 Value* ProxyCrosSettingsProvider::CreateServerPortValue(
370 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) const { 367 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) const {
371 return proxy.server.is_valid() ? 368 return proxy.server.is_valid() ?
372 Value::CreateIntegerValue(proxy.server.host_port_pair().port()) : 369 Value::CreateIntegerValue(proxy.server.host_port_pair().port()) :
373 NULL; 370 NULL;
374 } 371 }
375 372
376 } // namespace chromeos 373 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698