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/browser/chromeos/proxy_config_service_impl.h" | 5 #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/chromeos/login/user_manager.h" | 13 #include "chrome/browser/chromeos/login/user_manager.h" |
| 14 #include "chrome/browser/chromeos/net/proxy_config_handler.h" |
14 #include "chrome/browser/policy/browser_policy_connector.h" | 15 #include "chrome/browser/policy/browser_policy_connector.h" |
15 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" | 16 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" |
16 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 17 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
17 #include "chrome/browser/prefs/proxy_prefs.h" | 18 #include "chrome/browser/prefs/proxy_prefs.h" |
18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
19 #include "chromeos/network/network_profile.h" | 20 #include "chromeos/network/network_profile.h" |
20 #include "chromeos/network/network_profile_handler.h" | 21 #include "chromeos/network/network_profile_handler.h" |
21 #include "chromeos/network/network_state.h" | 22 #include "chromeos/network/network_state.h" |
22 #include "chromeos/network/network_state_handler.h" | 23 #include "chromeos/network/network_state_handler.h" |
23 #include "chromeos/network/onc/onc_utils.h" | 24 #include "chromeos/network/onc/onc_utils.h" |
24 #include "components/user_prefs/pref_registry_syncable.h" | 25 #include "components/user_prefs/pref_registry_syncable.h" |
25 | 26 |
26 namespace chromeos { | 27 namespace chromeos { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 // Convert and store the proxy config of |pref_proxy_config| of | 31 // Writes the proxy config of |network| to |proxy_config|. Returns false if no |
31 // ProxyConfigDictionary format to |proxy_config|. Returns true if | 32 // proxy was configured for this network. |
32 // |pref_proxy_config| was not empty and if it was successfully converted. | 33 bool GetProxyConfig(const NetworkState& network, |
33 bool ParseProxyConfig(const base::DictionaryValue& pref_proxy_config, | 34 net::ProxyConfig* proxy_config) { |
34 net::ProxyConfig* proxy_config) { | 35 scoped_ptr<ProxyConfigDictionary> proxy_dict = |
35 if (pref_proxy_config.empty()) | 36 proxy_config::GetProxyConfigForNetwork(network); |
| 37 if (!proxy_dict) |
36 return false; | 38 return false; |
37 ProxyConfigDictionary proxy_dict(&pref_proxy_config); | 39 return PrefProxyConfigTrackerImpl::PrefConfigToNetConfig(*proxy_dict, |
38 return PrefProxyConfigTrackerImpl::PrefConfigToNetConfig(proxy_dict, | |
39 proxy_config); | 40 proxy_config); |
40 } | 41 } |
41 | 42 |
42 } // namespace | 43 } // namespace |
43 | 44 |
44 ProxyConfigServiceImpl::ProxyConfigServiceImpl(PrefService* pref_service) | 45 ProxyConfigServiceImpl::ProxyConfigServiceImpl(PrefService* pref_service) |
45 : PrefProxyConfigTrackerImpl(pref_service), | 46 : PrefProxyConfigTrackerImpl(pref_service), |
46 active_config_state_(ProxyPrefs::CONFIG_UNSET), | 47 active_config_state_(ProxyPrefs::CONFIG_UNSET), |
47 pointer_factory_(this) { | 48 pointer_factory_(this) { |
48 | 49 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 net::ProxyConfigService::ConfigAvailability network_availability = | 180 net::ProxyConfigService::ConfigAvailability network_availability = |
180 net::ProxyConfigService::CONFIG_UNSET; | 181 net::ProxyConfigService::CONFIG_UNSET; |
181 bool ignore_proxy = true; | 182 bool ignore_proxy = true; |
182 if (network) { | 183 if (network) { |
183 ignore_proxy = | 184 ignore_proxy = |
184 IgnoreProxy(prefs(), network->profile_path(), network->onc_source()); | 185 IgnoreProxy(prefs(), network->profile_path(), network->onc_source()); |
185 // If network is shared but use-shared-proxies is off, use direct mode. | 186 // If network is shared but use-shared-proxies is off, use direct mode. |
186 if (ignore_proxy) { | 187 if (ignore_proxy) { |
187 VLOG(1) << "Shared network && !use-shared-proxies, use direct"; | 188 VLOG(1) << "Shared network && !use-shared-proxies, use direct"; |
188 network_availability = net::ProxyConfigService::CONFIG_VALID; | 189 network_availability = net::ProxyConfigService::CONFIG_VALID; |
189 } else if (ParseProxyConfig(network->proxy_config(), &network_config)) { | 190 } else if (chromeos::GetProxyConfig(*network, &network_config)) { |
190 // Network is private or shared with user using shared proxies. | 191 // Network is private or shared with user using shared proxies. |
191 VLOG(1) << this << ": using network proxy: " | 192 VLOG(1) << this << ": using network proxy: " |
192 << network->proxy_config(); | 193 << network->proxy_config(); |
193 network_availability = net::ProxyConfigService::CONFIG_VALID; | 194 network_availability = net::ProxyConfigService::CONFIG_VALID; |
194 } | 195 } |
195 } | 196 } |
196 | 197 |
197 // Determine effective proxy config, either from prefs or network. | 198 // Determine effective proxy config, either from prefs or network. |
198 ProxyPrefs::ConfigState effective_config_state; | 199 ProxyPrefs::ConfigState effective_config_state; |
199 net::ProxyConfig effective_config; | 200 net::ProxyConfig effective_config; |
(...skipping 29 matching lines...) Expand all Loading... |
229 scoped_ptr<base::DictionaryValue> config_dict( | 230 scoped_ptr<base::DictionaryValue> config_dict( |
230 effective_config.ToValue()); | 231 effective_config.ToValue()); |
231 VLOG(1) << this << ": Proxy changed: " | 232 VLOG(1) << this << ": Proxy changed: " |
232 << ProxyPrefs::ConfigStateToDebugString(active_config_state_) | 233 << ProxyPrefs::ConfigStateToDebugString(active_config_state_) |
233 << ", " << *config_dict; | 234 << ", " << *config_dict; |
234 } | 235 } |
235 } | 236 } |
236 } | 237 } |
237 | 238 |
238 } // namespace chromeos | 239 } // namespace chromeos |
OLD | NEW |