By moving the call to Load() up in SearchProvider::Start(), we are giving a chance...
[chromium-blink-merge.git] / net / proxy / proxy_info.h
blobd0fa523883adba757e2ad85916a60e151f03cb0c
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 "net/base/net_export.h"
11 #include "net/base/net_log.h"
12 #include "net/proxy/proxy_config.h"
13 #include "net/proxy/proxy_list.h"
14 #include "net/proxy/proxy_retry_info.h"
15 #include "net/proxy/proxy_server.h"
17 namespace net {
19 // This object holds proxy information returned by ResolveProxy.
20 class NET_EXPORT ProxyInfo {
21 public:
22 ProxyInfo();
23 ~ProxyInfo();
24 // Default copy-constructor and assignment operator are OK!
26 // Uses the same proxy server as the given |proxy_info|.
27 void Use(const ProxyInfo& proxy_info);
29 // Uses a direct connection.
30 void UseDirect();
32 // Uses a direct connection. did_bypass_proxy() will return true to indicate
33 // that the direct connection is the result of configured proxy bypass rules.
34 void UseDirectWithBypassedProxy();
36 // Uses a specific proxy server, of the form:
37 // proxy-uri = [<scheme> "://"] <hostname> [":" <port>]
38 // This may optionally be a semi-colon delimited list of <proxy-uri>.
39 // It is OK to have LWS between entries.
40 void UseNamedProxy(const std::string& proxy_uri_list);
42 // Sets the proxy list to a single entry, |proxy_server|.
43 void UseProxyServer(const ProxyServer& proxy_server);
45 // Parses from the given PAC result.
46 void UsePacString(const std::string& pac_string) {
47 proxy_list_.SetFromPacString(pac_string);
50 // Returns true if this proxy info specifies a direct connection.
51 bool is_direct() const {
52 // We don't implicitly fallback to DIRECT unless it was added to the list.
53 if (is_empty())
54 return false;
55 return proxy_list_.Get().is_direct();
58 bool is_direct_only() const {
59 return is_direct() && proxy_list_.size() == 1 && proxy_retry_info_.empty();
62 // Returns true if the first valid proxy server is an https proxy.
63 bool is_https() const {
64 if (is_empty())
65 return false;
66 return proxy_server().is_https();
69 // Returns true if the first valid proxy server is an http proxy.
70 bool is_http() const {
71 if (is_empty())
72 return false;
73 return proxy_server().is_http();
76 // Returns true if the first valid proxy server is a socks server.
77 bool is_socks() const {
78 if (is_empty())
79 return false;
80 return proxy_server().is_socks();
83 // Returns true if this proxy info has no proxies left to try.
84 bool is_empty() const {
85 return proxy_list_.IsEmpty();
88 // Returns true if this proxy resolution is using a direct connection due to
89 // proxy bypass rules.
90 bool did_bypass_proxy() const {
91 return did_bypass_proxy_;
94 // Returns true if the proxy resolution was done using a PAC script.
95 bool did_use_pac_script() const {
96 return did_use_pac_script_;
99 // Returns the first valid proxy server. is_empty() must be false to be able
100 // to call this function.
101 const ProxyServer& proxy_server() const { return proxy_list_.Get(); }
103 // Returns the source for configuration settings used for proxy resolution.
104 ProxyConfigSource config_source() const { return config_source_; }
106 // See description in ProxyList::ToPacString().
107 std::string ToPacString() const;
109 // Marks the current proxy as bad. Returns true if there is another proxy
110 // available to try in proxy list_.
111 bool Fallback(const BoundNetLog& net_log);
113 // De-prioritizes the proxies that we have cached as not working, by moving
114 // them to the end of the proxy list.
115 void DeprioritizeBadProxies(const ProxyRetryInfoMap& proxy_retry_info);
117 // Deletes any entry which doesn't have one of the specified proxy schemes.
118 void RemoveProxiesWithoutScheme(int scheme_bit_field);
120 ProxyConfig::ID config_id() const { return config_id_; }
122 private:
123 friend class ProxyService;
125 const ProxyRetryInfoMap& proxy_retry_info() const {
126 return proxy_retry_info_;
129 // Reset proxy and config settings.
130 void Reset();
132 // The ordered list of proxy servers (including DIRECT attempts) remaining to
133 // try. If proxy_list_ is empty, then there is nothing left to fall back to.
134 ProxyList proxy_list_;
136 // List of proxies that have been tried already.
137 ProxyRetryInfoMap proxy_retry_info_;
139 // This value identifies the proxy config used to initialize this object.
140 ProxyConfig::ID config_id_;
142 // The source of the proxy settings used,
143 ProxyConfigSource config_source_;
145 // Whether the proxy result represent a proxy bypass.
146 bool did_bypass_proxy_;
148 // Whether we used a PAC script for resolving the proxy.
149 bool did_use_pac_script_;
152 } // namespace net
154 #endif // NET_PROXY_PROXY_INFO_H_