file_manager: Fix a bug where hosted documents could not be opened without active...
[chromium-blink-merge.git] / net / proxy / proxy_list.h
blob9f5fa59db063080d7ef5062c725041be3105920b
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_LIST_H_
6 #define NET_PROXY_PROXY_LIST_H_
8 #include <string>
9 #include <vector>
11 #include "net/base/net_export.h"
12 #include "net/base/net_log.h"
13 #include "net/proxy/proxy_retry_info.h"
15 namespace base {
16 class ListValue;
19 namespace net {
21 class ProxyServer;
23 // This class is used to hold a list of proxies returned by GetProxyForUrl or
24 // manually configured. It handles proxy fallback if multiple servers are
25 // specified.
26 class NET_EXPORT_PRIVATE ProxyList {
27 public:
28 ProxyList();
29 ~ProxyList();
31 // Initializes the proxy list to a string containing one or more proxy servers
32 // delimited by a semicolon.
33 void Set(const std::string& proxy_uri_list);
35 // Set the proxy list to a single entry, |proxy_server|.
36 void SetSingleProxyServer(const ProxyServer& proxy_server);
38 // Append a single proxy server to the end of the proxy list.
39 void AddProxyServer(const ProxyServer& proxy_server);
41 // De-prioritizes the proxies that we have cached as not working, by moving
42 // them to the end of the fallback list.
43 void DeprioritizeBadProxies(const ProxyRetryInfoMap& proxy_retry_info);
45 // Returns true if this proxy list contains at least one proxy that is
46 // not currently present in |proxy_retry_info|.
47 bool HasUntriedProxies(const ProxyRetryInfoMap& proxy_retry_info) const;
49 // Delete any entry which doesn't have one of the specified proxy schemes.
50 // |scheme_bit_field| is a bunch of ProxyServer::Scheme bitwise ORed together.
51 void RemoveProxiesWithoutScheme(int scheme_bit_field);
53 // Clear the proxy list.
54 void Clear();
56 // Returns true if there is nothing left in the ProxyList.
57 bool IsEmpty() const;
59 // Returns the number of proxy servers in this list.
60 size_t size() const;
62 // Returns true if |*this| lists the same proxies as |other|.
63 bool Equals(const ProxyList& other) const;
65 // Returns the first proxy server in the list. It is only valid to call
66 // this if !IsEmpty().
67 const ProxyServer& Get() const;
69 // Sets the list by parsing the pac result |pac_string|.
70 // Some examples for |pac_string|:
71 // "DIRECT"
72 // "PROXY foopy1"
73 // "PROXY foopy1; SOCKS4 foopy2:1188"
74 // Does a best-effort parse, and silently discards any errors.
75 void SetFromPacString(const std::string& pac_string);
77 // Returns a PAC-style semicolon-separated list of valid proxy servers.
78 // For example: "PROXY xxx.xxx.xxx.xxx:xx; SOCKS yyy.yyy.yyy:yy".
79 std::string ToPacString() const;
81 // Returns a serialized value for the list. The caller takes ownership of it.
82 base::ListValue* ToValue() const;
84 // Marks the current proxy server as bad and deletes it from the list. The
85 // list of known bad proxies is given by proxy_retry_info. Returns true if
86 // there is another server available in the list.
87 bool Fallback(ProxyRetryInfoMap* proxy_retry_info,
88 const BoundNetLog& net_log);
90 // Updates |proxy_retry_info| to indicate that the first proxy in the list
91 // is bad. This is distinct from Fallback(), above, to allow updating proxy
92 // retry information without modifying a given transction's proxy list.
93 void UpdateRetryInfoOnFallback(ProxyRetryInfoMap* proxy_retry_info,
94 const BoundNetLog& net_log) const;
96 private:
97 // List of proxies.
98 std::vector<ProxyServer> proxies_;
101 } // namespace net
103 #endif // NET_PROXY_PROXY_LIST_H_