blob: 7455c23fc850556606e62da4167337d0d6e8af6a [file] [log] [blame]
[email protected]db8ff912012-06-12 23:32:511// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]7dc52f22009-03-02 22:37:182// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef NET_PROXY_PROXY_LIST_H_
6#define NET_PROXY_PROXY_LIST_H_
7
Avi Drissman13fc8932015-12-20 04:40:468#include <stddef.h>
9
mikecironef22f9812016-10-04 03:40:1910#include <memory>
[email protected]7dc52f22009-03-02 22:37:1811#include <string>
12#include <vector>
13
[email protected]172da1b2011-08-12 15:52:2614#include "net/base/net_export.h"
[email protected]7dc52f22009-03-02 22:37:1815#include "net/proxy/proxy_retry_info.h"
[email protected]7dc52f22009-03-02 22:37:1816
[email protected]117d54f2013-03-30 17:29:4317namespace base {
18class ListValue;
[email protected]3d498f72013-10-28 21:17:4019class TimeDelta;
[email protected]117d54f2013-03-30 17:29:4320}
21
[email protected]7dc52f22009-03-02 22:37:1822namespace net {
23
[email protected]20f0487a2010-09-30 20:06:3024class ProxyServer;
mikecironef22f9812016-10-04 03:40:1925class NetLogWithSource;
[email protected]20f0487a2010-09-30 20:06:3026
[email protected]7dc52f22009-03-02 22:37:1827// This class is used to hold a list of proxies returned by GetProxyForUrl or
28// manually configured. It handles proxy fallback if multiple servers are
29// specified.
[email protected]172da1b2011-08-12 15:52:2630class NET_EXPORT_PRIVATE ProxyList {
[email protected]7dc52f22009-03-02 22:37:1831 public:
[email protected]20f0487a2010-09-30 20:06:3032 ProxyList();
vmpstracd23b72016-02-26 21:08:5533 ProxyList(const ProxyList& other);
[email protected]20f0487a2010-09-30 20:06:3034 ~ProxyList();
35
[email protected]7dc52f22009-03-02 22:37:1836 // Initializes the proxy list to a string containing one or more proxy servers
37 // delimited by a semicolon.
38 void Set(const std::string& proxy_uri_list);
39
[email protected]5b45aec02009-03-31 01:03:2340 // Set the proxy list to a single entry, |proxy_server|.
41 void SetSingleProxyServer(const ProxyServer& proxy_server);
42
[email protected]2189e092013-03-16 18:02:0243 // Append a single proxy server to the end of the proxy list.
44 void AddProxyServer(const ProxyServer& proxy_server);
45
[email protected]d2b237502014-02-27 01:45:0646 // De-prioritizes the proxies that are cached as not working but are allowed
47 // to be reconsidered, by moving them to the end of the fallback list.
[email protected]02cf5a42010-01-12 22:10:2548 void DeprioritizeBadProxies(const ProxyRetryInfoMap& proxy_retry_info);
[email protected]7dc52f22009-03-02 22:37:1849
50 // Delete any entry which doesn't have one of the specified proxy schemes.
51 // |scheme_bit_field| is a bunch of ProxyServer::Scheme bitwise ORed together.
52 void RemoveProxiesWithoutScheme(int scheme_bit_field);
53
[email protected]db8ff912012-06-12 23:32:5154 // Clear the proxy list.
55 void Clear();
56
[email protected]69719062010-01-05 20:09:2157 // Returns true if there is nothing left in the ProxyList.
58 bool IsEmpty() const;
59
[email protected]db8ff912012-06-12 23:32:5160 // Returns the number of proxy servers in this list.
61 size_t size() const;
62
[email protected]2189e092013-03-16 18:02:0263 // Returns true if |*this| lists the same proxies as |other|.
64 bool Equals(const ProxyList& other) const;
65
[email protected]69719062010-01-05 20:09:2166 // Returns the first proxy server in the list. It is only valid to call
67 // this if !IsEmpty().
68 const ProxyServer& Get() const;
[email protected]7dc52f22009-03-02 22:37:1869
sammc5403aa1d2015-02-25 04:59:2170 // Returns all proxy servers in the list.
71 const std::vector<ProxyServer>& GetAll() const;
72
[email protected]aacc8f12010-06-23 17:24:4073 // Sets the list by parsing the pac result |pac_string|.
[email protected]7dc52f22009-03-02 22:37:1874 // Some examples for |pac_string|:
75 // "DIRECT"
76 // "PROXY foopy1"
77 // "PROXY foopy1; SOCKS4 foopy2:1188"
[email protected]aacc8f12010-06-23 17:24:4078 // Does a best-effort parse, and silently discards any errors.
[email protected]7dc52f22009-03-02 22:37:1879 void SetFromPacString(const std::string& pac_string);
80
81 // Returns a PAC-style semicolon-separated list of valid proxy servers.
82 // For example: "PROXY xxx.xxx.xxx.xxx:xx; SOCKS yyy.yyy.yyy:yy".
83 std::string ToPacString() const;
84
msu.koo4e6518f2015-08-25 01:58:2985 // Returns a serialized value for the list.
danakj8a98ca22016-04-16 02:47:3686 std::unique_ptr<base::ListValue> ToValue() const;
[email protected]117d54f2013-03-30 17:29:4387
[email protected]d0483b192014-08-15 23:50:1788 // Marks the current proxy server as bad and deletes it from the list. The
89 // list of known bad proxies is given by |proxy_retry_info|. |net_error|
90 // should contain the network error encountered when this proxy was tried, if
91 // any. If this fallback is not because of a network error, then |OK| should
92 // be passed in (eg. for reasons such as local policy). Returns true if there
93 // is another server available in the list.
[email protected]96e1933f2011-08-29 16:39:0094 bool Fallback(ProxyRetryInfoMap* proxy_retry_info,
[email protected]d0483b192014-08-15 23:50:1795 int net_error,
tfarina42834112016-09-22 13:38:2096 const NetLogWithSource& net_log);
[email protected]7dc52f22009-03-02 22:37:1897
[email protected]14b7e9a2012-10-16 19:51:2998 // Updates |proxy_retry_info| to indicate that the first proxy in the list
99 // is bad. This is distinct from Fallback(), above, to allow updating proxy
[email protected]3d498f72013-10-28 21:17:40100 // retry information without modifying a given transction's proxy list. Will
101 // retry after |retry_delay| if positive, and will use the default proxy retry
[email protected]d2b237502014-02-27 01:45:06102 // duration otherwise. It may reconsider the proxy beforehand if |reconsider|
103 // is true. Additionally updates |proxy_retry_info| with
jeremyim793a4712015-05-14 17:04:00104 // |additional_proxies_to_bypass|. |net_error| should contain the network
105 // error countered when this proxy was tried, or OK if the proxy retry info is
106 // being updated for a non-network related reason (e.g. local policy).
[email protected]a4fd43a2013-12-13 20:42:27107 void UpdateRetryInfoOnFallback(
108 ProxyRetryInfoMap* proxy_retry_info,
109 base::TimeDelta retry_delay,
[email protected]d2b237502014-02-27 01:45:06110 bool reconsider,
jeremyim793a4712015-05-14 17:04:00111 const std::vector<ProxyServer>& additional_proxies_to_bypass,
[email protected]d0483b192014-08-15 23:50:17112 int net_error,
tfarina42834112016-09-22 13:38:20113 const NetLogWithSource& net_log) const;
[email protected]14b7e9a2012-10-16 19:51:29114
[email protected]7dc52f22009-03-02 22:37:18115 private:
[email protected]15952a22013-12-19 04:08:25116 // Updates |proxy_retry_info| to indicate that the |proxy_to_retry| in
[email protected]d2b237502014-02-27 01:45:06117 // |proxies_| is bad for |retry_delay|, but may be reconsidered earlier if
[email protected]d0483b192014-08-15 23:50:17118 // |try_while_bad| is true. |net_error| should contain the network error
119 // countered when this proxy was tried, or OK if the proxy retry info is
120 // being updated for a non-network related reason (e.g. local policy).
[email protected]a4fd43a2013-12-13 20:42:27121 void AddProxyToRetryList(ProxyRetryInfoMap* proxy_retry_info,
122 base::TimeDelta retry_delay,
[email protected]d2b237502014-02-27 01:45:06123 bool try_while_bad,
[email protected]15952a22013-12-19 04:08:25124 const ProxyServer& proxy_to_retry,
[email protected]d0483b192014-08-15 23:50:17125 int net_error,
tfarina42834112016-09-22 13:38:20126 const NetLogWithSource& net_log) const;
[email protected]a4fd43a2013-12-13 20:42:27127
[email protected]7dc52f22009-03-02 22:37:18128 // List of proxies.
129 std::vector<ProxyServer> proxies_;
130};
131
132} // namespace net
133
134#endif // NET_PROXY_PROXY_LIST_H_