Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: net/proxy/proxy_list.cc

Issue 1286373002: Refactored not to expose raw pointers on ProxyList class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 std::string proxy_list; 135 std::string proxy_list;
136 std::vector<ProxyServer>::const_iterator iter = proxies_.begin(); 136 std::vector<ProxyServer>::const_iterator iter = proxies_.begin();
137 for (; iter != proxies_.end(); ++iter) { 137 for (; iter != proxies_.end(); ++iter) {
138 if (!proxy_list.empty()) 138 if (!proxy_list.empty())
139 proxy_list += ";"; 139 proxy_list += ";";
140 proxy_list += iter->ToPacString(); 140 proxy_list += iter->ToPacString();
141 } 141 }
142 return proxy_list.empty() ? std::string() : proxy_list; 142 return proxy_list.empty() ? std::string() : proxy_list;
143 } 143 }
144 144
145 base::ListValue* ProxyList::ToValue() const { 145 scoped_ptr<base::ListValue> ProxyList::ToValue() const {
146 scoped_ptr<base::ListValue> list(new base::ListValue()); 146 scoped_ptr<base::ListValue> list(new base::ListValue());
147 for (size_t i = 0; i < proxies_.size(); ++i) 147 for (size_t i = 0; i < proxies_.size(); ++i)
148 list->AppendString(proxies_[i].ToURI()); 148 list->AppendString(proxies_[i].ToURI());
149 return list.release(); 149 return list.Pass();
150 } 150 }
151 151
152 bool ProxyList::Fallback(ProxyRetryInfoMap* proxy_retry_info, 152 bool ProxyList::Fallback(ProxyRetryInfoMap& proxy_retry_info,
153 int net_error, 153 int net_error,
154 const BoundNetLog& net_log) { 154 const BoundNetLog& net_log) {
155
156 // TODO(eroman): It would be good if instead of removing failed proxies 155 // TODO(eroman): It would be good if instead of removing failed proxies
157 // from the list, we simply annotated them with the error code they failed 156 // from the list, we simply annotated them with the error code they failed
158 // with. Of course, ProxyService::ReconsiderProxyAfterError() would need to 157 // with. Of course, ProxyService::ReconsiderProxyAfterError() would need to
159 // be given this information by the network transaction. 158 // be given this information by the network transaction.
160 // 159 //
161 // The advantage of this approach is when the network transaction 160 // The advantage of this approach is when the network transaction
162 // fails, we could output the full list of proxies that were attempted, and 161 // fails, we could output the full list of proxies that were attempted, and
163 // why each one of those failed (as opposed to just the last failure). 162 // why each one of those failed (as opposed to just the last failure).
164 // 163 //
165 // And also, before failing the transaction wholesale, we could go back and 164 // And also, before failing the transaction wholesale, we could go back and
166 // retry the "bad proxies" which we never tried to begin with. 165 // retry the "bad proxies" which we never tried to begin with.
167 // (RemoveBadProxies would annotate them as 'expected bad' rather then delete 166 // (RemoveBadProxies would annotate them as 'expected bad' rather then delete
168 // them from the list, so we would know what they were). 167 // them from the list, so we would know what they were).
169 168
170 if (proxies_.empty()) { 169 if (proxies_.empty()) {
171 NOTREACHED(); 170 NOTREACHED();
172 return false; 171 return false;
173 } 172 }
174 // By default, proxies are not retried for 5 minutes. 173 // By default, proxies are not retried for 5 minutes.
175 UpdateRetryInfoOnFallback(proxy_retry_info, TimeDelta::FromMinutes(5), true, 174 UpdateRetryInfoOnFallback(proxy_retry_info, TimeDelta::FromMinutes(5), true,
176 std::vector<ProxyServer>(), net_error, net_log); 175 std::vector<ProxyServer>(), net_error, net_log);
177 176
178 // Remove this proxy from our list. 177 // Remove this proxy from our list.
179 proxies_.erase(proxies_.begin()); 178 proxies_.erase(proxies_.begin());
180 return !proxies_.empty(); 179 return !proxies_.empty();
181 } 180 }
182 181
183 void ProxyList::AddProxyToRetryList(ProxyRetryInfoMap* proxy_retry_info, 182 void ProxyList::AddProxyToRetryList(ProxyRetryInfoMap& proxy_retry_info,
184 base::TimeDelta retry_delay, 183 base::TimeDelta retry_delay,
185 bool try_while_bad, 184 bool try_while_bad,
186 const ProxyServer& proxy_to_retry, 185 const ProxyServer& proxy_to_retry,
187 int net_error, 186 int net_error,
188 const BoundNetLog& net_log) const { 187 const BoundNetLog& net_log) const {
189 // Mark this proxy as bad. 188 // Mark this proxy as bad.
190 TimeTicks bad_until = TimeTicks::Now() + retry_delay; 189 TimeTicks bad_until = TimeTicks::Now() + retry_delay;
191 std::string proxy_key = proxy_to_retry.ToURI(); 190 std::string proxy_key = proxy_to_retry.ToURI();
192 ProxyRetryInfoMap::iterator iter = proxy_retry_info->find(proxy_key); 191 ProxyRetryInfoMap::iterator iter = proxy_retry_info.find(proxy_key);
193 if (iter == proxy_retry_info->end() || bad_until > iter->second.bad_until) { 192 if (iter == proxy_retry_info.end() || bad_until > iter->second.bad_until) {
194 ProxyRetryInfo retry_info; 193 ProxyRetryInfo retry_info;
195 retry_info.current_delay = retry_delay; 194 retry_info.current_delay = retry_delay;
196 retry_info.bad_until = bad_until; 195 retry_info.bad_until = bad_until;
197 retry_info.try_while_bad = try_while_bad; 196 retry_info.try_while_bad = try_while_bad;
198 retry_info.net_error = net_error; 197 retry_info.net_error = net_error;
199 (*proxy_retry_info)[proxy_key] = retry_info; 198 proxy_retry_info[proxy_key] = retry_info;
200 } 199 }
201 net_log.AddEvent(NetLog::TYPE_PROXY_LIST_FALLBACK, 200 net_log.AddEvent(NetLog::TYPE_PROXY_LIST_FALLBACK,
202 NetLog::StringCallback("bad_proxy", &proxy_key)); 201 NetLog::StringCallback("bad_proxy", &proxy_key));
203 } 202 }
204 203
205 void ProxyList::UpdateRetryInfoOnFallback( 204 void ProxyList::UpdateRetryInfoOnFallback(
206 ProxyRetryInfoMap* proxy_retry_info, 205 ProxyRetryInfoMap& proxy_retry_info,
207 base::TimeDelta retry_delay, 206 base::TimeDelta retry_delay,
208 bool reconsider, 207 bool reconsider,
209 const std::vector<ProxyServer>& additional_proxies_to_bypass, 208 const std::vector<ProxyServer>& additional_proxies_to_bypass,
210 int net_error, 209 int net_error,
211 const BoundNetLog& net_log) const { 210 const BoundNetLog& net_log) const {
212 DCHECK(retry_delay != base::TimeDelta()); 211 DCHECK(retry_delay != base::TimeDelta());
213 212
214 if (proxies_.empty()) { 213 if (proxies_.empty()) {
215 NOTREACHED(); 214 NOTREACHED();
216 return; 215 return;
217 } 216 }
218 217
219 if (!proxies_[0].is_direct()) { 218 if (!proxies_[0].is_direct()) {
220 AddProxyToRetryList(proxy_retry_info, 219 AddProxyToRetryList(proxy_retry_info,
221 retry_delay, 220 retry_delay,
222 reconsider, 221 reconsider,
223 proxies_[0], 222 proxies_[0],
224 net_error, 223 net_error,
225 net_log); 224 net_log);
226 // If any additional proxies to bypass are specified, add to the retry map 225 // If any additional proxies to bypass are specified, add to the retry map
227 // as well. 226 // as well.
228 for (const ProxyServer& additional_proxy : additional_proxies_to_bypass) { 227 for (const ProxyServer& additional_proxy : additional_proxies_to_bypass) {
229 AddProxyToRetryList(proxy_retry_info, retry_delay, reconsider, 228 AddProxyToRetryList(proxy_retry_info, retry_delay, reconsider,
230 additional_proxy, net_error, net_log); 229 additional_proxy, net_error, net_log);
231 } 230 }
232 } 231 }
233 } 232 }
234 233
235 } // namespace net 234 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698