Chromium Code Reviews| 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_list.h" | 5 #include "net/proxy/proxy_list.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/string_tokenizer.h" | 9 #include "base/strings/string_tokenizer.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 ProxyServer uri = ProxyServer::FromURI( | 28 ProxyServer uri = ProxyServer::FromURI( |
| 29 str_tok.token_begin(), str_tok.token_end(), ProxyServer::SCHEME_HTTP); | 29 str_tok.token_begin(), str_tok.token_end(), ProxyServer::SCHEME_HTTP); |
| 30 // Silently discard malformed inputs. | 30 // Silently discard malformed inputs. |
| 31 if (uri.is_valid()) | 31 if (uri.is_valid()) |
| 32 proxies_.push_back(uri); | 32 proxies_.push_back(uri); |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 | 35 |
| 36 void ProxyList::SetSingleProxyServer(const ProxyServer& proxy_server) { | 36 void ProxyList::SetSingleProxyServer(const ProxyServer& proxy_server) { |
| 37 proxies_.clear(); | 37 proxies_.clear(); |
| 38 AddProxyServer(proxy_server); | |
| 39 } | |
| 40 | |
| 41 void ProxyList::AddProxyServer(const ProxyServer& proxy_server) { | |
| 38 if (proxy_server.is_valid()) | 42 if (proxy_server.is_valid()) |
| 39 proxies_.push_back(proxy_server); | 43 proxies_.push_back(proxy_server); |
| 40 } | 44 } |
| 41 | 45 |
| 42 void ProxyList::DeprioritizeBadProxies( | 46 void ProxyList::DeprioritizeBadProxies( |
| 43 const ProxyRetryInfoMap& proxy_retry_info) { | 47 const ProxyRetryInfoMap& proxy_retry_info) { |
| 44 // Partition the proxy list in two: | 48 // Partition the proxy list in two: |
| 45 // (1) the known bad proxies | 49 // (1) the known bad proxies |
| 46 // (2) everything else | 50 // (2) everything else |
| 47 std::vector<ProxyServer> good_proxies; | 51 std::vector<ProxyServer> good_proxies; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 } | 107 } |
| 104 | 108 |
| 105 bool ProxyList::IsEmpty() const { | 109 bool ProxyList::IsEmpty() const { |
| 106 return proxies_.empty(); | 110 return proxies_.empty(); |
| 107 } | 111 } |
| 108 | 112 |
| 109 size_t ProxyList::size() const { | 113 size_t ProxyList::size() const { |
| 110 return proxies_.size(); | 114 return proxies_.size(); |
| 111 } | 115 } |
| 112 | 116 |
| 117 // Returns true if |*this| lists the same proxies as |other|. | |
| 118 bool ProxyList::Equals(const ProxyList& other) const { | |
| 119 if (size() != other.size()) | |
| 120 return false; | |
| 121 return ToPacString() == other.ToPacString(); | |
|
eroman
2013/02/26 01:13:50
Not ideal. I will allow it though.
marq_use_my_chromium_address
2013/02/27 23:08:19
ProxyServer has an == operator, so I can just comp
| |
| 122 } | |
| 123 | |
| 113 const ProxyServer& ProxyList::Get() const { | 124 const ProxyServer& ProxyList::Get() const { |
| 114 DCHECK(!proxies_.empty()); | 125 DCHECK(!proxies_.empty()); |
| 115 return proxies_[0]; | 126 return proxies_[0]; |
| 116 } | 127 } |
| 117 | 128 |
| 118 void ProxyList::SetFromPacString(const std::string& pac_string) { | 129 void ProxyList::SetFromPacString(const std::string& pac_string) { |
| 119 base::StringTokenizer entry_tok(pac_string, ";"); | 130 base::StringTokenizer entry_tok(pac_string, ";"); |
| 120 proxies_.clear(); | 131 proxies_.clear(); |
| 121 while (entry_tok.GetNext()) { | 132 while (entry_tok.GetNext()) { |
| 122 ProxyServer uri = ProxyServer::FromPacString( | 133 ProxyServer uri = ProxyServer::FromPacString( |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 retry_info.current_delay = kProxyRetryDelay; | 210 retry_info.current_delay = kProxyRetryDelay; |
| 200 retry_info.bad_until = TimeTicks().Now() + retry_info.current_delay; | 211 retry_info.bad_until = TimeTicks().Now() + retry_info.current_delay; |
| 201 (*proxy_retry_info)[key] = retry_info; | 212 (*proxy_retry_info)[key] = retry_info; |
| 202 } | 213 } |
| 203 net_log.AddEvent(NetLog::TYPE_PROXY_LIST_FALLBACK, | 214 net_log.AddEvent(NetLog::TYPE_PROXY_LIST_FALLBACK, |
| 204 NetLog::StringCallback("bad_proxy", &key)); | 215 NetLog::StringCallback("bad_proxy", &key)); |
| 205 } | 216 } |
| 206 } | 217 } |
| 207 | 218 |
| 208 } // namespace net | 219 } // namespace net |
| OLD | NEW |