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