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