OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/proxy/proxy_service.h" | 5 #include "net/proxy/proxy_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 return OK; | 300 return OK; |
301 } | 301 } |
302 | 302 |
303 private: | 303 private: |
304 const std::string pac_string_; | 304 const std::string pac_string_; |
305 | 305 |
306 DISALLOW_COPY_AND_ASSIGN(ProxyResolverFactoryForPacResult); | 306 DISALLOW_COPY_AND_ASSIGN(ProxyResolverFactoryForPacResult); |
307 }; | 307 }; |
308 | 308 |
309 // Returns NetLog parameters describing a proxy configuration change. | 309 // Returns NetLog parameters describing a proxy configuration change. |
310 base::Value* NetLogProxyConfigChangedCallback( | 310 scoped_ptr<base::Value> NetLogProxyConfigChangedCallback( |
311 const ProxyConfig* old_config, | 311 const ProxyConfig* old_config, |
312 const ProxyConfig* new_config, | 312 const ProxyConfig* new_config, |
313 NetLogCaptureMode /* capture_mode */) { | 313 NetLogCaptureMode /* capture_mode */) { |
314 base::DictionaryValue* dict = new base::DictionaryValue(); | 314 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
315 // The "old_config" is optional -- the first notification will not have | 315 // The "old_config" is optional -- the first notification will not have |
316 // any "previous" configuration. | 316 // any "previous" configuration. |
317 if (old_config->is_valid()) | 317 if (old_config->is_valid()) |
318 dict->Set("old_config", old_config->ToValue()); | 318 dict->Set("old_config", old_config->ToValue()); |
319 dict->Set("new_config", new_config->ToValue()); | 319 dict->Set("new_config", new_config->ToValue()); |
320 return dict; | 320 return dict.Pass(); |
321 } | 321 } |
322 | 322 |
323 base::Value* NetLogBadProxyListCallback(const ProxyRetryInfoMap* retry_info, | 323 scoped_ptr<base::Value> NetLogBadProxyListCallback( |
324 NetLogCaptureMode /* capture_mode */) { | 324 const ProxyRetryInfoMap* retry_info, |
325 base::DictionaryValue* dict = new base::DictionaryValue(); | 325 NetLogCaptureMode /* capture_mode */) { |
326 base::ListValue* list = new base::ListValue(); | 326 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 327 scoped_ptr<base::ListValue> list(new base::ListValue()); |
327 | 328 |
328 for (ProxyRetryInfoMap::const_iterator iter = retry_info->begin(); | 329 for (ProxyRetryInfoMap::const_iterator iter = retry_info->begin(); |
329 iter != retry_info->end(); ++iter) { | 330 iter != retry_info->end(); ++iter) { |
330 list->Append(new base::StringValue(iter->first)); | 331 list->Append(new base::StringValue(iter->first)); |
331 } | 332 } |
332 dict->Set("bad_proxy_list", list); | 333 dict->Set("bad_proxy_list", list.Pass()); |
333 return dict; | 334 return dict.Pass(); |
334 } | 335 } |
335 | 336 |
336 // Returns NetLog parameters on a successfuly proxy resolution. | 337 // Returns NetLog parameters on a successfuly proxy resolution. |
337 base::Value* NetLogFinishedResolvingProxyCallback( | 338 scoped_ptr<base::Value> NetLogFinishedResolvingProxyCallback( |
338 const ProxyInfo* result, | 339 const ProxyInfo* result, |
339 NetLogCaptureMode /* capture_mode */) { | 340 NetLogCaptureMode /* capture_mode */) { |
340 base::DictionaryValue* dict = new base::DictionaryValue(); | 341 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
341 dict->SetString("pac_string", result->ToPacString()); | 342 dict->SetString("pac_string", result->ToPacString()); |
342 return dict; | 343 return dict.Pass(); |
343 } | 344 } |
344 | 345 |
345 #if defined(OS_CHROMEOS) | 346 #if defined(OS_CHROMEOS) |
346 class UnsetProxyConfigService : public ProxyConfigService { | 347 class UnsetProxyConfigService : public ProxyConfigService { |
347 public: | 348 public: |
348 UnsetProxyConfigService() {} | 349 UnsetProxyConfigService() {} |
349 ~UnsetProxyConfigService() override {} | 350 ~UnsetProxyConfigService() override {} |
350 | 351 |
351 void AddObserver(Observer* observer) override {} | 352 void AddObserver(Observer* observer) override {} |
352 void RemoveObserver(Observer* observer) override {} | 353 void RemoveObserver(Observer* observer) override {} |
(...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1336 network_delegate->NotifyProxyFallback(bad_proxy, | 1337 network_delegate->NotifyProxyFallback(bad_proxy, |
1337 proxy_retry_info.net_error); | 1338 proxy_retry_info.net_error); |
1338 } | 1339 } |
1339 } | 1340 } |
1340 else if (existing->second.bad_until < iter->second.bad_until) | 1341 else if (existing->second.bad_until < iter->second.bad_until) |
1341 existing->second.bad_until = iter->second.bad_until; | 1342 existing->second.bad_until = iter->second.bad_until; |
1342 } | 1343 } |
1343 if (net_log_) { | 1344 if (net_log_) { |
1344 net_log_->AddGlobalEntry( | 1345 net_log_->AddGlobalEntry( |
1345 NetLog::TYPE_BAD_PROXY_LIST_REPORTED, | 1346 NetLog::TYPE_BAD_PROXY_LIST_REPORTED, |
1346 base::Bind(&NetLogBadProxyListCallback, &new_retry_info)); | 1347 base::Bind(NetLogBadProxyListCallback, &new_retry_info)); |
1347 } | 1348 } |
1348 } | 1349 } |
1349 | 1350 |
1350 void ProxyService::CancelPacRequest(PacRequest* req) { | 1351 void ProxyService::CancelPacRequest(PacRequest* req) { |
1351 DCHECK(CalledOnValidThread()); | 1352 DCHECK(CalledOnValidThread()); |
1352 DCHECK(req); | 1353 DCHECK(req); |
1353 req->Cancel(); | 1354 req->Cancel(); |
1354 RemovePendingRequest(req); | 1355 RemovePendingRequest(req); |
1355 } | 1356 } |
1356 | 1357 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1407 if (result_code == OK) { | 1408 if (result_code == OK) { |
1408 // Allow the network delegate to interpose on the resolution decision, | 1409 // Allow the network delegate to interpose on the resolution decision, |
1409 // possibly modifying the ProxyInfo. | 1410 // possibly modifying the ProxyInfo. |
1410 if (network_delegate) | 1411 if (network_delegate) |
1411 network_delegate->NotifyResolveProxy(url, load_flags, *this, result); | 1412 network_delegate->NotifyResolveProxy(url, load_flags, *this, result); |
1412 | 1413 |
1413 // When logging all events is enabled, dump the proxy list. | 1414 // When logging all events is enabled, dump the proxy list. |
1414 if (net_log.IsCapturing()) { | 1415 if (net_log.IsCapturing()) { |
1415 net_log.AddEvent( | 1416 net_log.AddEvent( |
1416 NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, | 1417 NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, |
1417 base::Bind(&NetLogFinishedResolvingProxyCallback, result)); | 1418 base::Bind(NetLogFinishedResolvingProxyCallback, result)); |
1418 } | 1419 } |
1419 result->DeprioritizeBadProxies(proxy_retry_info_); | 1420 result->DeprioritizeBadProxies(proxy_retry_info_); |
1420 } else { | 1421 } else { |
1421 net_log.AddEventWithNetErrorCode( | 1422 net_log.AddEventWithNetErrorCode( |
1422 NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, result_code); | 1423 NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, result_code); |
1423 | 1424 |
1424 bool reset_config = result_code == ERR_PAC_SCRIPT_TERMINATED; | 1425 bool reset_config = result_code == ERR_PAC_SCRIPT_TERMINATED; |
1425 if (!config_.pac_mandatory()) { | 1426 if (!config_.pac_mandatory()) { |
1426 // Fall-back to direct when the proxy resolver fails. This corresponds | 1427 // Fall-back to direct when the proxy resolver fails. This corresponds |
1427 // with a javascript runtime error in the PAC script. | 1428 // with a javascript runtime error in the PAC script. |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1582 effective_config = config; | 1583 effective_config = config; |
1583 break; | 1584 break; |
1584 case ProxyConfigService::CONFIG_UNSET: | 1585 case ProxyConfigService::CONFIG_UNSET: |
1585 effective_config = ProxyConfig::CreateDirect(); | 1586 effective_config = ProxyConfig::CreateDirect(); |
1586 break; | 1587 break; |
1587 } | 1588 } |
1588 | 1589 |
1589 // Emit the proxy settings change to the NetLog stream. | 1590 // Emit the proxy settings change to the NetLog stream. |
1590 if (net_log_) { | 1591 if (net_log_) { |
1591 net_log_->AddGlobalEntry(NetLog::TYPE_PROXY_CONFIG_CHANGED, | 1592 net_log_->AddGlobalEntry(NetLog::TYPE_PROXY_CONFIG_CHANGED, |
1592 base::Bind(&NetLogProxyConfigChangedCallback, | 1593 base::Bind(NetLogProxyConfigChangedCallback, |
1593 &fetched_config_, &effective_config)); | 1594 &fetched_config_, &effective_config)); |
1594 } | 1595 } |
1595 | 1596 |
1596 // Set the new configuration as the most recently fetched one. | 1597 // Set the new configuration as the most recently fetched one. |
1597 fetched_config_ = effective_config; | 1598 fetched_config_ = effective_config; |
1598 fetched_config_.set_id(1); // Needed for a later DCHECK of is_valid(). | 1599 fetched_config_.set_id(1); // Needed for a later DCHECK of is_valid(). |
1599 | 1600 |
1600 InitializeUsingLastFetchedConfig(); | 1601 InitializeUsingLastFetchedConfig(); |
1601 } | 1602 } |
1602 | 1603 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1662 State previous_state = ResetProxyConfig(false); | 1663 State previous_state = ResetProxyConfig(false); |
1663 if (previous_state != STATE_NONE) | 1664 if (previous_state != STATE_NONE) |
1664 ApplyProxyConfigIfAvailable(); | 1665 ApplyProxyConfigIfAvailable(); |
1665 } | 1666 } |
1666 | 1667 |
1667 void ProxyService::OnDNSChanged() { | 1668 void ProxyService::OnDNSChanged() { |
1668 OnIPAddressChanged(); | 1669 OnIPAddressChanged(); |
1669 } | 1670 } |
1670 | 1671 |
1671 } // namespace net | 1672 } // namespace net |
OLD | NEW |