Roll src/third_party/skia 5cc0f6c:01d3319
[chromium-blink-merge.git] / net / proxy / proxy_info.h
blob8e78d9f916fc42661d7a9f62924c04205496d8cf
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_INFO_H_
6 #define NET_PROXY_PROXY_INFO_H_
8 #include <string>
10 #include "base/gtest_prod_util.h"
11 #include "base/time/time.h"
12 #include "net/base/net_export.h"
13 #include "net/base/net_log.h"
14 #include "net/proxy/proxy_config.h"
15 #include "net/proxy/proxy_list.h"
16 #include "net/proxy/proxy_retry_info.h"
17 #include "net/proxy/proxy_server.h"
19 namespace net {
21 // This object holds proxy information returned by ResolveProxy.
22 class NET_EXPORT ProxyInfo {
23 public:
24 ProxyInfo();
25 ~ProxyInfo();
26 // Default copy-constructor and assignment operator are OK!
28 // Uses the same proxy server as the given |proxy_info|.
29 void Use(const ProxyInfo& proxy_info);
31 // Uses a direct connection.
33 // Note that this method resets this instance unlike Fallback(), etc. which
34 // only modify |proxy_list_|. For example, since |config_id_| is cleared, the
35 // ProxyService may recognize this instance as a new config after UseDirect()
36 // call.
37 void UseDirect();
39 // Uses a direct connection. did_bypass_proxy() will return true to indicate
40 // that the direct connection is the result of configured proxy bypass rules.
42 // See also the note for UseDirect().
43 void UseDirectWithBypassedProxy();
45 // Uses a specific proxy server, of the form:
46 // proxy-uri = [<scheme> "://"] <hostname> [":" <port>]
47 // This may optionally be a semi-colon delimited list of <proxy-uri>.
48 // It is OK to have LWS between entries.
50 // See also the note for UseDirect().
51 void UseNamedProxy(const std::string& proxy_uri_list);
53 // Sets the proxy list to a single entry, |proxy_server|.
55 // See also the note for UseDirect().
56 void UseProxyServer(const ProxyServer& proxy_server);
58 // Parses from the given PAC result.
60 // See also the note for UseDirect().
61 void UsePacString(const std::string& pac_string);
63 // Uses the proxies from the given list.
65 // See also the note for UseDirect().
66 void UseProxyList(const ProxyList& proxy_list);
68 // Uses the proxies from the given list, but does not otherwise reset the
69 // proxy configuration.
70 void OverrideProxyList(const ProxyList& proxy_list);
72 // Returns true if this proxy info specifies a direct connection.
73 bool is_direct() const {
74 // We don't implicitly fallback to DIRECT unless it was added to the list.
75 if (is_empty())
76 return false;
77 return proxy_list_.Get().is_direct();
80 bool is_direct_only() const {
81 return is_direct() && proxy_list_.size() == 1 && proxy_retry_info_.empty();
84 // Returns true if the first valid proxy server is an https proxy.
85 bool is_https() const {
86 if (is_empty())
87 return false;
88 return proxy_server().is_https();
91 // Returns true if the first valid proxy server is an http proxy.
92 bool is_http() const {
93 if (is_empty())
94 return false;
95 return proxy_server().is_http();
98 // Returns true if the first valid proxy server is a quic proxy.
99 bool is_quic() const {
100 if (is_empty())
101 return false;
102 return proxy_server().is_quic();
105 // Returns true if the first valid proxy server is a socks server.
106 bool is_socks() const {
107 if (is_empty())
108 return false;
109 return proxy_server().is_socks();
112 // Returns true if this proxy info has no proxies left to try.
113 bool is_empty() const {
114 return proxy_list_.IsEmpty();
117 // Returns true if this proxy resolution is using a direct connection due to
118 // proxy bypass rules.
119 bool did_bypass_proxy() const {
120 return did_bypass_proxy_;
123 // Returns true if the proxy resolution was done using a PAC script.
124 bool did_use_pac_script() const {
125 return did_use_pac_script_;
128 // Returns the first valid proxy server. is_empty() must be false to be able
129 // to call this function.
130 const ProxyServer& proxy_server() const { return proxy_list_.Get(); }
132 // Returns the source for configuration settings used for proxy resolution.
133 ProxyConfigSource config_source() const { return config_source_; }
135 // See description in ProxyList::ToPacString().
136 std::string ToPacString() const;
138 // Marks the current proxy as bad. |net_error| should contain the network
139 // error encountered when this proxy was tried, if any. If this fallback
140 // is not because of a network error, then |OK| should be passed in (eg. for
141 // reasons such as local policy). Returns true if there is another proxy is
142 // available to try in proxy list_.
143 bool Fallback(int net_error, const BoundNetLog& net_log);
145 // De-prioritizes the proxies that we have cached as not working, by moving
146 // them to the end of the proxy list.
147 void DeprioritizeBadProxies(const ProxyRetryInfoMap& proxy_retry_info);
149 // Deletes any entry which doesn't have one of the specified proxy schemes.
150 void RemoveProxiesWithoutScheme(int scheme_bit_field);
152 ProxyConfig::ID config_id() const { return config_id_; }
154 // Returns the list of proxies to use.
155 const ProxyList& proxy_list() const {
156 return proxy_list_;
159 base::TimeTicks proxy_resolve_start_time() const {
160 return proxy_resolve_start_time_;
163 base::TimeTicks proxy_resolve_end_time() const {
164 return proxy_resolve_end_time_;
167 private:
168 friend class ProxyService;
169 FRIEND_TEST_ALL_PREFIXES(ProxyInfoTest, UseVsOverrideProxyList);
171 const ProxyRetryInfoMap& proxy_retry_info() const {
172 return proxy_retry_info_;
175 // Reset proxy and config settings.
176 void Reset();
178 // The ordered list of proxy servers (including DIRECT attempts) remaining to
179 // try. If proxy_list_ is empty, then there is nothing left to fall back to.
180 ProxyList proxy_list_;
182 // List of proxies that have been tried already.
183 ProxyRetryInfoMap proxy_retry_info_;
185 // This value identifies the proxy config used to initialize this object.
186 ProxyConfig::ID config_id_;
188 // The source of the proxy settings used,
189 ProxyConfigSource config_source_;
191 // Whether the proxy result represent a proxy bypass.
192 bool did_bypass_proxy_;
194 // Whether we used a PAC script for resolving the proxy.
195 bool did_use_pac_script_;
197 // How long it took to resolve the proxy. Times are both null if proxy was
198 // determined synchronously without running a PAC.
199 base::TimeTicks proxy_resolve_start_time_;
200 base::TimeTicks proxy_resolve_end_time_;
203 } // namespace net
205 #endif // NET_PROXY_PROXY_INFO_H_