| 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 "components/proxy_config/pref_proxy_config_tracker_impl.h" | 5 #include "components/proxy_config/pref_proxy_config_tracker_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 //========================= PrefProxyConfigTrackerImpl ========================= | 127 //========================= PrefProxyConfigTrackerImpl ========================= |
| 128 | 128 |
| 129 PrefProxyConfigTrackerImpl::PrefProxyConfigTrackerImpl( | 129 PrefProxyConfigTrackerImpl::PrefProxyConfigTrackerImpl( |
| 130 PrefService* pref_service, | 130 PrefService* pref_service, |
| 131 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) | 131 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
| 132 : pref_service_(pref_service), | 132 : pref_service_(pref_service), |
| 133 proxy_config_service_impl_(NULL), | 133 proxy_config_service_impl_(NULL), |
| 134 update_pending_(true), | |
| 135 io_task_runner_(io_task_runner) { | 134 io_task_runner_(io_task_runner) { |
| 136 config_state_ = ReadPrefConfig(pref_service_, &pref_config_); | 135 config_state_ = ReadPrefConfig(pref_service_, &pref_config_); |
| 137 proxy_prefs_.Init(pref_service); | 136 proxy_prefs_.Init(pref_service); |
| 138 proxy_prefs_.Add(proxy_config::prefs::kProxy, | 137 proxy_prefs_.Add(proxy_config::prefs::kProxy, |
| 139 base::Bind(&PrefProxyConfigTrackerImpl::OnProxyPrefChanged, | 138 base::Bind(&PrefProxyConfigTrackerImpl::OnProxyPrefChanged, |
| 140 base::Unretained(this))); | 139 base::Unretained(this))); |
| 141 } | 140 } |
| 142 | 141 |
| 143 PrefProxyConfigTrackerImpl::~PrefProxyConfigTrackerImpl() { | 142 PrefProxyConfigTrackerImpl::~PrefProxyConfigTrackerImpl() { |
| 144 DCHECK(pref_service_ == NULL); | 143 DCHECK(pref_service_ == NULL); |
| 145 } | 144 } |
| 146 | 145 |
| 147 std::unique_ptr<net::ProxyConfigService> | 146 std::unique_ptr<net::ProxyConfigService> |
| 148 PrefProxyConfigTrackerImpl::CreateTrackingProxyConfigService( | 147 PrefProxyConfigTrackerImpl::CreateTrackingProxyConfigService( |
| 149 std::unique_ptr<net::ProxyConfigService> base_service) { | 148 std::unique_ptr<net::ProxyConfigService> base_service) { |
| 150 DCHECK(!proxy_config_service_impl_); | 149 DCHECK(!proxy_config_service_impl_); |
| 151 proxy_config_service_impl_ = new ProxyConfigServiceImpl( | 150 proxy_config_service_impl_ = new ProxyConfigServiceImpl( |
| 152 std::move(base_service), config_state_, pref_config_); | 151 std::move(base_service), config_state_, pref_config_); |
| 153 VLOG(1) << this << ": set chrome proxy config service to " | 152 VLOG(1) << this << ": set chrome proxy config service to " |
| 154 << proxy_config_service_impl_; | 153 << proxy_config_service_impl_; |
| 155 update_pending_ = false; | |
| 156 | 154 |
| 157 return std::unique_ptr<net::ProxyConfigService>(proxy_config_service_impl_); | 155 return std::unique_ptr<net::ProxyConfigService>(proxy_config_service_impl_); |
| 158 } | 156 } |
| 159 | 157 |
| 160 void PrefProxyConfigTrackerImpl::DetachFromPrefService() { | 158 void PrefProxyConfigTrackerImpl::DetachFromPrefService() { |
| 161 DCHECK(thread_checker_.CalledOnValidThread()); | 159 DCHECK(thread_checker_.CalledOnValidThread()); |
| 162 // Stop notifications. | 160 // Stop notifications. |
| 163 proxy_prefs_.RemoveAll(); | 161 proxy_prefs_.RemoveAll(); |
| 164 pref_service_ = NULL; | 162 pref_service_ = NULL; |
| 165 proxy_config_service_impl_ = NULL; | 163 proxy_config_service_impl_ = NULL; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 net::ProxyConfig* config) { | 258 net::ProxyConfig* config) { |
| 261 DCHECK(thread_checker_.CalledOnValidThread()); | 259 DCHECK(thread_checker_.CalledOnValidThread()); |
| 262 if (config_state_ != ProxyPrefs::CONFIG_UNSET) | 260 if (config_state_ != ProxyPrefs::CONFIG_UNSET) |
| 263 *config = pref_config_; | 261 *config = pref_config_; |
| 264 return config_state_; | 262 return config_state_; |
| 265 } | 263 } |
| 266 | 264 |
| 267 void PrefProxyConfigTrackerImpl::OnProxyConfigChanged( | 265 void PrefProxyConfigTrackerImpl::OnProxyConfigChanged( |
| 268 ProxyPrefs::ConfigState config_state, | 266 ProxyPrefs::ConfigState config_state, |
| 269 const net::ProxyConfig& config) { | 267 const net::ProxyConfig& config) { |
| 270 if (!proxy_config_service_impl_) { | 268 if (!proxy_config_service_impl_) |
| 271 VLOG(1) << "No chrome proxy config service to push to UpdateProxyConfig"; | |
| 272 update_pending_ = true; | |
| 273 return; | 269 return; |
| 274 } | 270 io_task_runner_->PostTask( |
| 275 update_pending_ = !io_task_runner_->PostTask( | |
| 276 FROM_HERE, base::Bind(&ProxyConfigServiceImpl::UpdateProxyConfig, | 271 FROM_HERE, base::Bind(&ProxyConfigServiceImpl::UpdateProxyConfig, |
| 277 base::Unretained(proxy_config_service_impl_), | 272 base::Unretained(proxy_config_service_impl_), |
| 278 config_state, config)); | 273 config_state, config)); |
| 279 VLOG(1) << this << (update_pending_ ? ": Error" : ": Done") | |
| 280 << " pushing proxy to UpdateProxyConfig"; | |
| 281 } | 274 } |
| 282 | 275 |
| 283 bool PrefProxyConfigTrackerImpl::PrefConfigToNetConfig( | 276 bool PrefProxyConfigTrackerImpl::PrefConfigToNetConfig( |
| 284 const ProxyConfigDictionary& proxy_dict, | 277 const ProxyConfigDictionary& proxy_dict, |
| 285 net::ProxyConfig* config) { | 278 net::ProxyConfig* config) { |
| 286 ProxyPrefs::ProxyMode mode; | 279 ProxyPrefs::ProxyMode mode; |
| 287 if (!proxy_dict.GetMode(&mode)) { | 280 if (!proxy_dict.GetMode(&mode)) { |
| 288 // Fall back to system settings if the mode preference is invalid. | 281 // Fall back to system settings if the mode preference is invalid. |
| 289 return false; | 282 return false; |
| 290 } | 283 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 DCHECK(thread_checker_.CalledOnValidThread()); | 338 DCHECK(thread_checker_.CalledOnValidThread()); |
| 346 net::ProxyConfig new_config; | 339 net::ProxyConfig new_config; |
| 347 ProxyPrefs::ConfigState config_state = | 340 ProxyPrefs::ConfigState config_state = |
| 348 ReadPrefConfig(pref_service_, &new_config); | 341 ReadPrefConfig(pref_service_, &new_config); |
| 349 if (config_state_ != config_state || | 342 if (config_state_ != config_state || |
| 350 (config_state_ != ProxyPrefs::CONFIG_UNSET && | 343 (config_state_ != ProxyPrefs::CONFIG_UNSET && |
| 351 !pref_config_.Equals(new_config))) { | 344 !pref_config_.Equals(new_config))) { |
| 352 config_state_ = config_state; | 345 config_state_ = config_state; |
| 353 if (config_state_ != ProxyPrefs::CONFIG_UNSET) | 346 if (config_state_ != ProxyPrefs::CONFIG_UNSET) |
| 354 pref_config_ = new_config; | 347 pref_config_ = new_config; |
| 355 update_pending_ = true; | 348 OnProxyConfigChanged(config_state, new_config); |
| 356 } | 349 } |
| 357 if (update_pending_) | |
| 358 OnProxyConfigChanged(config_state, new_config); | |
| 359 } | 350 } |
| OLD | NEW |