| OLD | NEW |
| 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/net/pref_proxy_config_tracker_impl.h" | 5 #include "chrome/browser/net/pref_proxy_config_tracker_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/prefs/pref_registry_simple.h" | 8 #include "base/prefs/pref_registry_simple.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 | 124 |
| 125 //========================= PrefProxyConfigTrackerImpl ========================= | 125 //========================= PrefProxyConfigTrackerImpl ========================= |
| 126 | 126 |
| 127 PrefProxyConfigTrackerImpl::PrefProxyConfigTrackerImpl( | 127 PrefProxyConfigTrackerImpl::PrefProxyConfigTrackerImpl( |
| 128 PrefService* pref_service) | 128 PrefService* pref_service) |
| 129 : pref_service_(pref_service), | 129 : pref_service_(pref_service), |
| 130 chrome_proxy_config_service_(NULL), | 130 chrome_proxy_config_service_(NULL), |
| 131 update_pending_(true) { | 131 update_pending_(true) { |
| 132 config_state_ = ReadPrefConfig(&pref_config_); | 132 config_state_ = ReadPrefConfig(pref_service_, &pref_config_); |
| 133 proxy_prefs_.Init(pref_service); | 133 proxy_prefs_.Init(pref_service); |
| 134 proxy_prefs_.Add(prefs::kProxy, | 134 proxy_prefs_.Add(prefs::kProxy, |
| 135 base::Bind(&PrefProxyConfigTrackerImpl::OnProxyPrefChanged, | 135 base::Bind(&PrefProxyConfigTrackerImpl::OnProxyPrefChanged, |
| 136 base::Unretained(this))); | 136 base::Unretained(this))); |
| 137 } | 137 } |
| 138 | 138 |
| 139 PrefProxyConfigTrackerImpl::~PrefProxyConfigTrackerImpl() { | 139 PrefProxyConfigTrackerImpl::~PrefProxyConfigTrackerImpl() { |
| 140 DCHECK(pref_service_ == NULL); | 140 DCHECK(pref_service_ == NULL); |
| 141 } | 141 } |
| 142 | 142 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 // static | 205 // static |
| 206 void PrefProxyConfigTrackerImpl::RegisterUserPrefs( | 206 void PrefProxyConfigTrackerImpl::RegisterUserPrefs( |
| 207 user_prefs::PrefRegistrySyncable* pref_service) { | 207 user_prefs::PrefRegistrySyncable* pref_service) { |
| 208 DictionaryValue* default_settings = ProxyConfigDictionary::CreateSystem(); | 208 DictionaryValue* default_settings = ProxyConfigDictionary::CreateSystem(); |
| 209 pref_service->RegisterDictionaryPref( | 209 pref_service->RegisterDictionaryPref( |
| 210 prefs::kProxy, | 210 prefs::kProxy, |
| 211 default_settings, | 211 default_settings, |
| 212 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 212 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 213 } | 213 } |
| 214 | 214 |
| 215 // static |
| 216 ProxyPrefs::ConfigState PrefProxyConfigTrackerImpl::ReadPrefConfig( |
| 217 const PrefService* pref_service, net::ProxyConfig* config) { |
| 218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 219 |
| 220 // Clear the configuration and source. |
| 221 *config = net::ProxyConfig(); |
| 222 ProxyPrefs::ConfigState config_state = ProxyPrefs::CONFIG_UNSET; |
| 223 |
| 224 const PrefService::Preference* pref = |
| 225 pref_service->FindPreference(prefs::kProxy); |
| 226 DCHECK(pref); |
| 227 |
| 228 const DictionaryValue* dict = pref_service->GetDictionary(prefs::kProxy); |
| 229 DCHECK(dict); |
| 230 ProxyConfigDictionary proxy_dict(dict); |
| 231 |
| 232 if (PrefConfigToNetConfig(proxy_dict, config)) { |
| 233 if (!pref->IsUserModifiable() || pref->HasUserSetting()) { |
| 234 if (pref->IsManaged()) |
| 235 config_state = ProxyPrefs::CONFIG_POLICY; |
| 236 else if (pref->IsExtensionControlled()) |
| 237 config_state = ProxyPrefs::CONFIG_EXTENSION; |
| 238 else |
| 239 config_state = ProxyPrefs::CONFIG_OTHER_PRECEDE; |
| 240 } else { |
| 241 config_state = ProxyPrefs::CONFIG_FALLBACK; |
| 242 } |
| 243 } |
| 244 |
| 245 return config_state; |
| 246 } |
| 247 |
| 215 ProxyPrefs::ConfigState PrefProxyConfigTrackerImpl::GetProxyConfig( | 248 ProxyPrefs::ConfigState PrefProxyConfigTrackerImpl::GetProxyConfig( |
| 216 net::ProxyConfig* config) { | 249 net::ProxyConfig* config) { |
| 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 218 if (config_state_ != ProxyPrefs::CONFIG_UNSET) | 251 if (config_state_ != ProxyPrefs::CONFIG_UNSET) |
| 219 *config = pref_config_; | 252 *config = pref_config_; |
| 220 return config_state_; | 253 return config_state_; |
| 221 } | 254 } |
| 222 | 255 |
| 223 void PrefProxyConfigTrackerImpl::OnProxyConfigChanged( | 256 void PrefProxyConfigTrackerImpl::OnProxyConfigChanged( |
| 224 ProxyPrefs::ConfigState config_state, | 257 ProxyPrefs::ConfigState config_state, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 // Fall through to NOTREACHED(). | 327 // Fall through to NOTREACHED(). |
| 295 } | 328 } |
| 296 } | 329 } |
| 297 NOTREACHED() << "Unknown proxy mode, falling back to system settings."; | 330 NOTREACHED() << "Unknown proxy mode, falling back to system settings."; |
| 298 return false; | 331 return false; |
| 299 } | 332 } |
| 300 | 333 |
| 301 void PrefProxyConfigTrackerImpl::OnProxyPrefChanged() { | 334 void PrefProxyConfigTrackerImpl::OnProxyPrefChanged() { |
| 302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 335 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 303 net::ProxyConfig new_config; | 336 net::ProxyConfig new_config; |
| 304 ProxyPrefs::ConfigState config_state = ReadPrefConfig(&new_config); | 337 ProxyPrefs::ConfigState config_state = ReadPrefConfig(pref_service_, |
| 338 &new_config); |
| 305 if (config_state_ != config_state || | 339 if (config_state_ != config_state || |
| 306 (config_state_ != ProxyPrefs::CONFIG_UNSET && | 340 (config_state_ != ProxyPrefs::CONFIG_UNSET && |
| 307 !pref_config_.Equals(new_config))) { | 341 !pref_config_.Equals(new_config))) { |
| 308 config_state_ = config_state; | 342 config_state_ = config_state; |
| 309 if (config_state_ != ProxyPrefs::CONFIG_UNSET) | 343 if (config_state_ != ProxyPrefs::CONFIG_UNSET) |
| 310 pref_config_ = new_config; | 344 pref_config_ = new_config; |
| 311 update_pending_ = true; | 345 update_pending_ = true; |
| 312 } | 346 } |
| 313 if (update_pending_) | 347 if (update_pending_) |
| 314 OnProxyConfigChanged(config_state, new_config); | 348 OnProxyConfigChanged(config_state, new_config); |
| 315 } | 349 } |
| 316 | |
| 317 ProxyPrefs::ConfigState PrefProxyConfigTrackerImpl::ReadPrefConfig( | |
| 318 net::ProxyConfig* config) { | |
| 319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 320 | |
| 321 // Clear the configuration and source. | |
| 322 *config = net::ProxyConfig(); | |
| 323 ProxyPrefs::ConfigState config_state = ProxyPrefs::CONFIG_UNSET; | |
| 324 | |
| 325 const PrefService::Preference* pref = | |
| 326 pref_service_->FindPreference(prefs::kProxy); | |
| 327 DCHECK(pref); | |
| 328 | |
| 329 const DictionaryValue* dict = pref_service_->GetDictionary(prefs::kProxy); | |
| 330 DCHECK(dict); | |
| 331 ProxyConfigDictionary proxy_dict(dict); | |
| 332 | |
| 333 if (PrefConfigToNetConfig(proxy_dict, config)) { | |
| 334 if (!pref->IsUserModifiable() || pref->HasUserSetting()) { | |
| 335 if (pref->IsManaged()) | |
| 336 config_state = ProxyPrefs::CONFIG_POLICY; | |
| 337 else if (pref->IsExtensionControlled()) | |
| 338 config_state = ProxyPrefs::CONFIG_EXTENSION; | |
| 339 else | |
| 340 config_state = ProxyPrefs::CONFIG_OTHER_PRECEDE; | |
| 341 } else { | |
| 342 config_state = ProxyPrefs::CONFIG_FALLBACK; | |
| 343 } | |
| 344 } | |
| 345 | |
| 346 return config_state; | |
| 347 } | |
| OLD | NEW |