| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } | 66 } |
| 67 | 67 |
| 68 void ChromeProxyConfigService::OnLazyPoll() { | 68 void ChromeProxyConfigService::OnLazyPoll() { |
| 69 if (base_service_.get()) | 69 if (base_service_.get()) |
| 70 base_service_->OnLazyPoll(); | 70 base_service_->OnLazyPoll(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void ChromeProxyConfigService::UpdateProxyConfig( | 73 void ChromeProxyConfigService::UpdateProxyConfig( |
| 74 ProxyPrefs::ConfigState config_state, | 74 ProxyPrefs::ConfigState config_state, |
| 75 const net::ProxyConfig& config) { | 75 const net::ProxyConfig& config) { |
| 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 76 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 77 | 77 |
| 78 pref_config_read_pending_ = false; | 78 pref_config_read_pending_ = false; |
| 79 pref_config_state_ = config_state; | 79 pref_config_state_ = config_state; |
| 80 pref_config_ = config; | 80 pref_config_ = config; |
| 81 | 81 |
| 82 if (!observers_.might_have_observers()) | 82 if (!observers_.might_have_observers()) |
| 83 return; | 83 return; |
| 84 | 84 |
| 85 // Evaluate the proxy configuration. If GetLatestProxyConfig returns | 85 // Evaluate the proxy configuration. If GetLatestProxyConfig returns |
| 86 // CONFIG_PENDING, we are using the system proxy service, but it doesn't have | 86 // CONFIG_PENDING, we are using the system proxy service, but it doesn't have |
| 87 // a valid configuration yet. Once it is ready, OnProxyConfigChanged() will be | 87 // a valid configuration yet. Once it is ready, OnProxyConfigChanged() will be |
| 88 // called and broadcast the proxy configuration. | 88 // called and broadcast the proxy configuration. |
| 89 // Note: If a switch between a preference proxy configuration and the system | 89 // Note: If a switch between a preference proxy configuration and the system |
| 90 // proxy configuration occurs an unnecessary notification might get send if | 90 // proxy configuration occurs an unnecessary notification might get send if |
| 91 // the two configurations agree. This case should be rare however, so we don't | 91 // the two configurations agree. This case should be rare however, so we don't |
| 92 // handle that case specially. | 92 // handle that case specially. |
| 93 net::ProxyConfig new_config; | 93 net::ProxyConfig new_config; |
| 94 ConfigAvailability availability = GetLatestProxyConfig(&new_config); | 94 ConfigAvailability availability = GetLatestProxyConfig(&new_config); |
| 95 if (availability != CONFIG_PENDING) { | 95 if (availability != CONFIG_PENDING) { |
| 96 FOR_EACH_OBSERVER(net::ProxyConfigService::Observer, observers_, | 96 FOR_EACH_OBSERVER(net::ProxyConfigService::Observer, observers_, |
| 97 OnProxyConfigChanged(new_config, availability)); | 97 OnProxyConfigChanged(new_config, availability)); |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 | 100 |
| 101 void ChromeProxyConfigService::OnProxyConfigChanged( | 101 void ChromeProxyConfigService::OnProxyConfigChanged( |
| 102 const net::ProxyConfig& config, | 102 const net::ProxyConfig& config, |
| 103 ConfigAvailability availability) { | 103 ConfigAvailability availability) { |
| 104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 104 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 105 | 105 |
| 106 // Check whether there is a proxy configuration defined by preferences. In | 106 // Check whether there is a proxy configuration defined by preferences. In |
| 107 // this case that proxy configuration takes precedence and the change event | 107 // this case that proxy configuration takes precedence and the change event |
| 108 // from the delegate proxy service can be disregarded. | 108 // from the delegate proxy service can be disregarded. |
| 109 if (!PrefProxyConfigTrackerImpl::PrefPrecedes(pref_config_state_)) { | 109 if (!PrefProxyConfigTrackerImpl::PrefPrecedes(pref_config_state_)) { |
| 110 net::ProxyConfig actual_config; | 110 net::ProxyConfig actual_config; |
| 111 availability = GetLatestProxyConfig(&actual_config); | 111 availability = GetLatestProxyConfig(&actual_config); |
| 112 FOR_EACH_OBSERVER(net::ProxyConfigService::Observer, observers_, | 112 FOR_EACH_OBSERVER(net::ProxyConfigService::Observer, observers_, |
| 113 OnProxyConfigChanged(actual_config, availability)); | 113 OnProxyConfigChanged(actual_config, availability)); |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 void ChromeProxyConfigService::RegisterObserver() { | 117 void ChromeProxyConfigService::RegisterObserver() { |
| 118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 118 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 119 if (!registered_observer_ && base_service_.get()) { | 119 if (!registered_observer_ && base_service_.get()) { |
| 120 base_service_->AddObserver(this); | 120 base_service_->AddObserver(this); |
| 121 registered_observer_ = true; | 121 registered_observer_ = true; |
| 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) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 147 new ChromeProxyConfigService(base_service.release()); | 147 new ChromeProxyConfigService(base_service.release()); |
| 148 VLOG(1) << this << ": set chrome proxy config service to " | 148 VLOG(1) << this << ": set chrome proxy config service to " |
| 149 << chrome_proxy_config_service_; | 149 << chrome_proxy_config_service_; |
| 150 if (chrome_proxy_config_service_ && update_pending_) | 150 if (chrome_proxy_config_service_ && update_pending_) |
| 151 OnProxyConfigChanged(config_state_, pref_config_); | 151 OnProxyConfigChanged(config_state_, pref_config_); |
| 152 | 152 |
| 153 return scoped_ptr<net::ProxyConfigService>(chrome_proxy_config_service_); | 153 return scoped_ptr<net::ProxyConfigService>(chrome_proxy_config_service_); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void PrefProxyConfigTrackerImpl::DetachFromPrefService() { | 156 void PrefProxyConfigTrackerImpl::DetachFromPrefService() { |
| 157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 157 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 158 // Stop notifications. | 158 // Stop notifications. |
| 159 proxy_prefs_.RemoveAll(); | 159 proxy_prefs_.RemoveAll(); |
| 160 pref_service_ = NULL; | 160 pref_service_ = NULL; |
| 161 chrome_proxy_config_service_ = NULL; | 161 chrome_proxy_config_service_ = NULL; |
| 162 } | 162 } |
| 163 | 163 |
| 164 // static | 164 // static |
| 165 bool PrefProxyConfigTrackerImpl::PrefPrecedes( | 165 bool PrefProxyConfigTrackerImpl::PrefPrecedes( |
| 166 ProxyPrefs::ConfigState config_state) { | 166 ProxyPrefs::ConfigState config_state) { |
| 167 return config_state == ProxyPrefs::CONFIG_POLICY || | 167 return config_state == ProxyPrefs::CONFIG_POLICY || |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 user_prefs::PrefRegistrySyncable* pref_service) { | 212 user_prefs::PrefRegistrySyncable* pref_service) { |
| 213 base::DictionaryValue* default_settings = | 213 base::DictionaryValue* default_settings = |
| 214 ProxyConfigDictionary::CreateSystem(); | 214 ProxyConfigDictionary::CreateSystem(); |
| 215 pref_service->RegisterDictionaryPref(prefs::kProxy, default_settings); | 215 pref_service->RegisterDictionaryPref(prefs::kProxy, default_settings); |
| 216 } | 216 } |
| 217 | 217 |
| 218 // static | 218 // static |
| 219 ProxyPrefs::ConfigState PrefProxyConfigTrackerImpl::ReadPrefConfig( | 219 ProxyPrefs::ConfigState PrefProxyConfigTrackerImpl::ReadPrefConfig( |
| 220 const PrefService* pref_service, | 220 const PrefService* pref_service, |
| 221 net::ProxyConfig* config) { | 221 net::ProxyConfig* config) { |
| 222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 222 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 223 | 223 |
| 224 // Clear the configuration and source. | 224 // Clear the configuration and source. |
| 225 *config = net::ProxyConfig(); | 225 *config = net::ProxyConfig(); |
| 226 ProxyPrefs::ConfigState config_state = ProxyPrefs::CONFIG_UNSET; | 226 ProxyPrefs::ConfigState config_state = ProxyPrefs::CONFIG_UNSET; |
| 227 | 227 |
| 228 const PrefService::Preference* pref = | 228 const PrefService::Preference* pref = |
| 229 pref_service->FindPreference(prefs::kProxy); | 229 pref_service->FindPreference(prefs::kProxy); |
| 230 DCHECK(pref); | 230 DCHECK(pref); |
| 231 | 231 |
| 232 const base::DictionaryValue* dict = | 232 const base::DictionaryValue* dict = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 245 } else { | 245 } else { |
| 246 config_state = ProxyPrefs::CONFIG_FALLBACK; | 246 config_state = ProxyPrefs::CONFIG_FALLBACK; |
| 247 } | 247 } |
| 248 } | 248 } |
| 249 | 249 |
| 250 return config_state; | 250 return config_state; |
| 251 } | 251 } |
| 252 | 252 |
| 253 ProxyPrefs::ConfigState PrefProxyConfigTrackerImpl::GetProxyConfig( | 253 ProxyPrefs::ConfigState PrefProxyConfigTrackerImpl::GetProxyConfig( |
| 254 net::ProxyConfig* config) { | 254 net::ProxyConfig* config) { |
| 255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 255 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 256 if (config_state_ != ProxyPrefs::CONFIG_UNSET) | 256 if (config_state_ != ProxyPrefs::CONFIG_UNSET) |
| 257 *config = pref_config_; | 257 *config = pref_config_; |
| 258 return config_state_; | 258 return config_state_; |
| 259 } | 259 } |
| 260 | 260 |
| 261 void PrefProxyConfigTrackerImpl::OnProxyConfigChanged( | 261 void PrefProxyConfigTrackerImpl::OnProxyConfigChanged( |
| 262 ProxyPrefs::ConfigState config_state, | 262 ProxyPrefs::ConfigState config_state, |
| 263 const net::ProxyConfig& config) { | 263 const net::ProxyConfig& config) { |
| 264 if (!chrome_proxy_config_service_) { | 264 if (!chrome_proxy_config_service_) { |
| 265 VLOG(1) << "No chrome proxy config service to push to UpdateProxyConfig"; | 265 VLOG(1) << "No chrome proxy config service to push to UpdateProxyConfig"; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 } | 330 } |
| 331 case ProxyPrefs::kModeCount: { | 331 case ProxyPrefs::kModeCount: { |
| 332 // Fall through to NOTREACHED(). | 332 // Fall through to NOTREACHED(). |
| 333 } | 333 } |
| 334 } | 334 } |
| 335 NOTREACHED() << "Unknown proxy mode, falling back to system settings."; | 335 NOTREACHED() << "Unknown proxy mode, falling back to system settings."; |
| 336 return false; | 336 return false; |
| 337 } | 337 } |
| 338 | 338 |
| 339 void PrefProxyConfigTrackerImpl::OnProxyPrefChanged() { | 339 void PrefProxyConfigTrackerImpl::OnProxyPrefChanged() { |
| 340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 340 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 341 net::ProxyConfig new_config; | 341 net::ProxyConfig new_config; |
| 342 ProxyPrefs::ConfigState config_state = ReadPrefConfig(pref_service_, | 342 ProxyPrefs::ConfigState config_state = ReadPrefConfig(pref_service_, |
| 343 &new_config); | 343 &new_config); |
| 344 if (config_state_ != config_state || | 344 if (config_state_ != config_state || |
| 345 (config_state_ != ProxyPrefs::CONFIG_UNSET && | 345 (config_state_ != ProxyPrefs::CONFIG_UNSET && |
| 346 !pref_config_.Equals(new_config))) { | 346 !pref_config_.Equals(new_config))) { |
| 347 config_state_ = config_state; | 347 config_state_ = config_state; |
| 348 if (config_state_ != ProxyPrefs::CONFIG_UNSET) | 348 if (config_state_ != ProxyPrefs::CONFIG_UNSET) |
| 349 pref_config_ = new_config; | 349 pref_config_ = new_config; |
| 350 update_pending_ = true; | 350 update_pending_ = true; |
| 351 } | 351 } |
| 352 if (update_pending_) | 352 if (update_pending_) |
| 353 OnProxyConfigChanged(config_state, new_config); | 353 OnProxyConfigChanged(config_state, new_config); |
| 354 } | 354 } |
| OLD | NEW |