| 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/time.h" | 10 #include "base/time/time.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } | 139 } |
| 140 | 140 |
| 141 base::ListValue* ProxyList::ToValue() const { | 141 base::ListValue* ProxyList::ToValue() const { |
| 142 base::ListValue* list = new base::ListValue(); | 142 base::ListValue* list = new base::ListValue(); |
| 143 for (size_t i = 0; i < proxies_.size(); ++i) | 143 for (size_t i = 0; i < proxies_.size(); ++i) |
| 144 list->AppendString(proxies_[i].ToURI()); | 144 list->AppendString(proxies_[i].ToURI()); |
| 145 return list; | 145 return list; |
| 146 } | 146 } |
| 147 | 147 |
| 148 bool ProxyList::Fallback(ProxyRetryInfoMap* proxy_retry_info, | 148 bool ProxyList::Fallback(ProxyRetryInfoMap* proxy_retry_info, |
| 149 const int net_error, |
| 149 const BoundNetLog& net_log) { | 150 const BoundNetLog& net_log) { |
| 150 | 151 |
| 151 // TODO(eroman): It would be good if instead of removing failed proxies | 152 // TODO(eroman): It would be good if instead of removing failed proxies |
| 152 // from the list, we simply annotated them with the error code they failed | 153 // from the list, we simply annotated them with the error code they failed |
| 153 // with. Of course, ProxyService::ReconsiderProxyAfterError() would need to | 154 // with. Of course, ProxyService::ReconsiderProxyAfterError() would need to |
| 154 // be given this information by the network transaction. | 155 // be given this information by the network transaction. |
| 155 // | 156 // |
| 156 // The advantage of this approach is when the network transaction | 157 // The advantage of this approach is when the network transaction |
| 157 // fails, we could output the full list of proxies that were attempted, and | 158 // fails, we could output the full list of proxies that were attempted, and |
| 158 // why each one of those failed (as opposed to just the last failure). | 159 // why each one of those failed (as opposed to just the last failure). |
| 159 // | 160 // |
| 160 // And also, before failing the transaction wholesale, we could go back and | 161 // And also, before failing the transaction wholesale, we could go back and |
| 161 // retry the "bad proxies" which we never tried to begin with. | 162 // retry the "bad proxies" which we never tried to begin with. |
| 162 // (RemoveBadProxies would annotate them as 'expected bad' rather then delete | 163 // (RemoveBadProxies would annotate them as 'expected bad' rather then delete |
| 163 // them from the list, so we would know what they were). | 164 // them from the list, so we would know what they were). |
| 164 | 165 |
| 165 if (proxies_.empty()) { | 166 if (proxies_.empty()) { |
| 166 NOTREACHED(); | 167 NOTREACHED(); |
| 167 return false; | 168 return false; |
| 168 } | 169 } |
| 169 // By default, proxies are not retried for 5 minutes. | 170 // By default, proxies are not retried for 5 minutes. |
| 170 UpdateRetryInfoOnFallback(proxy_retry_info, | 171 UpdateRetryInfoOnFallback(proxy_retry_info, |
| 171 TimeDelta::FromMinutes(5), | 172 TimeDelta::FromMinutes(5), |
| 172 true, | 173 true, |
| 173 ProxyServer(), | 174 ProxyServer(), |
| 175 net_error, |
| 174 net_log); | 176 net_log); |
| 175 | 177 |
| 176 // Remove this proxy from our list. | 178 // Remove this proxy from our list. |
| 177 proxies_.erase(proxies_.begin()); | 179 proxies_.erase(proxies_.begin()); |
| 178 return !proxies_.empty(); | 180 return !proxies_.empty(); |
| 179 } | 181 } |
| 180 | 182 |
| 181 void ProxyList::AddProxyToRetryList(ProxyRetryInfoMap* proxy_retry_info, | 183 void ProxyList::AddProxyToRetryList(ProxyRetryInfoMap* proxy_retry_info, |
| 182 base::TimeDelta retry_delay, | 184 base::TimeDelta retry_delay, |
| 183 bool try_while_bad, | 185 bool try_while_bad, |
| 184 const ProxyServer& proxy_to_retry, | 186 const ProxyServer& proxy_to_retry, |
| 187 const int net_error, |
| 185 const BoundNetLog& net_log) const { | 188 const BoundNetLog& net_log) const { |
| 186 // Mark this proxy as bad. | 189 // Mark this proxy as bad. |
| 187 std::string proxy_key = proxy_to_retry.ToURI(); | 190 std::string proxy_key = proxy_to_retry.ToURI(); |
| 188 ProxyRetryInfoMap::iterator iter = proxy_retry_info->find(proxy_key); | 191 ProxyRetryInfoMap::iterator iter = proxy_retry_info->find(proxy_key); |
| 189 if (iter != proxy_retry_info->end()) { | 192 if (iter != proxy_retry_info->end()) { |
| 190 // TODO(nsylvain): This is not the first time we get this. We should | 193 // TODO(nsylvain): This is not the first time we get this. We should |
| 191 // double the retry time. Bug 997660. | 194 // double the retry time. Bug 997660. |
| 192 iter->second.bad_until = TimeTicks::Now() + iter->second.current_delay; | 195 iter->second.bad_until = TimeTicks::Now() + iter->second.current_delay; |
| 193 } else { | 196 } else { |
| 194 ProxyRetryInfo retry_info; | 197 ProxyRetryInfo retry_info; |
| 195 retry_info.current_delay = retry_delay; | 198 retry_info.current_delay = retry_delay; |
| 196 retry_info.bad_until = TimeTicks().Now() + retry_info.current_delay; | 199 retry_info.bad_until = TimeTicks().Now() + retry_info.current_delay; |
| 197 retry_info.try_while_bad = try_while_bad; | 200 retry_info.try_while_bad = try_while_bad; |
| 201 retry_info.net_error = net_error; |
| 198 (*proxy_retry_info)[proxy_key] = retry_info; | 202 (*proxy_retry_info)[proxy_key] = retry_info; |
| 199 } | 203 } |
| 200 net_log.AddEvent(NetLog::TYPE_PROXY_LIST_FALLBACK, | 204 net_log.AddEvent(NetLog::TYPE_PROXY_LIST_FALLBACK, |
| 201 NetLog::StringCallback("bad_proxy", &proxy_key)); | 205 NetLog::StringCallback("bad_proxy", &proxy_key)); |
| 202 } | 206 } |
| 203 | 207 |
| 204 void ProxyList::UpdateRetryInfoOnFallback( | 208 void ProxyList::UpdateRetryInfoOnFallback( |
| 205 ProxyRetryInfoMap* proxy_retry_info, | 209 ProxyRetryInfoMap* proxy_retry_info, |
| 206 base::TimeDelta retry_delay, | 210 base::TimeDelta retry_delay, |
| 207 bool reconsider, | 211 bool reconsider, |
| 208 const ProxyServer& another_proxy_to_bypass, | 212 const ProxyServer& another_proxy_to_bypass, |
| 213 const int net_error, |
| 209 const BoundNetLog& net_log) const { | 214 const BoundNetLog& net_log) const { |
| 210 DCHECK(retry_delay != base::TimeDelta()); | 215 DCHECK(retry_delay != base::TimeDelta()); |
| 211 | 216 |
| 212 if (proxies_.empty()) { | 217 if (proxies_.empty()) { |
| 213 NOTREACHED(); | 218 NOTREACHED(); |
| 214 return; | 219 return; |
| 215 } | 220 } |
| 216 | 221 |
| 217 if (!proxies_[0].is_direct()) { | 222 if (!proxies_[0].is_direct()) { |
| 218 AddProxyToRetryList(proxy_retry_info, retry_delay, reconsider, proxies_[0], | 223 AddProxyToRetryList(proxy_retry_info, |
| 224 retry_delay, |
| 225 reconsider, |
| 226 proxies_[0], |
| 227 net_error, |
| 219 net_log); | 228 net_log); |
| 220 | 229 |
| 221 // If an additional proxy to bypass is specified, add it to the retry map | 230 // If an additional proxy to bypass is specified, add it to the retry map |
| 222 // as well. | 231 // as well. |
| 223 if (another_proxy_to_bypass.is_valid()) { | 232 if (another_proxy_to_bypass.is_valid()) { |
| 224 AddProxyToRetryList(proxy_retry_info, retry_delay, reconsider, | 233 AddProxyToRetryList(proxy_retry_info, |
| 225 another_proxy_to_bypass, net_log); | 234 retry_delay, |
| 235 reconsider, |
| 236 another_proxy_to_bypass, |
| 237 net_error, |
| 238 net_log); |
| 226 } | 239 } |
| 227 } | 240 } |
| 228 } | 241 } |
| 229 | 242 |
| 230 } // namespace net | 243 } // namespace net |
| OLD | NEW |