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> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "components/pref_registry/pref_registry_syncable.h" | |
17 #include "components/prefs/pref_registry_simple.h" | 16 #include "components/prefs/pref_registry_simple.h" |
18 #include "components/prefs/pref_service.h" | 17 #include "components/prefs/pref_service.h" |
19 #include "components/proxy_config/proxy_config_dictionary.h" | 18 #include "components/proxy_config/proxy_config_dictionary.h" |
20 #include "components/proxy_config/proxy_config_pref_names.h" | 19 #include "components/proxy_config/proxy_config_pref_names.h" |
21 #include "net/proxy/proxy_server.h" | 20 #include "net/proxy/proxy_server.h" |
22 #include "url/gurl.h" | 21 #include "url/gurl.h" |
23 | 22 |
24 //============================= ProxyConfigServiceImpl ======================= | 23 //============================= ProxyConfigServiceImpl ======================= |
25 | 24 |
26 ProxyConfigServiceImpl::ProxyConfigServiceImpl( | 25 ProxyConfigServiceImpl::ProxyConfigServiceImpl( |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } | 124 } |
126 | 125 |
127 //========================= PrefProxyConfigTrackerImpl ========================= | 126 //========================= PrefProxyConfigTrackerImpl ========================= |
128 | 127 |
129 PrefProxyConfigTrackerImpl::PrefProxyConfigTrackerImpl( | 128 PrefProxyConfigTrackerImpl::PrefProxyConfigTrackerImpl( |
130 PrefService* pref_service, | 129 PrefService* pref_service, |
131 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) | 130 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
132 : pref_service_(pref_service), | 131 : pref_service_(pref_service), |
133 proxy_config_service_impl_(NULL), | 132 proxy_config_service_impl_(NULL), |
134 io_task_runner_(io_task_runner) { | 133 io_task_runner_(io_task_runner) { |
135 config_state_ = ReadPrefConfig(pref_service_, &pref_config_); | 134 pref_config_state_ = ReadPrefConfig(pref_service_, &pref_config_); |
| 135 active_config_state_ = pref_config_state_; |
| 136 active_config_ = pref_config_; |
| 137 |
136 proxy_prefs_.Init(pref_service); | 138 proxy_prefs_.Init(pref_service); |
137 proxy_prefs_.Add(proxy_config::prefs::kProxy, | 139 proxy_prefs_.Add(proxy_config::prefs::kProxy, |
138 base::Bind(&PrefProxyConfigTrackerImpl::OnProxyPrefChanged, | 140 base::Bind(&PrefProxyConfigTrackerImpl::OnProxyPrefChanged, |
139 base::Unretained(this))); | 141 base::Unretained(this))); |
140 } | 142 } |
141 | 143 |
142 PrefProxyConfigTrackerImpl::~PrefProxyConfigTrackerImpl() { | 144 PrefProxyConfigTrackerImpl::~PrefProxyConfigTrackerImpl() { |
143 DCHECK(pref_service_ == NULL); | 145 DCHECK(pref_service_ == NULL); |
144 } | 146 } |
145 | 147 |
146 std::unique_ptr<net::ProxyConfigService> | 148 std::unique_ptr<net::ProxyConfigService> |
147 PrefProxyConfigTrackerImpl::CreateTrackingProxyConfigService( | 149 PrefProxyConfigTrackerImpl::CreateTrackingProxyConfigService( |
148 std::unique_ptr<net::ProxyConfigService> base_service) { | 150 std::unique_ptr<net::ProxyConfigService> base_service) { |
149 DCHECK(!proxy_config_service_impl_); | 151 DCHECK(!proxy_config_service_impl_); |
150 proxy_config_service_impl_ = new ProxyConfigServiceImpl( | 152 proxy_config_service_impl_ = new ProxyConfigServiceImpl( |
151 std::move(base_service), config_state_, pref_config_); | 153 std::move(base_service), active_config_state_, active_config_); |
152 VLOG(1) << this << ": set chrome proxy config service to " | 154 VLOG(1) << this << ": set chrome proxy config service to " |
153 << proxy_config_service_impl_; | 155 << proxy_config_service_impl_; |
154 | 156 |
155 return std::unique_ptr<net::ProxyConfigService>(proxy_config_service_impl_); | 157 return std::unique_ptr<net::ProxyConfigService>(proxy_config_service_impl_); |
156 } | 158 } |
157 | 159 |
158 void PrefProxyConfigTrackerImpl::DetachFromPrefService() { | 160 void PrefProxyConfigTrackerImpl::DetachFromPrefService() { |
159 DCHECK(thread_checker_.CalledOnValidThread()); | 161 DCHECK(thread_checker_.CalledOnValidThread()); |
160 // Stop notifications. | 162 // Stop notifications. |
161 proxy_prefs_.RemoveAll(); | 163 proxy_prefs_.RemoveAll(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 // static | 207 // static |
206 void PrefProxyConfigTrackerImpl::RegisterPrefs(PrefRegistrySimple* registry) { | 208 void PrefProxyConfigTrackerImpl::RegisterPrefs(PrefRegistrySimple* registry) { |
207 std::unique_ptr<base::DictionaryValue> default_settings = | 209 std::unique_ptr<base::DictionaryValue> default_settings = |
208 ProxyConfigDictionary::CreateSystem(); | 210 ProxyConfigDictionary::CreateSystem(); |
209 registry->RegisterDictionaryPref(proxy_config::prefs::kProxy, | 211 registry->RegisterDictionaryPref(proxy_config::prefs::kProxy, |
210 std::move(default_settings)); | 212 std::move(default_settings)); |
211 } | 213 } |
212 | 214 |
213 // static | 215 // static |
214 void PrefProxyConfigTrackerImpl::RegisterProfilePrefs( | 216 void PrefProxyConfigTrackerImpl::RegisterProfilePrefs( |
215 user_prefs::PrefRegistrySyncable* pref_service) { | 217 PrefRegistrySimple* registry) { |
216 std::unique_ptr<base::DictionaryValue> default_settings = | 218 std::unique_ptr<base::DictionaryValue> default_settings = |
217 ProxyConfigDictionary::CreateSystem(); | 219 ProxyConfigDictionary::CreateSystem(); |
218 pref_service->RegisterDictionaryPref(proxy_config::prefs::kProxy, | 220 registry->RegisterDictionaryPref(proxy_config::prefs::kProxy, |
219 std::move(default_settings)); | 221 std::move(default_settings)); |
220 pref_service->RegisterBooleanPref(proxy_config::prefs::kUseSharedProxies, | 222 registry->RegisterBooleanPref(proxy_config::prefs::kUseSharedProxies, false); |
221 false); | |
222 } | 223 } |
223 | 224 |
224 // static | 225 // static |
225 ProxyPrefs::ConfigState PrefProxyConfigTrackerImpl::ReadPrefConfig( | 226 ProxyPrefs::ConfigState PrefProxyConfigTrackerImpl::ReadPrefConfig( |
226 const PrefService* pref_service, | 227 const PrefService* pref_service, |
227 net::ProxyConfig* config) { | 228 net::ProxyConfig* config) { |
228 // Clear the configuration and source. | 229 // Clear the configuration and source. |
229 *config = net::ProxyConfig(); | 230 *config = net::ProxyConfig(); |
230 ProxyPrefs::ConfigState config_state = ProxyPrefs::CONFIG_UNSET; | 231 ProxyPrefs::ConfigState config_state = ProxyPrefs::CONFIG_UNSET; |
231 | 232 |
(...skipping 18 matching lines...) Expand all Loading... |
250 config_state = ProxyPrefs::CONFIG_FALLBACK; | 251 config_state = ProxyPrefs::CONFIG_FALLBACK; |
251 } | 252 } |
252 } | 253 } |
253 | 254 |
254 return config_state; | 255 return config_state; |
255 } | 256 } |
256 | 257 |
257 ProxyPrefs::ConfigState PrefProxyConfigTrackerImpl::GetProxyConfig( | 258 ProxyPrefs::ConfigState PrefProxyConfigTrackerImpl::GetProxyConfig( |
258 net::ProxyConfig* config) { | 259 net::ProxyConfig* config) { |
259 DCHECK(thread_checker_.CalledOnValidThread()); | 260 DCHECK(thread_checker_.CalledOnValidThread()); |
260 if (config_state_ != ProxyPrefs::CONFIG_UNSET) | 261 if (pref_config_state_ != ProxyPrefs::CONFIG_UNSET) |
261 *config = pref_config_; | 262 *config = pref_config_; |
262 return config_state_; | 263 return pref_config_state_; |
263 } | 264 } |
264 | 265 |
265 void PrefProxyConfigTrackerImpl::OnProxyConfigChanged( | 266 void PrefProxyConfigTrackerImpl::OnProxyConfigChanged( |
266 ProxyPrefs::ConfigState config_state, | 267 ProxyPrefs::ConfigState config_state, |
267 const net::ProxyConfig& config) { | 268 const net::ProxyConfig& config) { |
| 269 // If the configuration hasn't changed, do nothing. |
| 270 if (active_config_state_ == config_state && |
| 271 (active_config_state_ == ProxyPrefs::CONFIG_UNSET || |
| 272 active_config_.Equals(config))) { |
| 273 return; |
| 274 } |
| 275 |
| 276 active_config_state_ = config_state; |
| 277 if (active_config_state_ != ProxyPrefs::CONFIG_UNSET) |
| 278 active_config_ = config; |
| 279 |
268 if (!proxy_config_service_impl_) | 280 if (!proxy_config_service_impl_) |
269 return; | 281 return; |
270 io_task_runner_->PostTask( | 282 io_task_runner_->PostTask( |
271 FROM_HERE, base::Bind(&ProxyConfigServiceImpl::UpdateProxyConfig, | 283 FROM_HERE, base::Bind(&ProxyConfigServiceImpl::UpdateProxyConfig, |
272 base::Unretained(proxy_config_service_impl_), | 284 base::Unretained(proxy_config_service_impl_), |
273 config_state, config)); | 285 config_state, config)); |
274 } | 286 } |
275 | 287 |
276 bool PrefProxyConfigTrackerImpl::PrefConfigToNetConfig( | 288 bool PrefProxyConfigTrackerImpl::PrefConfigToNetConfig( |
277 const ProxyConfigDictionary& proxy_dict, | 289 const ProxyConfigDictionary& proxy_dict, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 } | 344 } |
333 NOTREACHED() << "Unknown proxy mode, falling back to system settings."; | 345 NOTREACHED() << "Unknown proxy mode, falling back to system settings."; |
334 return false; | 346 return false; |
335 } | 347 } |
336 | 348 |
337 void PrefProxyConfigTrackerImpl::OnProxyPrefChanged() { | 349 void PrefProxyConfigTrackerImpl::OnProxyPrefChanged() { |
338 DCHECK(thread_checker_.CalledOnValidThread()); | 350 DCHECK(thread_checker_.CalledOnValidThread()); |
339 net::ProxyConfig new_config; | 351 net::ProxyConfig new_config; |
340 ProxyPrefs::ConfigState config_state = | 352 ProxyPrefs::ConfigState config_state = |
341 ReadPrefConfig(pref_service_, &new_config); | 353 ReadPrefConfig(pref_service_, &new_config); |
342 if (config_state_ != config_state || | 354 if (pref_config_state_ != config_state || |
343 (config_state_ != ProxyPrefs::CONFIG_UNSET && | 355 (pref_config_state_ != ProxyPrefs::CONFIG_UNSET && |
344 !pref_config_.Equals(new_config))) { | 356 !pref_config_.Equals(new_config))) { |
345 config_state_ = config_state; | 357 pref_config_state_ = config_state; |
346 if (config_state_ != ProxyPrefs::CONFIG_UNSET) | 358 if (pref_config_state_ != ProxyPrefs::CONFIG_UNSET) |
347 pref_config_ = new_config; | 359 pref_config_ = new_config; |
348 OnProxyConfigChanged(config_state, new_config); | 360 OnProxyConfigChanged(config_state, new_config); |
349 } | 361 } |
350 } | 362 } |
OLD | NEW |