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 "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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 dict->Set("new_config", new_config_.ToValue()); | 257 dict->Set("new_config", new_config_.ToValue()); |
258 return dict; | 258 return dict; |
259 } | 259 } |
260 | 260 |
261 private: | 261 private: |
262 const ProxyConfig old_config_; | 262 const ProxyConfig old_config_; |
263 const ProxyConfig new_config_; | 263 const ProxyConfig new_config_; |
264 DISALLOW_COPY_AND_ASSIGN(ProxyConfigChangedNetLogParam); | 264 DISALLOW_COPY_AND_ASSIGN(ProxyConfigChangedNetLogParam); |
265 }; | 265 }; |
266 | 266 |
| 267 class BadProxyListNetLogParam : public NetLog::EventParameters { |
| 268 public: |
| 269 BadProxyListNetLogParam(const ProxyRetryInfoMap& retry_info) { |
| 270 proxy_list_.reserve(retry_info.size()); |
| 271 for (ProxyRetryInfoMap::const_iterator iter = retry_info.begin(); |
| 272 iter != retry_info.end(); ++iter) { |
| 273 proxy_list_.push_back(iter->first); |
| 274 } |
| 275 } |
| 276 |
| 277 virtual Value* ToValue() const OVERRIDE { |
| 278 DictionaryValue* dict = new DictionaryValue(); |
| 279 ListValue* list = new ListValue(); |
| 280 for (std::vector<std::string>::const_iterator iter = proxy_list_.begin(); |
| 281 iter != proxy_list_.end(); ++iter) |
| 282 list->Append(Value::CreateStringValue(*iter)); |
| 283 dict->Set("bad_proxy_list", list); |
| 284 return dict; |
| 285 } |
| 286 |
| 287 private: |
| 288 std::vector<std::string> proxy_list_; |
| 289 DISALLOW_COPY_AND_ASSIGN(BadProxyListNetLogParam); |
| 290 }; |
| 291 |
267 } // namespace | 292 } // namespace |
268 | 293 |
269 // ProxyService::PacRequest --------------------------------------------------- | 294 // ProxyService::PacRequest --------------------------------------------------- |
270 | 295 |
271 class ProxyService::PacRequest | 296 class ProxyService::PacRequest |
272 : public base::RefCounted<ProxyService::PacRequest> { | 297 : public base::RefCounted<ProxyService::PacRequest> { |
273 public: | 298 public: |
274 PacRequest(ProxyService* service, | 299 PacRequest(ProxyService* service, |
275 const GURL& url, | 300 const GURL& url, |
276 ProxyInfo* results, | 301 ProxyInfo* results, |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 | 733 |
709 if (re_resolve) { | 734 if (re_resolve) { |
710 // If we have a new config or the config was never tried, we delete the | 735 // If we have a new config or the config was never tried, we delete the |
711 // list of bad proxies and we try again. | 736 // list of bad proxies and we try again. |
712 proxy_retry_info_.clear(); | 737 proxy_retry_info_.clear(); |
713 return ResolveProxy(url, result, callback, pac_request, net_log); | 738 return ResolveProxy(url, result, callback, pac_request, net_log); |
714 } | 739 } |
715 | 740 |
716 // We don't have new proxy settings to try, try to fallback to the next proxy | 741 // We don't have new proxy settings to try, try to fallback to the next proxy |
717 // in the list. | 742 // in the list. |
718 bool did_fallback = result->Fallback(&proxy_retry_info_); | 743 bool did_fallback = result->Fallback(net_log); |
719 | 744 |
720 // Return synchronous failure if there is nothing left to fall-back to. | 745 // Return synchronous failure if there is nothing left to fall-back to. |
721 // TODO(eroman): This is a yucky API, clean it up. | 746 // TODO(eroman): This is a yucky API, clean it up. |
722 return did_fallback ? OK : ERR_FAILED; | 747 return did_fallback ? OK : ERR_FAILED; |
723 } | 748 } |
724 | 749 |
| 750 void ProxyService::ReportSuccess(const ProxyInfo& result) { |
| 751 DCHECK(CalledOnValidThread()); |
| 752 |
| 753 const ProxyRetryInfoMap& new_retry_info = result.proxy_retry_info(); |
| 754 if (new_retry_info.empty()) |
| 755 return; |
| 756 |
| 757 for (ProxyRetryInfoMap::const_iterator iter = new_retry_info.begin(); |
| 758 iter != new_retry_info.end(); ++iter) { |
| 759 ProxyRetryInfoMap::iterator existing = proxy_retry_info_.find(iter->first); |
| 760 if (existing == proxy_retry_info_.end()) |
| 761 proxy_retry_info_[iter->first] = iter->second; |
| 762 else if (existing->second.bad_until < iter->second.bad_until) |
| 763 existing->second.bad_until = iter->second.bad_until; |
| 764 } |
| 765 if (net_log_) { |
| 766 net_log_->AddEntry(NetLog::TYPE_BAD_PROXY_LIST_REPORTED, |
| 767 base::TimeTicks::Now(), |
| 768 NetLog::Source(), |
| 769 NetLog::PHASE_NONE, |
| 770 make_scoped_refptr( |
| 771 new BadProxyListNetLogParam(new_retry_info))); |
| 772 } |
| 773 } |
| 774 |
725 void ProxyService::CancelPacRequest(PacRequest* req) { | 775 void ProxyService::CancelPacRequest(PacRequest* req) { |
726 DCHECK(CalledOnValidThread()); | 776 DCHECK(CalledOnValidThread()); |
727 DCHECK(req); | 777 DCHECK(req); |
728 req->Cancel(); | 778 req->Cancel(); |
729 RemovePendingRequest(req); | 779 RemovePendingRequest(req); |
730 } | 780 } |
731 | 781 |
732 bool ProxyService::ContainsPendingRequest(PacRequest* req) { | 782 bool ProxyService::ContainsPendingRequest(PacRequest* req) { |
733 PendingRequests::iterator it = std::find( | 783 PendingRequests::iterator it = std::find( |
734 pending_requests_.begin(), pending_requests_.end(), req); | 784 pending_requests_.begin(), pending_requests_.end(), req); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 OnCompletion(result_); | 1071 OnCompletion(result_); |
1022 } | 1072 } |
1023 } | 1073 } |
1024 | 1074 |
1025 void SyncProxyServiceHelper::OnCompletion(int rv) { | 1075 void SyncProxyServiceHelper::OnCompletion(int rv) { |
1026 result_ = rv; | 1076 result_ = rv; |
1027 event_.Signal(); | 1077 event_.Signal(); |
1028 } | 1078 } |
1029 | 1079 |
1030 } // namespace net | 1080 } // namespace net |
OLD | NEW |