• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2010 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.
4 
5 #ifndef NET_PROXY_PROXY_INFO_H_
6 #define NET_PROXY_PROXY_INFO_H_
7 #pragma once
8 
9 #include <string>
10 
11 #include "net/proxy/proxy_config.h"
12 #include "net/proxy/proxy_list.h"
13 #include "net/proxy/proxy_retry_info.h"
14 #include "net/proxy/proxy_server.h"
15 
16 namespace net {
17 
18 // This object holds proxy information returned by ResolveProxy.
19 class ProxyInfo {
20  public:
21   ProxyInfo();
22   ~ProxyInfo();
23   // Default copy-constructor and assignment operator are OK!
24 
25   // Uses the same proxy server as the given |proxy_info|.
26   void Use(const ProxyInfo& proxy_info);
27 
28   // Uses a direct connection.
29   void UseDirect();
30 
31   // Uses a specific proxy server, of the form:
32   //   proxy-uri = [<scheme> "://"] <hostname> [":" <port>]
33   // This may optionally be a semi-colon delimited list of <proxy-uri>.
34   // It is OK to have LWS between entries.
35   void UseNamedProxy(const std::string& proxy_uri_list);
36 
37   // Sets the proxy list to a single entry, |proxy_server|.
38   void UseProxyServer(const ProxyServer& proxy_server);
39 
40   // Parses from the given PAC result.
UsePacString(const std::string & pac_string)41   void UsePacString(const std::string& pac_string) {
42     proxy_list_.SetFromPacString(pac_string);
43   }
44 
45   // Returns true if this proxy info specifies a direct connection.
is_direct()46   bool is_direct() const {
47     // We don't implicitly fallback to DIRECT unless it was added to the list.
48     if (is_empty())
49       return false;
50     return proxy_list_.Get().is_direct();
51   }
52 
53   // Returns true if the first valid proxy server is an https proxy.
is_https()54   bool is_https() const {
55     if (is_empty())
56       return false;
57     return proxy_server().is_https();
58   }
59 
60   // Returns true if the first valid proxy server is an http proxy.
is_http()61   bool is_http() const {
62     if (is_empty())
63       return false;
64     return proxy_server().is_http();
65   }
66 
67   // Returns true if the first valid proxy server is a socks server.
is_socks()68   bool is_socks() const {
69     if (is_empty())
70       return false;
71     return proxy_server().is_socks();
72   }
73 
74   // Returns true if this proxy info has no proxies left to try.
is_empty()75   bool is_empty() const {
76     return proxy_list_.IsEmpty();
77   }
78 
79   // Returns the first valid proxy server. is_empty() must be false to be able
80   // to call this function.
proxy_server()81   const ProxyServer& proxy_server() const { return proxy_list_.Get(); }
82 
83   // See description in ProxyList::ToPacString().
84   std::string ToPacString() const;
85 
86   // Marks the current proxy as bad. Returns true if there is another proxy
87   // available to try in proxy list_.
88   bool Fallback(ProxyRetryInfoMap* proxy_retry_info);
89 
90   // De-prioritizes the proxies that we have cached as not working, by moving
91   // them to the end of the proxy list.
92   void DeprioritizeBadProxies(const ProxyRetryInfoMap& proxy_retry_info);
93 
94   // Deletes any entry which doesn't have one of the specified proxy schemes.
95   void RemoveProxiesWithoutScheme(int scheme_bit_field);
96 
97  private:
98   friend class ProxyService;
99 
100   // The ordered list of proxy servers (including DIRECT attempts) remaining to
101   // try. If proxy_list_ is empty, then there is nothing left to fall back to.
102   ProxyList proxy_list_;
103 
104   // This value identifies the proxy config used to initialize this object.
105   ProxyConfig::ID config_id_;
106 };
107 
108 }  // namespace net
109 
110 #endif  // NET_PROXY_PROXY_INFO_H_
111