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
3 // found in the LICENSE file.
5 #ifndef NET_PROXY_PROXY_LIST_H_
6 #define NET_PROXY_PROXY_LIST_H_
11 #include "net/base/net_export.h"
12 #include "net/base/net_log.h"
13 #include "net/proxy/proxy_retry_info.h"
19 // This class is used to hold a list of proxies returned by GetProxyForUrl or
20 // manually configured. It handles proxy fallback if multiple servers are
22 class NET_EXPORT_PRIVATE ProxyList
{
27 // Initializes the proxy list to a string containing one or more proxy servers
28 // delimited by a semicolon.
29 void Set(const std::string
& proxy_uri_list
);
31 // Set the proxy list to a single entry, |proxy_server|.
32 void SetSingleProxyServer(const ProxyServer
& proxy_server
);
34 // De-prioritizes the proxies that we have cached as not working, by moving
35 // them to the end of the fallback list.
36 void DeprioritizeBadProxies(const ProxyRetryInfoMap
& proxy_retry_info
);
38 // Returns true if this proxy list contains at least one proxy that is
39 // not currently present in |proxy_retry_info|.
40 bool HasUntriedProxies(const ProxyRetryInfoMap
& proxy_retry_info
) const;
42 // Delete any entry which doesn't have one of the specified proxy schemes.
43 // |scheme_bit_field| is a bunch of ProxyServer::Scheme bitwise ORed together.
44 void RemoveProxiesWithoutScheme(int scheme_bit_field
);
46 // Clear the proxy list.
49 // Returns true if there is nothing left in the ProxyList.
52 // Returns the number of proxy servers in this list.
55 // Returns the first proxy server in the list. It is only valid to call
56 // this if !IsEmpty().
57 const ProxyServer
& Get() const;
59 // Sets the list by parsing the pac result |pac_string|.
60 // Some examples for |pac_string|:
63 // "PROXY foopy1; SOCKS4 foopy2:1188"
64 // Does a best-effort parse, and silently discards any errors.
65 void SetFromPacString(const std::string
& pac_string
);
67 // Returns a PAC-style semicolon-separated list of valid proxy servers.
68 // For example: "PROXY xxx.xxx.xxx.xxx:xx; SOCKS yyy.yyy.yyy:yy".
69 std::string
ToPacString() const;
71 // Marks the current proxy server as bad and deletes it from the list. The
72 // list of known bad proxies is given by proxy_retry_info. Returns true if
73 // there is another server available in the list.
74 bool Fallback(ProxyRetryInfoMap
* proxy_retry_info
,
75 const BoundNetLog
& net_log
);
77 // Updates |proxy_retry_info| to indicate that the first proxy in the list
78 // is bad. This is distinct from Fallback(), above, to allow updating proxy
79 // retry information without modifying a given transction's proxy list.
80 void UpdateRetryInfoOnFallback(ProxyRetryInfoMap
* proxy_retry_info
,
81 const BoundNetLog
& net_log
) const;
85 std::vector
<ProxyServer
> proxies_
;
90 #endif // NET_PROXY_PROXY_LIST_H_