Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / net / proxy / proxy_list.h
blobaa477d2083834fd7cf5d1bb3c305c600c5926931
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_
8 #include <string>
9 #include <vector>
11 #include "net/base/net_export.h"
12 #include "net/log/net_log.h"
13 #include "net/proxy/proxy_retry_info.h"
15 namespace base {
16 class ListValue;
17 class TimeDelta;
20 namespace net {
22 class ProxyServer;
24 // This class is used to hold a list of proxies returned by GetProxyForUrl or
25 // manually configured. It handles proxy fallback if multiple servers are
26 // specified.
27 class NET_EXPORT_PRIVATE ProxyList {
28 public:
29 ProxyList();
30 ~ProxyList();
32 // Initializes the proxy list to a string containing one or more proxy servers
33 // delimited by a semicolon.
34 void Set(const std::string& proxy_uri_list);
36 // Set the proxy list to a single entry, |proxy_server|.
37 void SetSingleProxyServer(const ProxyServer& proxy_server);
39 // Append a single proxy server to the end of the proxy list.
40 void AddProxyServer(const ProxyServer& proxy_server);
42 // De-prioritizes the proxies that are cached as not working but are allowed
43 // to be reconsidered, by moving them to the end of the fallback list.
44 void DeprioritizeBadProxies(const ProxyRetryInfoMap& proxy_retry_info);
46 // Delete any entry which doesn't have one of the specified proxy schemes.
47 // |scheme_bit_field| is a bunch of ProxyServer::Scheme bitwise ORed together.
48 void RemoveProxiesWithoutScheme(int scheme_bit_field);
50 // Clear the proxy list.
51 void Clear();
53 // Returns true if there is nothing left in the ProxyList.
54 bool IsEmpty() const;
56 // Returns the number of proxy servers in this list.
57 size_t size() const;
59 // Returns true if |*this| lists the same proxies as |other|.
60 bool Equals(const ProxyList& other) const;
62 // Returns the first proxy server in the list. It is only valid to call
63 // this if !IsEmpty().
64 const ProxyServer& Get() const;
66 // Returns all proxy servers in the list.
67 const std::vector<ProxyServer>& GetAll() const;
69 // Sets the list by parsing the pac result |pac_string|.
70 // Some examples for |pac_string|:
71 // "DIRECT"
72 // "PROXY foopy1"
73 // "PROXY foopy1; SOCKS4 foopy2:1188"
74 // Does a best-effort parse, and silently discards any errors.
75 void SetFromPacString(const std::string& pac_string);
77 // Returns a PAC-style semicolon-separated list of valid proxy servers.
78 // For example: "PROXY xxx.xxx.xxx.xxx:xx; SOCKS yyy.yyy.yyy:yy".
79 std::string ToPacString() const;
81 // Returns a serialized value for the list. The caller takes ownership of it.
82 base::ListValue* ToValue() const;
84 // Marks the current proxy server as bad and deletes it from the list. The
85 // list of known bad proxies is given by |proxy_retry_info|. |net_error|
86 // should contain the network error encountered when this proxy was tried, if
87 // any. If this fallback is not because of a network error, then |OK| should
88 // be passed in (eg. for reasons such as local policy). Returns true if there
89 // is another server available in the list.
90 bool Fallback(ProxyRetryInfoMap* proxy_retry_info,
91 int net_error,
92 const BoundNetLog& net_log);
94 // Updates |proxy_retry_info| to indicate that the first proxy in the list
95 // is bad. This is distinct from Fallback(), above, to allow updating proxy
96 // retry information without modifying a given transction's proxy list. Will
97 // retry after |retry_delay| if positive, and will use the default proxy retry
98 // duration otherwise. It may reconsider the proxy beforehand if |reconsider|
99 // is true. Additionally updates |proxy_retry_info| with
100 // |additional_proxies_to_bypass|. |net_error| should contain the network
101 // error countered when this proxy was tried, or OK if the proxy retry info is
102 // being updated for a non-network related reason (e.g. local policy).
103 void UpdateRetryInfoOnFallback(
104 ProxyRetryInfoMap* proxy_retry_info,
105 base::TimeDelta retry_delay,
106 bool reconsider,
107 const std::vector<ProxyServer>& additional_proxies_to_bypass,
108 int net_error,
109 const BoundNetLog& net_log) const;
111 private:
112 // Updates |proxy_retry_info| to indicate that the |proxy_to_retry| in
113 // |proxies_| is bad for |retry_delay|, but may be reconsidered earlier if
114 // |try_while_bad| is true. |net_error| should contain the network error
115 // countered when this proxy was tried, or OK if the proxy retry info is
116 // being updated for a non-network related reason (e.g. local policy).
117 void AddProxyToRetryList(ProxyRetryInfoMap* proxy_retry_info,
118 base::TimeDelta retry_delay,
119 bool try_while_bad,
120 const ProxyServer& proxy_to_retry,
121 int net_error,
122 const BoundNetLog& net_log) const;
124 // List of proxies.
125 std::vector<ProxyServer> proxies_;
128 } // namespace net
130 #endif // NET_PROXY_PROXY_LIST_H_