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 "chromeos/network/proxy/proxy_config_service_impl.h" | 5 #include "chromeos/network/proxy/proxy_config_service_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 ProxyConfigServiceImpl::ProxyConfigServiceImpl( | 51 ProxyConfigServiceImpl::ProxyConfigServiceImpl( |
52 PrefService* profile_prefs, | 52 PrefService* profile_prefs, |
53 PrefService* local_state_prefs, | 53 PrefService* local_state_prefs, |
54 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) | 54 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
55 : PrefProxyConfigTrackerImpl( | 55 : PrefProxyConfigTrackerImpl( |
56 profile_prefs ? profile_prefs : local_state_prefs, | 56 profile_prefs ? profile_prefs : local_state_prefs, |
57 io_task_runner), | 57 io_task_runner), |
58 active_config_state_(ProxyPrefs::CONFIG_UNSET), | |
59 profile_prefs_(profile_prefs), | 58 profile_prefs_(profile_prefs), |
60 local_state_prefs_(local_state_prefs), | 59 local_state_prefs_(local_state_prefs), |
61 pointer_factory_(this) { | 60 pointer_factory_(this) { |
62 const base::Closure proxy_change_callback = base::Bind( | 61 const base::Closure proxy_change_callback = base::Bind( |
63 &ProxyConfigServiceImpl::OnProxyPrefChanged, base::Unretained(this)); | 62 &ProxyConfigServiceImpl::OnProxyPrefChanged, base::Unretained(this)); |
64 | 63 |
65 if (profile_prefs) { | 64 if (profile_prefs) { |
66 profile_pref_registrar_.Init(profile_prefs); | 65 profile_pref_registrar_.Init(profile_prefs); |
67 profile_pref_registrar_.Add(::onc::prefs::kOpenNetworkConfiguration, | 66 profile_pref_registrar_.Add(::onc::prefs::kOpenNetworkConfiguration, |
68 proxy_change_callback); | 67 proxy_change_callback); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 } | 248 } |
250 } | 249 } |
251 | 250 |
252 // Determine effective proxy config, either from prefs or network. | 251 // Determine effective proxy config, either from prefs or network. |
253 ProxyPrefs::ConfigState effective_config_state; | 252 ProxyPrefs::ConfigState effective_config_state; |
254 net::ProxyConfig effective_config; | 253 net::ProxyConfig effective_config; |
255 GetEffectiveProxyConfig(pref_state, pref_config, network_availability, | 254 GetEffectiveProxyConfig(pref_state, pref_config, network_availability, |
256 network_config, ignore_proxy, &effective_config_state, | 255 network_config, ignore_proxy, &effective_config_state, |
257 &effective_config); | 256 &effective_config); |
258 | 257 |
259 bool config_changed = active_config_state_ != effective_config_state || | 258 // If effective config is from system (i.e. network), it's considered a |
260 (active_config_state_ != ProxyPrefs::CONFIG_UNSET && | 259 // special kind of prefs that ranks below policy/extension but above |
261 !active_config_.Equals(effective_config)); | 260 // others, so bump it up to CONFIG_OTHER_PRECEDE to force its precedence |
262 if (config_changed) { // Activate and store new effective config. | 261 // when PrefProxyConfigTrackerImpl pushes it to ChromeProxyConfigService. |
263 active_config_state_ = effective_config_state; | 262 if (effective_config_state == ProxyPrefs::CONFIG_SYSTEM) |
264 if (active_config_state_ != ProxyPrefs::CONFIG_UNSET) | 263 effective_config_state = ProxyPrefs::CONFIG_OTHER_PRECEDE; |
265 active_config_ = effective_config; | 264 // If config is manual, add rule to bypass local host. |
266 // If effective config is from system (i.e. network), it's considered a | 265 if (effective_config.proxy_rules().type != |
267 // special kind of prefs that ranks below policy/extension but above | 266 net::ProxyConfig::ProxyRules::TYPE_NO_RULES) { |
268 // others, so bump it up to CONFIG_OTHER_PRECEDE to force its precedence | 267 effective_config.proxy_rules().bypass_rules.AddRuleToBypassLocal(); |
269 // when PrefProxyConfigTrackerImpl pushes it to ChromeProxyConfigService. | 268 } |
270 if (effective_config_state == ProxyPrefs::CONFIG_SYSTEM) | 269 PrefProxyConfigTrackerImpl::OnProxyConfigChanged(effective_config_state, |
271 effective_config_state = ProxyPrefs::CONFIG_OTHER_PRECEDE; | 270 effective_config); |
272 // If config is manual, add rule to bypass local host. | 271 if (VLOG_IS_ON(1)) { |
273 if (effective_config.proxy_rules().type != | 272 std::unique_ptr<base::DictionaryValue> config_dict( |
274 net::ProxyConfig::ProxyRules::TYPE_NO_RULES) { | 273 effective_config.ToValue()); |
275 effective_config.proxy_rules().bypass_rules.AddRuleToBypassLocal(); | 274 VLOG(1) << this << ": Proxy changed: " |
276 } | 275 << ProxyPrefs::ConfigStateToDebugString(effective_config_state) |
277 PrefProxyConfigTrackerImpl::OnProxyConfigChanged(effective_config_state, | 276 << ", " << *config_dict; |
278 effective_config); | |
279 if (VLOG_IS_ON(1)) { | |
280 std::unique_ptr<base::DictionaryValue> config_dict( | |
281 effective_config.ToValue()); | |
282 VLOG(1) << this << ": Proxy changed: " | |
283 << ProxyPrefs::ConfigStateToDebugString(active_config_state_) | |
284 << ", " << *config_dict; | |
285 } | |
286 } | 277 } |
287 } | 278 } |
288 | 279 |
289 } // namespace chromeos | 280 } // namespace chromeos |
OLD | NEW |