| 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 #include "net/proxy/proxy_server.h" | 10 #include "net/proxy/proxy_server.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 bool ProxyList::IsEmpty() const { | 80 bool ProxyList::IsEmpty() const { |
| 81 return proxies_.empty(); | 81 return proxies_.empty(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 const ProxyServer& ProxyList::Get() const { | 84 const ProxyServer& ProxyList::Get() const { |
| 85 DCHECK(!proxies_.empty()); | 85 DCHECK(!proxies_.empty()); |
| 86 return proxies_[0]; | 86 return proxies_[0]; |
| 87 } | 87 } |
| 88 | 88 |
| 89 std::string ProxyList::ToPacString() const { | |
| 90 std::string proxy_list; | |
| 91 std::vector<ProxyServer>::const_iterator iter = proxies_.begin(); | |
| 92 for (; iter != proxies_.end(); ++iter) { | |
| 93 if (!proxy_list.empty()) | |
| 94 proxy_list += ";"; | |
| 95 proxy_list += iter->ToPacString(); | |
| 96 } | |
| 97 return proxy_list.empty() ? std::string() : proxy_list; | |
| 98 } | |
| 99 | |
| 100 void ProxyList::SetFromPacString(const std::string& pac_string) { | 89 void ProxyList::SetFromPacString(const std::string& pac_string) { |
| 101 StringTokenizer entry_tok(pac_string, ";"); | 90 StringTokenizer entry_tok(pac_string, ";"); |
| 102 proxies_.clear(); | 91 proxies_.clear(); |
| 103 while (entry_tok.GetNext()) { | 92 while (entry_tok.GetNext()) { |
| 104 ProxyServer uri = ProxyServer::FromPacString( | 93 ProxyServer uri = ProxyServer::FromPacString( |
| 105 entry_tok.token_begin(), entry_tok.token_end()); | 94 entry_tok.token_begin(), entry_tok.token_end()); |
| 106 // Silently discard malformed inputs. | 95 // Silently discard malformed inputs. |
| 107 if (uri.is_valid()) | 96 if (uri.is_valid()) |
| 108 proxies_.push_back(uri); | 97 proxies_.push_back(uri); |
| 109 } | 98 } |
| 110 | 99 |
| 111 // If we failed to parse anything from the PAC results list, fallback to | 100 // If we failed to parse anything from the PAC results list, fallback to |
| 112 // DIRECT (this basically means an error in the PAC script). | 101 // DIRECT (this basically means an error in the PAC script). |
| 113 if (proxies_.empty()) { | 102 if (proxies_.empty()) { |
| 114 proxies_.push_back(ProxyServer::Direct()); | 103 proxies_.push_back(ProxyServer::Direct()); |
| 115 } | 104 } |
| 116 } | 105 } |
| 117 | 106 |
| 107 std::string ProxyList::ToPacString() const { |
| 108 std::string proxy_list; |
| 109 std::vector<ProxyServer>::const_iterator iter = proxies_.begin(); |
| 110 for (; iter != proxies_.end(); ++iter) { |
| 111 if (!proxy_list.empty()) |
| 112 proxy_list += ";"; |
| 113 proxy_list += iter->ToPacString(); |
| 114 } |
| 115 return proxy_list.empty() ? std::string() : proxy_list; |
| 116 } |
| 117 |
| 118 bool ProxyList::Fallback(ProxyRetryInfoMap* proxy_retry_info) { | 118 bool ProxyList::Fallback(ProxyRetryInfoMap* proxy_retry_info) { |
| 119 // Number of minutes to wait before retrying a bad proxy server. | 119 // Number of minutes to wait before retrying a bad proxy server. |
| 120 const TimeDelta kProxyRetryDelay = TimeDelta::FromMinutes(5); | 120 const TimeDelta kProxyRetryDelay = TimeDelta::FromMinutes(5); |
| 121 | 121 |
| 122 // TODO(eroman): It would be good if instead of removing failed proxies | 122 // TODO(eroman): It would be good if instead of removing failed proxies |
| 123 // from the list, we simply annotated them with the error code they failed | 123 // from the list, we simply annotated them with the error code they failed |
| 124 // with. Of course, ProxyService::ReconsiderProxyAfterError() would need to | 124 // with. Of course, ProxyService::ReconsiderProxyAfterError() would need to |
| 125 // be given this information by the network transaction. | 125 // be given this information by the network transaction. |
| 126 // | 126 // |
| 127 // The advantage of this approach is when the network transaction | 127 // The advantage of this approach is when the network transaction |
| (...skipping 26 matching lines...) Expand all Loading... |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 | 156 |
| 157 // Remove this proxy from our list. | 157 // Remove this proxy from our list. |
| 158 proxies_.erase(proxies_.begin()); | 158 proxies_.erase(proxies_.begin()); |
| 159 | 159 |
| 160 return !proxies_.empty(); | 160 return !proxies_.empty(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 } // namespace net | 163 } // namespace net |
| OLD | NEW |