OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_list.h" | 5 #include "net/proxy/proxy_list.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_tokenizer.h" | 8 #include "base/string_tokenizer.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 proxies_.push_back(uri); | 24 proxies_.push_back(uri); |
25 } | 25 } |
26 } | 26 } |
27 | 27 |
28 void ProxyList::SetSingleProxyServer(const ProxyServer& proxy_server) { | 28 void ProxyList::SetSingleProxyServer(const ProxyServer& proxy_server) { |
29 proxies_.clear(); | 29 proxies_.clear(); |
30 if (proxy_server.is_valid()) | 30 if (proxy_server.is_valid()) |
31 proxies_.push_back(proxy_server); | 31 proxies_.push_back(proxy_server); |
32 } | 32 } |
33 | 33 |
34 void ProxyList::RemoveBadProxies(const ProxyRetryInfoMap& proxy_retry_info) { | 34 void ProxyList::DeprioritizeBadProxies( |
35 std::vector<ProxyServer> new_proxy_list; | 35 const ProxyRetryInfoMap& proxy_retry_info) { |
| 36 // Partition the proxy list in two: |
| 37 // (1) the known bad proxies |
| 38 // (2) everything else |
| 39 std::vector<ProxyServer> good_proxies; |
| 40 std::vector<ProxyServer> bad_proxies; |
| 41 |
36 std::vector<ProxyServer>::const_iterator iter = proxies_.begin(); | 42 std::vector<ProxyServer>::const_iterator iter = proxies_.begin(); |
37 for (; iter != proxies_.end(); ++iter) { | 43 for (; iter != proxies_.end(); ++iter) { |
38 ProxyRetryInfoMap::const_iterator bad_proxy = | 44 ProxyRetryInfoMap::const_iterator bad_proxy = |
39 proxy_retry_info.find(iter->ToURI()); | 45 proxy_retry_info.find(iter->ToURI()); |
40 if (bad_proxy != proxy_retry_info.end()) { | 46 if (bad_proxy != proxy_retry_info.end()) { |
41 // This proxy is bad. Check if it's time to retry. | 47 // This proxy is bad. Check if it's time to retry. |
42 if (bad_proxy->second.bad_until >= TimeTicks::Now()) { | 48 if (bad_proxy->second.bad_until >= TimeTicks::Now()) { |
43 // still invalid. | 49 // still invalid. |
| 50 bad_proxies.push_back(*iter); |
44 continue; | 51 continue; |
45 } | 52 } |
46 } | 53 } |
47 new_proxy_list.push_back(*iter); | 54 good_proxies.push_back(*iter); |
48 } | 55 } |
49 | 56 |
50 proxies_ = new_proxy_list; | 57 // "proxies_ = good_proxies + bad_proxies" |
| 58 proxies_.swap(good_proxies); |
| 59 proxies_.insert(proxies_.end(), bad_proxies.begin(), bad_proxies.end()); |
51 } | 60 } |
52 | 61 |
53 void ProxyList::RemoveProxiesWithoutScheme(int scheme_bit_field) { | 62 void ProxyList::RemoveProxiesWithoutScheme(int scheme_bit_field) { |
54 for (std::vector<ProxyServer>::iterator it = proxies_.begin(); | 63 for (std::vector<ProxyServer>::iterator it = proxies_.begin(); |
55 it != proxies_.end(); ) { | 64 it != proxies_.end(); ) { |
56 if (!(scheme_bit_field & it->scheme())) { | 65 if (!(scheme_bit_field & it->scheme())) { |
57 it = proxies_.erase(it); | 66 it = proxies_.erase(it); |
58 continue; | 67 continue; |
59 } | 68 } |
60 ++it; | 69 ++it; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 } | 147 } |
139 } | 148 } |
140 | 149 |
141 // Remove this proxy from our list. | 150 // Remove this proxy from our list. |
142 proxies_.erase(proxies_.begin()); | 151 proxies_.erase(proxies_.begin()); |
143 | 152 |
144 return !proxies_.empty(); | 153 return !proxies_.empty(); |
145 } | 154 } |
146 | 155 |
147 } // namespace net | 156 } // namespace net |
OLD | NEW |