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 "components/proxy_config/pref_proxy_config_tracker_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" |
8 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
9 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
10 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/single_thread_task_runner.h" |
11 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
12 #include "base/values.h" | 14 #include "base/values.h" |
13 #include "chrome/browser/chrome_notification_types.h" | |
14 #include "chrome/common/pref_names.h" | |
15 #include "components/pref_registry/pref_registry_syncable.h" | 15 #include "components/pref_registry/pref_registry_syncable.h" |
16 #include "components/proxy_config/proxy_config_dictionary.h" | 16 #include "components/proxy_config/proxy_config_dictionary.h" |
17 #include "content/public/browser/browser_thread.h" | 17 #include "components/proxy_config/proxy_config_pref_names.h" |
18 #include "content/public/browser/notification_details.h" | |
19 #include "content/public/browser/notification_source.h" | |
20 #include "net/proxy/proxy_list.h" | 18 #include "net/proxy/proxy_list.h" |
21 #include "net/proxy/proxy_server.h" | 19 #include "net/proxy/proxy_server.h" |
22 | 20 #include "url/gurl.h" |
23 using content::BrowserThread; | |
24 | 21 |
25 namespace { | 22 namespace { |
26 | 23 |
27 // Determine if |proxy| is of the form "*.googlezip.net". | 24 // Determine if |proxy| is of the form "*.googlezip.net". |
28 bool IsGooglezipDataReductionProxy(const net::ProxyServer& proxy) { | 25 bool IsGooglezipDataReductionProxy(const net::ProxyServer& proxy) { |
29 return proxy.is_valid() && !proxy.is_direct() && | 26 return proxy.is_valid() && !proxy.is_direct() && |
30 base::EndsWith(proxy.host_port_pair().host(), ".googlezip.net", | 27 base::EndsWith(proxy.host_port_pair().host(), ".googlezip.net", |
31 base::CompareCase::SENSITIVE); | 28 base::CompareCase::SENSITIVE); |
32 } | 29 } |
33 | 30 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 RemoveGooglezipDataReductionProxiesFromList( | 76 RemoveGooglezipDataReductionProxiesFromList( |
80 &proxy_rules->proxies_for_https) + | 77 &proxy_rules->proxies_for_https) + |
81 RemoveGooglezipDataReductionProxiesFromList(&proxy_rules->single_proxies); | 78 RemoveGooglezipDataReductionProxiesFromList(&proxy_rules->single_proxies); |
82 | 79 |
83 UMA_HISTOGRAM_COUNTS_100("Net.PrefProxyConfig.GooglezipProxyRemovalCount", | 80 UMA_HISTOGRAM_COUNTS_100("Net.PrefProxyConfig.GooglezipProxyRemovalCount", |
84 num_removed_proxies); | 81 num_removed_proxies); |
85 } | 82 } |
86 | 83 |
87 } // namespace | 84 } // namespace |
88 | 85 |
89 //============================= ChromeProxyConfigService ======================= | 86 //============================= ProxyConfigServiceImpl ======================= |
90 | 87 |
91 ChromeProxyConfigService::ChromeProxyConfigService( | 88 ProxyConfigServiceImpl::ProxyConfigServiceImpl( |
92 net::ProxyConfigService* base_service) | 89 net::ProxyConfigService* base_service) |
93 : base_service_(base_service), | 90 : base_service_(base_service), |
94 pref_config_state_(ProxyPrefs::CONFIG_UNSET), | 91 pref_config_state_(ProxyPrefs::CONFIG_UNSET), |
95 pref_config_read_pending_(true), | 92 pref_config_read_pending_(true), |
96 registered_observer_(false) { | 93 registered_observer_(false) { |
| 94 // ProxyConfigServiceImpl is created on the UI thread, but used on the network |
| 95 // thread. |
| 96 thread_checker_.DetachFromThread(); |
97 } | 97 } |
98 | 98 |
99 ChromeProxyConfigService::~ChromeProxyConfigService() { | 99 ProxyConfigServiceImpl::~ProxyConfigServiceImpl() { |
100 if (registered_observer_ && base_service_.get()) | 100 if (registered_observer_ && base_service_.get()) |
101 base_service_->RemoveObserver(this); | 101 base_service_->RemoveObserver(this); |
102 } | 102 } |
103 | 103 |
104 void ChromeProxyConfigService::AddObserver( | 104 void ProxyConfigServiceImpl::AddObserver( |
105 net::ProxyConfigService::Observer* observer) { | 105 net::ProxyConfigService::Observer* observer) { |
106 RegisterObserver(); | 106 RegisterObserver(); |
107 observers_.AddObserver(observer); | 107 observers_.AddObserver(observer); |
108 } | 108 } |
109 | 109 |
110 void ChromeProxyConfigService::RemoveObserver( | 110 void ProxyConfigServiceImpl::RemoveObserver( |
111 net::ProxyConfigService::Observer* observer) { | 111 net::ProxyConfigService::Observer* observer) { |
112 observers_.RemoveObserver(observer); | 112 observers_.RemoveObserver(observer); |
113 } | 113 } |
114 | 114 |
115 net::ProxyConfigService::ConfigAvailability | 115 net::ProxyConfigService::ConfigAvailability |
116 ChromeProxyConfigService::GetLatestProxyConfig(net::ProxyConfig* config) { | 116 ProxyConfigServiceImpl::GetLatestProxyConfig(net::ProxyConfig* config) { |
117 RegisterObserver(); | 117 RegisterObserver(); |
118 | 118 |
119 if (pref_config_read_pending_) | 119 if (pref_config_read_pending_) |
120 return net::ProxyConfigService::CONFIG_PENDING; | 120 return net::ProxyConfigService::CONFIG_PENDING; |
121 | 121 |
122 // Ask the base service if available. | 122 // Ask the base service if available. |
123 net::ProxyConfig system_config; | 123 net::ProxyConfig system_config; |
124 ConfigAvailability system_availability = | 124 ConfigAvailability system_availability = |
125 net::ProxyConfigService::CONFIG_UNSET; | 125 net::ProxyConfigService::CONFIG_UNSET; |
126 if (base_service_.get()) | 126 if (base_service_.get()) |
127 system_availability = base_service_->GetLatestProxyConfig(&system_config); | 127 system_availability = base_service_->GetLatestProxyConfig(&system_config); |
128 | 128 |
129 ProxyPrefs::ConfigState config_state; | 129 ProxyPrefs::ConfigState config_state; |
130 return PrefProxyConfigTrackerImpl::GetEffectiveProxyConfig( | 130 return PrefProxyConfigTrackerImpl::GetEffectiveProxyConfig( |
131 pref_config_state_, pref_config_, | 131 pref_config_state_, pref_config_, system_availability, system_config, |
132 system_availability, system_config, false, | 132 false, &config_state, config); |
133 &config_state, config); | |
134 } | 133 } |
135 | 134 |
136 void ChromeProxyConfigService::OnLazyPoll() { | 135 void ProxyConfigServiceImpl::OnLazyPoll() { |
137 if (base_service_.get()) | 136 if (base_service_.get()) |
138 base_service_->OnLazyPoll(); | 137 base_service_->OnLazyPoll(); |
139 } | 138 } |
140 | 139 |
141 void ChromeProxyConfigService::UpdateProxyConfig( | 140 void ProxyConfigServiceImpl::UpdateProxyConfig( |
142 ProxyPrefs::ConfigState config_state, | 141 ProxyPrefs::ConfigState config_state, |
143 const net::ProxyConfig& config) { | 142 const net::ProxyConfig& config) { |
144 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 143 DCHECK(thread_checker_.CalledOnValidThread()); |
145 | |
146 pref_config_read_pending_ = false; | 144 pref_config_read_pending_ = false; |
147 pref_config_state_ = config_state; | 145 pref_config_state_ = config_state; |
148 pref_config_ = config; | 146 pref_config_ = config; |
149 | 147 |
150 if (!observers_.might_have_observers()) | 148 if (!observers_.might_have_observers()) |
151 return; | 149 return; |
152 | 150 |
153 // Evaluate the proxy configuration. If GetLatestProxyConfig returns | 151 // Evaluate the proxy configuration. If GetLatestProxyConfig returns |
154 // CONFIG_PENDING, we are using the system proxy service, but it doesn't have | 152 // CONFIG_PENDING, we are using the system proxy service, but it doesn't have |
155 // a valid configuration yet. Once it is ready, OnProxyConfigChanged() will be | 153 // a valid configuration yet. Once it is ready, OnProxyConfigChanged() will be |
156 // called and broadcast the proxy configuration. | 154 // called and broadcast the proxy configuration. |
157 // Note: If a switch between a preference proxy configuration and the system | 155 // Note: If a switch between a preference proxy configuration and the system |
158 // proxy configuration occurs an unnecessary notification might get send if | 156 // proxy configuration occurs an unnecessary notification might get send if |
159 // the two configurations agree. This case should be rare however, so we don't | 157 // the two configurations agree. This case should be rare however, so we don't |
160 // handle that case specially. | 158 // handle that case specially. |
161 net::ProxyConfig new_config; | 159 net::ProxyConfig new_config; |
162 ConfigAvailability availability = GetLatestProxyConfig(&new_config); | 160 ConfigAvailability availability = GetLatestProxyConfig(&new_config); |
163 if (availability != CONFIG_PENDING) { | 161 if (availability != CONFIG_PENDING) { |
164 FOR_EACH_OBSERVER(net::ProxyConfigService::Observer, observers_, | 162 FOR_EACH_OBSERVER(net::ProxyConfigService::Observer, observers_, |
165 OnProxyConfigChanged(new_config, availability)); | 163 OnProxyConfigChanged(new_config, availability)); |
166 } | 164 } |
167 } | 165 } |
168 | 166 |
169 void ChromeProxyConfigService::OnProxyConfigChanged( | 167 void ProxyConfigServiceImpl::OnProxyConfigChanged( |
170 const net::ProxyConfig& config, | 168 const net::ProxyConfig& config, |
171 ConfigAvailability availability) { | 169 ConfigAvailability availability) { |
172 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 170 DCHECK(thread_checker_.CalledOnValidThread()); |
173 | 171 |
174 // Check whether there is a proxy configuration defined by preferences. In | 172 // Check whether there is a proxy configuration defined by preferences. In |
175 // this case that proxy configuration takes precedence and the change event | 173 // this case that proxy configuration takes precedence and the change event |
176 // from the delegate proxy service can be disregarded. | 174 // from the delegate proxy service can be disregarded. |
177 if (!PrefProxyConfigTrackerImpl::PrefPrecedes(pref_config_state_)) { | 175 if (!PrefProxyConfigTrackerImpl::PrefPrecedes(pref_config_state_)) { |
178 net::ProxyConfig actual_config; | 176 net::ProxyConfig actual_config; |
179 availability = GetLatestProxyConfig(&actual_config); | 177 availability = GetLatestProxyConfig(&actual_config); |
180 FOR_EACH_OBSERVER(net::ProxyConfigService::Observer, observers_, | 178 FOR_EACH_OBSERVER(net::ProxyConfigService::Observer, observers_, |
181 OnProxyConfigChanged(actual_config, availability)); | 179 OnProxyConfigChanged(actual_config, availability)); |
182 } | 180 } |
183 } | 181 } |
184 | 182 |
185 void ChromeProxyConfigService::RegisterObserver() { | 183 void ProxyConfigServiceImpl::RegisterObserver() { |
186 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 184 DCHECK(thread_checker_.CalledOnValidThread()); |
187 if (!registered_observer_ && base_service_.get()) { | 185 if (!registered_observer_ && base_service_.get()) { |
188 base_service_->AddObserver(this); | 186 base_service_->AddObserver(this); |
189 registered_observer_ = true; | 187 registered_observer_ = true; |
190 } | 188 } |
191 } | 189 } |
192 | 190 |
193 //========================= PrefProxyConfigTrackerImpl ========================= | 191 //========================= PrefProxyConfigTrackerImpl ========================= |
194 | 192 |
195 PrefProxyConfigTrackerImpl::PrefProxyConfigTrackerImpl( | 193 PrefProxyConfigTrackerImpl::PrefProxyConfigTrackerImpl( |
196 PrefService* pref_service) | 194 PrefService* pref_service, |
| 195 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
197 : pref_service_(pref_service), | 196 : pref_service_(pref_service), |
198 chrome_proxy_config_service_(NULL), | 197 proxy_config_service_impl_(NULL), |
199 update_pending_(true) { | 198 update_pending_(true), |
| 199 io_task_runner_(io_task_runner) { |
200 config_state_ = ReadPrefConfig(pref_service_, &pref_config_); | 200 config_state_ = ReadPrefConfig(pref_service_, &pref_config_); |
201 proxy_prefs_.Init(pref_service); | 201 proxy_prefs_.Init(pref_service); |
202 proxy_prefs_.Add(prefs::kProxy, | 202 proxy_prefs_.Add(proxy_config::prefs::kProxy, |
203 base::Bind(&PrefProxyConfigTrackerImpl::OnProxyPrefChanged, | 203 base::Bind(&PrefProxyConfigTrackerImpl::OnProxyPrefChanged, |
204 base::Unretained(this))); | 204 base::Unretained(this))); |
205 } | 205 } |
206 | 206 |
207 PrefProxyConfigTrackerImpl::~PrefProxyConfigTrackerImpl() { | 207 PrefProxyConfigTrackerImpl::~PrefProxyConfigTrackerImpl() { |
208 DCHECK(pref_service_ == NULL); | 208 DCHECK(pref_service_ == NULL); |
209 } | 209 } |
210 | 210 |
211 scoped_ptr<net::ProxyConfigService> | 211 scoped_ptr<net::ProxyConfigService> |
212 PrefProxyConfigTrackerImpl::CreateTrackingProxyConfigService( | 212 PrefProxyConfigTrackerImpl::CreateTrackingProxyConfigService( |
213 scoped_ptr<net::ProxyConfigService> base_service) { | 213 scoped_ptr<net::ProxyConfigService> base_service) { |
214 chrome_proxy_config_service_ = | 214 proxy_config_service_impl_ = |
215 new ChromeProxyConfigService(base_service.release()); | 215 new ProxyConfigServiceImpl(base_service.release()); |
216 VLOG(1) << this << ": set chrome proxy config service to " | 216 VLOG(1) << this << ": set chrome proxy config service to " |
217 << chrome_proxy_config_service_; | 217 << proxy_config_service_impl_; |
218 if (chrome_proxy_config_service_ && update_pending_) | 218 if (proxy_config_service_impl_ && update_pending_) |
219 OnProxyConfigChanged(config_state_, pref_config_); | 219 OnProxyConfigChanged(config_state_, pref_config_); |
220 | 220 |
221 return scoped_ptr<net::ProxyConfigService>(chrome_proxy_config_service_); | 221 return scoped_ptr<net::ProxyConfigService>(proxy_config_service_impl_); |
222 } | 222 } |
223 | 223 |
224 void PrefProxyConfigTrackerImpl::DetachFromPrefService() { | 224 void PrefProxyConfigTrackerImpl::DetachFromPrefService() { |
225 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 225 DCHECK(thread_checker_.CalledOnValidThread()); |
226 // Stop notifications. | 226 // Stop notifications. |
227 proxy_prefs_.RemoveAll(); | 227 proxy_prefs_.RemoveAll(); |
228 pref_service_ = NULL; | 228 pref_service_ = NULL; |
229 chrome_proxy_config_service_ = NULL; | 229 proxy_config_service_impl_ = NULL; |
230 } | 230 } |
231 | 231 |
232 // static | 232 // static |
233 bool PrefProxyConfigTrackerImpl::PrefPrecedes( | 233 bool PrefProxyConfigTrackerImpl::PrefPrecedes( |
234 ProxyPrefs::ConfigState config_state) { | 234 ProxyPrefs::ConfigState config_state) { |
235 return config_state == ProxyPrefs::CONFIG_POLICY || | 235 return config_state == ProxyPrefs::CONFIG_POLICY || |
236 config_state == ProxyPrefs::CONFIG_EXTENSION || | 236 config_state == ProxyPrefs::CONFIG_EXTENSION || |
237 config_state == ProxyPrefs::CONFIG_OTHER_PRECEDE; | 237 config_state == ProxyPrefs::CONFIG_OTHER_PRECEDE; |
238 } | 238 } |
239 | 239 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 if (rv == net::ProxyConfigService::CONFIG_VALID) | 277 if (rv == net::ProxyConfigService::CONFIG_VALID) |
278 RemoveGooglezipDataReductionProxies(&effective_config->proxy_rules()); | 278 RemoveGooglezipDataReductionProxies(&effective_config->proxy_rules()); |
279 | 279 |
280 return rv; | 280 return rv; |
281 } | 281 } |
282 | 282 |
283 // static | 283 // static |
284 void PrefProxyConfigTrackerImpl::RegisterPrefs(PrefRegistrySimple* registry) { | 284 void PrefProxyConfigTrackerImpl::RegisterPrefs(PrefRegistrySimple* registry) { |
285 base::DictionaryValue* default_settings = | 285 base::DictionaryValue* default_settings = |
286 ProxyConfigDictionary::CreateSystem(); | 286 ProxyConfigDictionary::CreateSystem(); |
287 registry->RegisterDictionaryPref(prefs::kProxy, default_settings); | 287 registry->RegisterDictionaryPref(proxy_config::prefs::kProxy, |
| 288 default_settings); |
288 } | 289 } |
289 | 290 |
290 // static | 291 // static |
291 void PrefProxyConfigTrackerImpl::RegisterProfilePrefs( | 292 void PrefProxyConfigTrackerImpl::RegisterProfilePrefs( |
292 user_prefs::PrefRegistrySyncable* pref_service) { | 293 user_prefs::PrefRegistrySyncable* pref_service) { |
293 base::DictionaryValue* default_settings = | 294 base::DictionaryValue* default_settings = |
294 ProxyConfigDictionary::CreateSystem(); | 295 ProxyConfigDictionary::CreateSystem(); |
295 pref_service->RegisterDictionaryPref(prefs::kProxy, default_settings); | 296 pref_service->RegisterDictionaryPref(proxy_config::prefs::kProxy, |
| 297 default_settings); |
296 } | 298 } |
297 | 299 |
298 // static | 300 // static |
299 ProxyPrefs::ConfigState PrefProxyConfigTrackerImpl::ReadPrefConfig( | 301 ProxyPrefs::ConfigState PrefProxyConfigTrackerImpl::ReadPrefConfig( |
300 const PrefService* pref_service, | 302 const PrefService* pref_service, |
301 net::ProxyConfig* config) { | 303 net::ProxyConfig* config) { |
302 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
303 | |
304 // Clear the configuration and source. | 304 // Clear the configuration and source. |
305 *config = net::ProxyConfig(); | 305 *config = net::ProxyConfig(); |
306 ProxyPrefs::ConfigState config_state = ProxyPrefs::CONFIG_UNSET; | 306 ProxyPrefs::ConfigState config_state = ProxyPrefs::CONFIG_UNSET; |
307 | 307 |
308 const PrefService::Preference* pref = | 308 const PrefService::Preference* pref = |
309 pref_service->FindPreference(prefs::kProxy); | 309 pref_service->FindPreference(proxy_config::prefs::kProxy); |
310 DCHECK(pref); | 310 DCHECK(pref); |
311 | 311 |
312 const base::DictionaryValue* dict = | 312 const base::DictionaryValue* dict = |
313 pref_service->GetDictionary(prefs::kProxy); | 313 pref_service->GetDictionary(proxy_config::prefs::kProxy); |
314 DCHECK(dict); | 314 DCHECK(dict); |
315 ProxyConfigDictionary proxy_dict(dict); | 315 ProxyConfigDictionary proxy_dict(dict); |
316 | 316 |
317 if (PrefConfigToNetConfig(proxy_dict, config)) { | 317 if (PrefConfigToNetConfig(proxy_dict, config)) { |
318 if (!pref->IsUserModifiable() || pref->HasUserSetting()) { | 318 if (!pref->IsUserModifiable() || pref->HasUserSetting()) { |
319 if (pref->IsManaged()) | 319 if (pref->IsManaged()) |
320 config_state = ProxyPrefs::CONFIG_POLICY; | 320 config_state = ProxyPrefs::CONFIG_POLICY; |
321 else if (pref->IsExtensionControlled()) | 321 else if (pref->IsExtensionControlled()) |
322 config_state = ProxyPrefs::CONFIG_EXTENSION; | 322 config_state = ProxyPrefs::CONFIG_EXTENSION; |
323 else | 323 else |
324 config_state = ProxyPrefs::CONFIG_OTHER_PRECEDE; | 324 config_state = ProxyPrefs::CONFIG_OTHER_PRECEDE; |
325 } else { | 325 } else { |
326 config_state = ProxyPrefs::CONFIG_FALLBACK; | 326 config_state = ProxyPrefs::CONFIG_FALLBACK; |
327 } | 327 } |
328 } | 328 } |
329 | 329 |
330 return config_state; | 330 return config_state; |
331 } | 331 } |
332 | 332 |
333 ProxyPrefs::ConfigState PrefProxyConfigTrackerImpl::GetProxyConfig( | 333 ProxyPrefs::ConfigState PrefProxyConfigTrackerImpl::GetProxyConfig( |
334 net::ProxyConfig* config) { | 334 net::ProxyConfig* config) { |
335 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 335 DCHECK(thread_checker_.CalledOnValidThread()); |
336 if (config_state_ != ProxyPrefs::CONFIG_UNSET) | 336 if (config_state_ != ProxyPrefs::CONFIG_UNSET) |
337 *config = pref_config_; | 337 *config = pref_config_; |
338 return config_state_; | 338 return config_state_; |
339 } | 339 } |
340 | 340 |
341 void PrefProxyConfigTrackerImpl::OnProxyConfigChanged( | 341 void PrefProxyConfigTrackerImpl::OnProxyConfigChanged( |
342 ProxyPrefs::ConfigState config_state, | 342 ProxyPrefs::ConfigState config_state, |
343 const net::ProxyConfig& config) { | 343 const net::ProxyConfig& config) { |
344 if (!chrome_proxy_config_service_) { | 344 if (!proxy_config_service_impl_) { |
345 VLOG(1) << "No chrome proxy config service to push to UpdateProxyConfig"; | 345 VLOG(1) << "No chrome proxy config service to push to UpdateProxyConfig"; |
346 update_pending_ = true; | 346 update_pending_ = true; |
347 return; | 347 return; |
348 } | 348 } |
349 update_pending_ = !BrowserThread::PostTask( | 349 update_pending_ = !io_task_runner_->PostTask( |
350 BrowserThread::IO, FROM_HERE, | 350 FROM_HERE, base::Bind(&ProxyConfigServiceImpl::UpdateProxyConfig, |
351 base::Bind(&ChromeProxyConfigService::UpdateProxyConfig, | 351 base::Unretained(proxy_config_service_impl_), |
352 base::Unretained(chrome_proxy_config_service_), | 352 config_state, config)); |
353 config_state, config)); | |
354 VLOG(1) << this << (update_pending_ ? ": Error" : ": Done") | 353 VLOG(1) << this << (update_pending_ ? ": Error" : ": Done") |
355 << " pushing proxy to UpdateProxyConfig"; | 354 << " pushing proxy to UpdateProxyConfig"; |
356 } | 355 } |
357 | 356 |
358 bool PrefProxyConfigTrackerImpl::PrefConfigToNetConfig( | 357 bool PrefProxyConfigTrackerImpl::PrefConfigToNetConfig( |
359 const ProxyConfigDictionary& proxy_dict, | 358 const ProxyConfigDictionary& proxy_dict, |
360 net::ProxyConfig* config) { | 359 net::ProxyConfig* config) { |
361 ProxyPrefs::ProxyMode mode; | 360 ProxyPrefs::ProxyMode mode; |
362 if (!proxy_dict.GetMode(&mode)) { | 361 if (!proxy_dict.GetMode(&mode)) { |
363 // Fall back to system settings if the mode preference is invalid. | 362 // Fall back to system settings if the mode preference is invalid. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 } | 409 } |
411 case ProxyPrefs::kModeCount: { | 410 case ProxyPrefs::kModeCount: { |
412 // Fall through to NOTREACHED(). | 411 // Fall through to NOTREACHED(). |
413 } | 412 } |
414 } | 413 } |
415 NOTREACHED() << "Unknown proxy mode, falling back to system settings."; | 414 NOTREACHED() << "Unknown proxy mode, falling back to system settings."; |
416 return false; | 415 return false; |
417 } | 416 } |
418 | 417 |
419 void PrefProxyConfigTrackerImpl::OnProxyPrefChanged() { | 418 void PrefProxyConfigTrackerImpl::OnProxyPrefChanged() { |
420 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 419 DCHECK(thread_checker_.CalledOnValidThread()); |
421 net::ProxyConfig new_config; | 420 net::ProxyConfig new_config; |
422 ProxyPrefs::ConfigState config_state = ReadPrefConfig(pref_service_, | 421 ProxyPrefs::ConfigState config_state = |
423 &new_config); | 422 ReadPrefConfig(pref_service_, &new_config); |
424 if (config_state_ != config_state || | 423 if (config_state_ != config_state || |
425 (config_state_ != ProxyPrefs::CONFIG_UNSET && | 424 (config_state_ != ProxyPrefs::CONFIG_UNSET && |
426 !pref_config_.Equals(new_config))) { | 425 !pref_config_.Equals(new_config))) { |
427 config_state_ = config_state; | 426 config_state_ = config_state; |
428 if (config_state_ != ProxyPrefs::CONFIG_UNSET) | 427 if (config_state_ != ProxyPrefs::CONFIG_UNSET) |
429 pref_config_ = new_config; | 428 pref_config_ = new_config; |
430 update_pending_ = true; | 429 update_pending_ = true; |
431 } | 430 } |
432 if (update_pending_) | 431 if (update_pending_) |
433 OnProxyConfigChanged(config_state, new_config); | 432 OnProxyConfigChanged(config_state, new_config); |
434 } | 433 } |
OLD | NEW |