[email protected] | db8ff91 | 2012-06-12 23:32:51 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 7dc52f2 | 2009-03-02 22:37:18 | [diff] [blame] | 2 | // 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 Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 10 | #include <memory> |
[email protected] | 7dc52f2 | 2009-03-02 22:37:18 | [diff] [blame] | 11 | #include <string> |
| 12 | #include <vector> |
| 13 | |
[email protected] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 14 | #include "net/base/net_export.h" |
[email protected] | 7dc52f2 | 2009-03-02 22:37:18 | [diff] [blame] | 15 | #include "net/proxy/proxy_retry_info.h" |
[email protected] | 7dc52f2 | 2009-03-02 22:37:18 | [diff] [blame] | 16 | |
[email protected] | 117d54f | 2013-03-30 17:29:43 | [diff] [blame] | 17 | namespace base { |
| 18 | class ListValue; |
[email protected] | 3d498f7 | 2013-10-28 21:17:40 | [diff] [blame] | 19 | class TimeDelta; |
[email protected] | 117d54f | 2013-03-30 17:29:43 | [diff] [blame] | 20 | } |
| 21 | |
[email protected] | 7dc52f2 | 2009-03-02 22:37:18 | [diff] [blame] | 22 | namespace net { |
| 23 | |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 24 | class ProxyServer; |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 25 | class NetLogWithSource; |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 26 | |
[email protected] | 7dc52f2 | 2009-03-02 22:37:18 | [diff] [blame] | 27 | // 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] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 30 | class NET_EXPORT_PRIVATE ProxyList { |
[email protected] | 7dc52f2 | 2009-03-02 22:37:18 | [diff] [blame] | 31 | public: |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 32 | ProxyList(); |
vmpstr | acd23b7 | 2016-02-26 21:08:55 | [diff] [blame] | 33 | ProxyList(const ProxyList& other); |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 34 | ~ProxyList(); |
| 35 | |
[email protected] | 7dc52f2 | 2009-03-02 22:37:18 | [diff] [blame] | 36 | // 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] | 5b45aec0 | 2009-03-31 01:03:23 | [diff] [blame] | 40 | // Set the proxy list to a single entry, |proxy_server|. |
| 41 | void SetSingleProxyServer(const ProxyServer& proxy_server); |
| 42 | |
[email protected] | 2189e09 | 2013-03-16 18:02:02 | [diff] [blame] | 43 | // Append a single proxy server to the end of the proxy list. |
| 44 | void AddProxyServer(const ProxyServer& proxy_server); |
| 45 | |
[email protected] | d2b23750 | 2014-02-27 01:45:06 | [diff] [blame] | 46 | // 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] | 02cf5a4 | 2010-01-12 22:10:25 | [diff] [blame] | 48 | void DeprioritizeBadProxies(const ProxyRetryInfoMap& proxy_retry_info); |
[email protected] | 7dc52f2 | 2009-03-02 22:37:18 | [diff] [blame] | 49 | |
| 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] | db8ff91 | 2012-06-12 23:32:51 | [diff] [blame] | 54 | // Clear the proxy list. |
| 55 | void Clear(); |
| 56 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 57 | // Returns true if there is nothing left in the ProxyList. |
| 58 | bool IsEmpty() const; |
| 59 | |
[email protected] | db8ff91 | 2012-06-12 23:32:51 | [diff] [blame] | 60 | // Returns the number of proxy servers in this list. |
| 61 | size_t size() const; |
| 62 | |
[email protected] | 2189e09 | 2013-03-16 18:02:02 | [diff] [blame] | 63 | // Returns true if |*this| lists the same proxies as |other|. |
| 64 | bool Equals(const ProxyList& other) const; |
| 65 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 66 | // 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] | 7dc52f2 | 2009-03-02 22:37:18 | [diff] [blame] | 69 | |
sammc | 5403aa1d | 2015-02-25 04:59:21 | [diff] [blame] | 70 | // Returns all proxy servers in the list. |
| 71 | const std::vector<ProxyServer>& GetAll() const; |
| 72 | |
[email protected] | aacc8f1 | 2010-06-23 17:24:40 | [diff] [blame] | 73 | // Sets the list by parsing the pac result |pac_string|. |
[email protected] | 7dc52f2 | 2009-03-02 22:37:18 | [diff] [blame] | 74 | // Some examples for |pac_string|: |
| 75 | // "DIRECT" |
| 76 | // "PROXY foopy1" |
| 77 | // "PROXY foopy1; SOCKS4 foopy2:1188" |
[email protected] | aacc8f1 | 2010-06-23 17:24:40 | [diff] [blame] | 78 | // Does a best-effort parse, and silently discards any errors. |
[email protected] | 7dc52f2 | 2009-03-02 22:37:18 | [diff] [blame] | 79 | 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.koo | 4e6518f | 2015-08-25 01:58:29 | [diff] [blame] | 85 | // Returns a serialized value for the list. |
danakj | 8a98ca2 | 2016-04-16 02:47:36 | [diff] [blame] | 86 | std::unique_ptr<base::ListValue> ToValue() const; |
[email protected] | 117d54f | 2013-03-30 17:29:43 | [diff] [blame] | 87 | |
[email protected] | d0483b19 | 2014-08-15 23:50:17 | [diff] [blame] | 88 | // 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] | 96e1933f | 2011-08-29 16:39:00 | [diff] [blame] | 94 | bool Fallback(ProxyRetryInfoMap* proxy_retry_info, |
[email protected] | d0483b19 | 2014-08-15 23:50:17 | [diff] [blame] | 95 | int net_error, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 96 | const NetLogWithSource& net_log); |
[email protected] | 7dc52f2 | 2009-03-02 22:37:18 | [diff] [blame] | 97 | |
[email protected] | 14b7e9a | 2012-10-16 19:51:29 | [diff] [blame] | 98 | // 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] | 3d498f7 | 2013-10-28 21:17:40 | [diff] [blame] | 100 | // 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] | d2b23750 | 2014-02-27 01:45:06 | [diff] [blame] | 102 | // duration otherwise. It may reconsider the proxy beforehand if |reconsider| |
| 103 | // is true. Additionally updates |proxy_retry_info| with |
jeremyim | 793a471 | 2015-05-14 17:04:00 | [diff] [blame] | 104 | // |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] | a4fd43a | 2013-12-13 20:42:27 | [diff] [blame] | 107 | void UpdateRetryInfoOnFallback( |
| 108 | ProxyRetryInfoMap* proxy_retry_info, |
| 109 | base::TimeDelta retry_delay, |
[email protected] | d2b23750 | 2014-02-27 01:45:06 | [diff] [blame] | 110 | bool reconsider, |
jeremyim | 793a471 | 2015-05-14 17:04:00 | [diff] [blame] | 111 | const std::vector<ProxyServer>& additional_proxies_to_bypass, |
[email protected] | d0483b19 | 2014-08-15 23:50:17 | [diff] [blame] | 112 | int net_error, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 113 | const NetLogWithSource& net_log) const; |
[email protected] | 14b7e9a | 2012-10-16 19:51:29 | [diff] [blame] | 114 | |
[email protected] | 7dc52f2 | 2009-03-02 22:37:18 | [diff] [blame] | 115 | private: |
[email protected] | 15952a2 | 2013-12-19 04:08:25 | [diff] [blame] | 116 | // Updates |proxy_retry_info| to indicate that the |proxy_to_retry| in |
[email protected] | d2b23750 | 2014-02-27 01:45:06 | [diff] [blame] | 117 | // |proxies_| is bad for |retry_delay|, but may be reconsidered earlier if |
[email protected] | d0483b19 | 2014-08-15 23:50:17 | [diff] [blame] | 118 | // |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] | a4fd43a | 2013-12-13 20:42:27 | [diff] [blame] | 121 | void AddProxyToRetryList(ProxyRetryInfoMap* proxy_retry_info, |
| 122 | base::TimeDelta retry_delay, |
[email protected] | d2b23750 | 2014-02-27 01:45:06 | [diff] [blame] | 123 | bool try_while_bad, |
[email protected] | 15952a2 | 2013-12-19 04:08:25 | [diff] [blame] | 124 | const ProxyServer& proxy_to_retry, |
[email protected] | d0483b19 | 2014-08-15 23:50:17 | [diff] [blame] | 125 | int net_error, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 126 | const NetLogWithSource& net_log) const; |
[email protected] | a4fd43a | 2013-12-13 20:42:27 | [diff] [blame] | 127 | |
[email protected] | 7dc52f2 | 2009-03-02 22:37:18 | [diff] [blame] | 128 | // List of proxies. |
| 129 | std::vector<ProxyServer> proxies_; |
| 130 | }; |
| 131 | |
| 132 | } // namespace net |
| 133 | |
| 134 | #endif // NET_PROXY_PROXY_LIST_H_ |