File: proxy_list.h

package info (click to toggle)
chromium 145.0.7632.159-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,976,224 kB
  • sloc: cpp: 36,198,469; ansic: 7,634,080; javascript: 3,564,060; python: 1,649,622; xml: 838,470; asm: 717,087; pascal: 185,708; sh: 88,786; perl: 88,718; objc: 79,984; sql: 59,811; cs: 42,452; fortran: 24,101; makefile: 21,144; tcl: 15,277; php: 14,022; yacc: 9,066; ruby: 7,553; awk: 3,720; lisp: 3,233; lex: 1,328; ada: 727; jsp: 228; sed: 36
file content (132 lines) | stat: -rw-r--r-- 4,890 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_PROXY_RESOLUTION_PROXY_LIST_H_
#define NET_PROXY_RESOLUTION_PROXY_LIST_H_

#include <stddef.h>

#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "net/base/net_export.h"
#include "net/base/proxy_server.h"
#include "net/proxy_resolution/proxy_retry_info.h"

namespace base {
class Value;
}

namespace net {

class ProxyChain;
class NetLogWithSource;

// This class is used to hold a prioritized list of proxy chains. It handles
// fallback to lower-priority chains if multiple chains are specified.
class NET_EXPORT_PRIVATE ProxyList {
 public:
  ProxyList();
  ProxyList(const ProxyList& other);
  ProxyList(ProxyList&& other);
  ProxyList& operator=(const ProxyList& other);
  ProxyList& operator=(ProxyList&& other);
  ~ProxyList();

  // Initializes the ProxyList to contain one or more ProxyChains.
  // `proxy_uri_list` is a semicolon-delimited list of proxy URIs. Note that
  // multi-proxy chains cannot be represented in this format.
  void Set(const std::string& proxy_uri_list);

  // Set the proxy list to a single entry, |proxy_chain|.
  void SetSingleProxyChain(ProxyChain proxy_chain);

  // Set the proxy list to a single entry, a chain containing |proxy_server|.
  void SetSingleProxyServer(ProxyServer proxy_server);

  // Append a single proxy chain to the end of the proxy list.
  void AddProxyChain(ProxyChain proxy_chain);

  // Append a single proxy chain containing the given server to the end of the
  // proxy list.
  void AddProxyServer(ProxyServer proxy_server);

  // De-prioritizes the proxy chains that are cached as not working but are
  // allowed to be reconsidered, by moving them to the end of the fallback list.
  // If `remove_bad_proxy_chains` is true, bad proxy chains are removed
  // from the list rather than just moved to the end.
  void DeprioritizeBadProxyChains(const ProxyRetryInfoMap& proxy_retry_info,
                                  bool remove_bad_proxy_chains = false);

  // Deletes all chains which don't exclusively consist of proxy servers with
  // the specified schemes. `scheme_bit_field` is a bunch of
  // `ProxyServer::Scheme` bitwise ORed together. This is used to remove proxies
  // that do not support specific functionality such as websockets.
  void RemoveProxiesWithoutScheme(int scheme_bit_field);

  // Clear the proxy list.
  void Clear();

  // Returns true if there is nothing left in the ProxyList.
  bool IsEmpty() const;

  // Returns the number of proxy servers in this list.
  size_t size() const;

  // Returns true if |*this| lists the same proxies as |other|.
  bool Equals(const ProxyList& other) const;

  // Returns the first proxy chain in the list.
  const ProxyChain& First() const;

  // Returns all proxy chains in the list.
  const std::vector<ProxyChain>& AllChains() const;

  // Sets the list by parsing the PAC result |pac_string|.
  // Some examples for |pac_string|:
  //   "DIRECT"
  //   "PROXY foopy1"
  //   "PROXY foopy1; SOCKS4 foopy2:1188"
  // Does a best-effort parse, and silently discards any errors.
  void SetFromPacString(const std::string& pac_string);

  // Returns a PAC-style semicolon-separated list of valid proxy servers.
  // For example: "PROXY xxx.xxx.xxx.xxx:xx; SOCKS yyy.yyy.yyy:yy". This is
  // only valid if the list contains no multi-proxy chains, as those cannot
  // be represented in PAC syntax.
  std::string ToPacString() const;

  // Returns a semicolon-separated list of proxy chain debug representations.
  // For single-proxy chains, this is just the PAC representation of the proxy;
  // otherwise the chain is displayed in "[..]".
  // TODO(crbug.com/40284947): Once a PAC string format for multi-proxy
  // chains is implemented, this can be removed in favor of `ToPacString()`.
  std::string ToDebugString() const;

  // Returns a serialized value for the list.
  base::Value ToValue() const;

  // Marks the current proxy chain as bad and deletes it from the list. The
  // list of known bad proxies is given by |proxy_retry_info|. |net_error|
  // should contain the network error encountered when this proxy chain was
  // tried, if any. If this fallback is not because of a network error, then
  // |OK| should be passed in (eg. for reasons such as local policy). Returns
  // true if there is another chain available in the list.
  //
  // When a proxy chain is marked as bad, it will be deprioritized by calls to
  // `DeprioritizeBadProxyChains()` for five minutes.
  bool Fallback(ProxyRetryInfoMap* proxy_retry_info,
                int net_error,
                const NetLogWithSource& net_log);

 private:
  // List of proxy chains.
  std::vector<ProxyChain> proxy_chains_;
};

}  // namespace net

#endif  // NET_PROXY_RESOLUTION_PROXY_LIST_H_