Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_params.h

Issue 333113002: Move data reduction proxy to Chrome-Proxy header for authentication (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@flywheel-refactor-net-fake-a-redirect-response-headers-chrome-proxy-auth
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PARAMS_H_ 5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PARAMS_H_
6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PARAMS_H_ 6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PARAMS_H_
7 7
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "net/base/host_port_pair.h" 13 #include "net/base/host_port_pair.h"
14 #include "url/gurl.h" 14 #include "url/gurl.h"
15 15
16 namespace net { 16 namespace net {
17 class URLRequest; 17 class URLRequest;
18 } 18 }
19 19
20 namespace data_reduction_proxy { 20 namespace data_reduction_proxy {
21 // Provides initialization parameters. Proxy origins, the probe url, and the 21 // Provides initialization parameters. Proxy origins, and the probe url are
22 // authentication key are taken from flags if available and from preprocessor 22 // are taken from flags if available and from preprocessor constants otherwise.
23 // constants otherwise. Only the key may be changed after construction. The 23 // The DataReductionProxySettings class and others use this class to determine
24 // DataReductionProxySettings class and others use this class to determine 24 // the necessary DNS names to configure use of the data reduction proxy.
25 // the necessary DNS names and keys to configure use of the data reduction
26 // proxy.
27 class DataReductionProxyParams { 25 class DataReductionProxyParams {
28 public: 26 public:
29 static const unsigned int kAllowed = (1 << 0); 27 static const unsigned int kAllowed = (1 << 0);
30 static const unsigned int kFallbackAllowed = (1 << 1); 28 static const unsigned int kFallbackAllowed = (1 << 1);
31 static const unsigned int kAlternativeAllowed = (1 << 2); 29 static const unsigned int kAlternativeAllowed = (1 << 2);
32 static const unsigned int kPromoAllowed = (1 << 3); 30 static const unsigned int kPromoAllowed = (1 << 3);
33 31
34 typedef std::vector<GURL> DataReductionProxyList; 32 typedef std::vector<GURL> DataReductionProxyList;
35 33
36 // Returns true if this client is part of the data reduction proxy field 34 // Returns true if this client is part of the data reduction proxy field
37 // trial. 35 // trial.
38 static bool IsIncludedInFieldTrial(); 36 static bool IsIncludedInFieldTrial();
39 37
40 // Returns true if this client is part of field trial to use an alternative 38 // Returns true if this client is part of field trial to use an alternative
41 // configuration for the data reduction proxy. 39 // configuration for the data reduction proxy.
42 static bool IsIncludedInAlternativeFieldTrial(); 40 static bool IsIncludedInAlternativeFieldTrial();
43 41
44 // Returns true if this client is part of the field trial that should display 42 // Returns true if this client is part of the field trial that should display
45 // a promotion for the data reduction proxy. 43 // a promotion for the data reduction proxy.
46 static bool IsIncludedInPromoFieldTrial(); 44 static bool IsIncludedInPromoFieldTrial();
47 45
48 // Returns true if this client is part of a field trial that uses preconnect 46 // Returns true if this client is part of a field trial that uses preconnect
49 // hinting. 47 // hinting.
50 static bool IsIncludedInPreconnectHintingFieldTrial(); 48 static bool IsIncludedInPreconnectHintingFieldTrial();
51 49
52 // Returns true if the authentication key was set on the command line.
53 static bool IsKeySetOnCommandLine();
54
55 // Constructs configuration parameters. If |kAllowed|, then the standard 50 // Constructs configuration parameters. If |kAllowed|, then the standard
56 // data reduction proxy configuration is allowed to be used. If 51 // data reduction proxy configuration is allowed to be used. If
57 // |kfallbackAllowed| a fallback proxy can be used if the primary proxy is 52 // |kfallbackAllowed| a fallback proxy can be used if the primary proxy is
58 // bypassed or disabled. If |kAlternativeAllowed| then an alternative proxy 53 // bypassed or disabled. If |kAlternativeAllowed| then an alternative proxy
59 // configuration is allowed to be used. This alternative configuration would 54 // configuration is allowed to be used. This alternative configuration would
60 // replace the primary and fallback proxy configurations if enabled. Finally 55 // replace the primary and fallback proxy configurations if enabled. Finally
61 // if |kPromoAllowed|, the client may show a promotion for the data reduction 56 // if |kPromoAllowed|, the client may show a promotion for the data reduction
62 // proxy. 57 // proxy.
63 // 58 //
64 // A standard configuration has a primary proxy, and a fallback proxy for 59 // A standard configuration has a primary proxy, and a fallback proxy for
(...skipping 12 matching lines...) Expand all
77 // values. 72 // values.
78 virtual bool WasDataReductionProxyUsed( 73 virtual bool WasDataReductionProxyUsed(
79 const net::URLRequest* request, 74 const net::URLRequest* request,
80 std::pair<GURL, GURL>* proxy_servers) const; 75 std::pair<GURL, GURL>* proxy_servers) const;
81 76
82 // Returns true if the specified |host_port_pair| matches a data reduction 77 // Returns true if the specified |host_port_pair| matches a data reduction
83 // proxy. If true, |proxy_servers.first| will contain the name of the proxy 78 // proxy. If true, |proxy_servers.first| will contain the name of the proxy
84 // that matches. |proxy_servers.second| will contain the name of the 79 // that matches. |proxy_servers.second| will contain the name of the
85 // data reduction proxy server that would be used if |proxy_server.first| is 80 // data reduction proxy server that would be used if |proxy_server.first| is
86 // bypassed, if one exists. |proxy_servers| can be NULL if the caller isn't 81 // bypassed, if one exists. |proxy_servers| can be NULL if the caller isn't
87 // interested in its values. 82 // interested in its values. Virtual for testing.
88 bool IsDataReductionProxy(const net::HostPortPair& host_port_pair, 83 virtual bool IsDataReductionProxy(const net::HostPortPair& host_port_pair,
89 std::pair<GURL, GURL>* proxy_servers) const; 84 std::pair<GURL, GURL>* proxy_servers) const;
90 85
91 // Returns the data reduction proxy primary origin. 86 // Returns the data reduction proxy primary origin.
92 const GURL& origin() const { 87 const GURL& origin() const {
93 return origin_; 88 return origin_;
94 } 89 }
95 90
96 // Returns the data reduction proxy fallback origin. 91 // Returns the data reduction proxy fallback origin.
97 const GURL& fallback_origin() const { 92 const GURL& fallback_origin() const {
98 return fallback_origin_; 93 return fallback_origin_;
99 } 94 }
(...skipping 17 matching lines...) Expand all
117 // Returns the URL to probe to decide if the primary origin should be used. 112 // Returns the URL to probe to decide if the primary origin should be used.
118 const GURL& probe_url() const { 113 const GURL& probe_url() const {
119 return probe_url_; 114 return probe_url_;
120 } 115 }
121 116
122 // Returns the URL to fetch to warm the data reduction proxy connection. 117 // Returns the URL to fetch to warm the data reduction proxy connection.
123 const GURL& warmup_url() const { 118 const GURL& warmup_url() const {
124 return warmup_url_; 119 return warmup_url_;
125 } 120 }
126 121
127 // Set the proxy authentication key.
128 void set_key(const std::string& key) {
129 key_ = key;
130 }
131
132 // Returns the proxy authentication key.
133 const std::string& key() const {
134 return key_;
135 }
136
137 // Returns true if the data reduction proxy configuration may be used. 122 // Returns true if the data reduction proxy configuration may be used.
138 bool allowed() const { 123 bool allowed() const {
139 return allowed_; 124 return allowed_;
140 } 125 }
141 126
142 // Returns true if the fallback proxy may be used. 127 // Returns true if the fallback proxy may be used.
143 bool fallback_allowed() const { 128 bool fallback_allowed() const {
144 return fallback_allowed_; 129 return fallback_allowed_;
145 } 130 }
146 131
147 // Returns true if the alternative data reduction proxy configuration may be 132 // Returns true if the alternative data reduction proxy configuration may be
148 // used. 133 // used.
149 bool alternative_allowed() const { 134 bool alternative_allowed() const {
150 return alt_allowed_; 135 return alt_allowed_;
151 } 136 }
152 137
153 // Returns true if the data reduction proxy promo may be shown. 138 // Returns true if the data reduction proxy promo may be shown.
154 // This is idependent of whether the data reduction proxy is allowed. 139 // This is idependent of whether the data reduction proxy is allowed.
155 // TODO(bengr): maybe tie to whether proxy is allowed. 140 // TODO(bengr): maybe tie to whether proxy is allowed.
156 bool promo_allowed() const { 141 bool promo_allowed() const {
157 return promo_allowed_; 142 return promo_allowed_;
158 } 143 }
159 144
160 // Given |allowed_|, |fallback_allowed_|, and |alt_allowed_|, returns the 145 // Given |allowed_|, |fallback_allowed_|, and |alt_allowed_|, returns the
161 // list of data reduction proxies that may be used. 146 // list of data reduction proxies that may be used.
162 DataReductionProxyList GetAllowedProxies() const; 147 DataReductionProxyList GetAllowedProxies() const;
163 148
149 // Returns true if any dns names are set on the command line.
150 bool is_configured_on_command_line() const {
151 return configured_on_command_line_;
152 }
153
164 protected: 154 protected:
165 // Test constructor that optionally won't call Init(); 155 // Test constructor that optionally won't call Init();
166 DataReductionProxyParams(int flags, 156 DataReductionProxyParams(int flags,
167 bool should_call_init); 157 bool should_call_init);
168 158
169 // Initialize the values of the proxies, probe URL, and key from command 159 // Initialize the values of the proxies, and probe URL, from command
170 // line flags and preprocessor constants, and check that there are 160 // line flags and preprocessor constants, and check that there are
171 // corresponding definitions for the allowed configurations. 161 // corresponding definitions for the allowed configurations.
172 bool Init(bool allowed, bool fallback_allowed, bool alt_allowed); 162 bool Init(bool allowed, bool fallback_allowed, bool alt_allowed);
173 163
174 // Initialize the values of the proxies, probe URL, and key from command 164 // Initialize the values of the proxies, and probe URL from command
175 // line flags and preprocessor constants. 165 // line flags and preprocessor constants.
176 void InitWithoutChecks(); 166 void InitWithoutChecks();
177 167
178 // Returns the corresponding string from preprocessor constants if defined, 168 // Returns the corresponding string from preprocessor constants if defined,
179 // and an empty string otherwise. 169 // and an empty string otherwise.
180 virtual std::string GetDefaultKey() const;
181 virtual std::string GetDefaultDevOrigin() const; 170 virtual std::string GetDefaultDevOrigin() const;
182 virtual std::string GetDefaultOrigin() const; 171 virtual std::string GetDefaultOrigin() const;
183 virtual std::string GetDefaultFallbackOrigin() const; 172 virtual std::string GetDefaultFallbackOrigin() const;
184 virtual std::string GetDefaultSSLOrigin() const; 173 virtual std::string GetDefaultSSLOrigin() const;
185 virtual std::string GetDefaultAltOrigin() const; 174 virtual std::string GetDefaultAltOrigin() const;
186 virtual std::string GetDefaultAltFallbackOrigin() const; 175 virtual std::string GetDefaultAltFallbackOrigin() const;
187 virtual std::string GetDefaultProbeURL() const; 176 virtual std::string GetDefaultProbeURL() const;
188 virtual std::string GetDefaultWarmupURL() const; 177 virtual std::string GetDefaultWarmupURL() const;
189 178
190 private: 179 private:
191 GURL origin_; 180 GURL origin_;
192 GURL fallback_origin_; 181 GURL fallback_origin_;
193 GURL ssl_origin_; 182 GURL ssl_origin_;
194 GURL alt_origin_; 183 GURL alt_origin_;
195 GURL alt_fallback_origin_; 184 GURL alt_fallback_origin_;
196 GURL probe_url_; 185 GURL probe_url_;
197 GURL warmup_url_; 186 GURL warmup_url_;
198 187
199 std::string key_;
200
201 bool allowed_; 188 bool allowed_;
202 const bool fallback_allowed_; 189 const bool fallback_allowed_;
203 bool alt_allowed_; 190 bool alt_allowed_;
204 const bool promo_allowed_; 191 const bool promo_allowed_;
205 192
193 bool configured_on_command_line_;
194
206 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyParams); 195 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyParams);
207 }; 196 };
208 197
209 } // namespace data_reduction_proxy 198 } // namespace data_reduction_proxy
210 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PARAMS_H _ 199 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PARAMS_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698