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

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: errata Created 6 years, 6 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 true if this request will be sent through the data request proxy 86 // Returns true if this request will be sent through the data request proxy
92 // based on applying the param rules to the URL. We do not check bad proxy 87 // based on applying the param rules to the URL. We do not check bad proxy
93 // list. 88 // list.
94 virtual bool IsDataReductionProxyEligible(const net::URLRequest* request); 89 virtual bool IsDataReductionProxyEligible(const net::URLRequest* request);
95 90
96 // Returns the data reduction proxy primary origin. 91 // Returns the data reduction proxy primary origin.
97 const GURL& origin() const { 92 const GURL& origin() const {
98 return origin_; 93 return origin_;
99 } 94 }
(...skipping 22 matching lines...) Expand all
122 // Returns the URL to probe to decide if the primary origin should be used. 117 // Returns the URL to probe to decide if the primary origin should be used.
123 const GURL& probe_url() const { 118 const GURL& probe_url() const {
124 return probe_url_; 119 return probe_url_;
125 } 120 }
126 121
127 // Returns the URL to fetch to warm the data reduction proxy connection. 122 // Returns the URL to fetch to warm the data reduction proxy connection.
128 const GURL& warmup_url() const { 123 const GURL& warmup_url() const {
129 return warmup_url_; 124 return warmup_url_;
130 } 125 }
131 126
132 // Set the proxy authentication key.
133 void set_key(const std::string& key) {
134 key_ = key;
135 }
136
137 // Returns the proxy authentication key.
138 const std::string& key() const {
139 return key_;
140 }
141
142 // Returns true if the data reduction proxy configuration may be used. 127 // Returns true if the data reduction proxy configuration may be used.
143 bool allowed() const { 128 bool allowed() const {
144 return allowed_; 129 return allowed_;
145 } 130 }
146 131
147 // Returns true if the fallback proxy may be used. 132 // Returns true if the fallback proxy may be used.
148 bool fallback_allowed() const { 133 bool fallback_allowed() const {
149 return fallback_allowed_; 134 return fallback_allowed_;
150 } 135 }
151 136
152 // Returns true if the alternative data reduction proxy configuration may be 137 // Returns true if the alternative data reduction proxy configuration may be
153 // used. 138 // used.
154 bool alternative_allowed() const { 139 bool alternative_allowed() const {
155 return alt_allowed_; 140 return alt_allowed_;
156 } 141 }
157 142
158 // Returns true if the data reduction proxy promo may be shown. 143 // Returns true if the data reduction proxy promo may be shown.
159 // This is idependent of whether the data reduction proxy is allowed. 144 // This is idependent of whether the data reduction proxy is allowed.
160 // TODO(bengr): maybe tie to whether proxy is allowed. 145 // TODO(bengr): maybe tie to whether proxy is allowed.
161 bool promo_allowed() const { 146 bool promo_allowed() const {
162 return promo_allowed_; 147 return promo_allowed_;
163 } 148 }
164 149
165 // Given |allowed_|, |fallback_allowed_|, and |alt_allowed_|, returns the 150 // Given |allowed_|, |fallback_allowed_|, and |alt_allowed_|, returns the
166 // list of data reduction proxies that may be used. 151 // list of data reduction proxies that may be used.
167 DataReductionProxyList GetAllowedProxies() const; 152 DataReductionProxyList GetAllowedProxies() const;
168 153
154 // Returns true if any proxy origins are set on the command line.
155 bool is_configured_on_command_line() const {
156 return configured_on_command_line_;
157 }
158
169 protected: 159 protected:
170 // Test constructor that optionally won't call Init(); 160 // Test constructor that optionally won't call Init();
171 DataReductionProxyParams(int flags, 161 DataReductionProxyParams(int flags,
172 bool should_call_init); 162 bool should_call_init);
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, and check that there are 165 // line flags and preprocessor constants, and check that there are
176 // corresponding definitions for the allowed configurations. 166 // corresponding definitions for the allowed configurations.
177 bool Init(bool allowed, bool fallback_allowed, bool alt_allowed); 167 bool Init(bool allowed, bool fallback_allowed, bool alt_allowed);
178 168
179 // Initialize the values of the proxies, probe URL, and key from command 169 // Initialize the values of the proxies, and probe URL from command
180 // line flags and preprocessor constants. 170 // line flags and preprocessor constants.
181 void InitWithoutChecks(); 171 void InitWithoutChecks();
182 172
183 // Returns the corresponding string from preprocessor constants if defined, 173 // Returns the corresponding string from preprocessor constants if defined,
184 // and an empty string otherwise. 174 // and an empty string otherwise.
185 virtual std::string GetDefaultKey() const;
186 virtual std::string GetDefaultDevOrigin() const; 175 virtual std::string GetDefaultDevOrigin() const;
187 virtual std::string GetDefaultOrigin() const; 176 virtual std::string GetDefaultOrigin() const;
188 virtual std::string GetDefaultFallbackOrigin() const; 177 virtual std::string GetDefaultFallbackOrigin() const;
189 virtual std::string GetDefaultSSLOrigin() const; 178 virtual std::string GetDefaultSSLOrigin() const;
190 virtual std::string GetDefaultAltOrigin() const; 179 virtual std::string GetDefaultAltOrigin() const;
191 virtual std::string GetDefaultAltFallbackOrigin() const; 180 virtual std::string GetDefaultAltFallbackOrigin() const;
192 virtual std::string GetDefaultProbeURL() const; 181 virtual std::string GetDefaultProbeURL() const;
193 virtual std::string GetDefaultWarmupURL() const; 182 virtual std::string GetDefaultWarmupURL() const;
194 183
195 private: 184 private:
196 GURL origin_; 185 GURL origin_;
197 GURL fallback_origin_; 186 GURL fallback_origin_;
198 GURL ssl_origin_; 187 GURL ssl_origin_;
199 GURL alt_origin_; 188 GURL alt_origin_;
200 GURL alt_fallback_origin_; 189 GURL alt_fallback_origin_;
201 GURL probe_url_; 190 GURL probe_url_;
202 GURL warmup_url_; 191 GURL warmup_url_;
203 192
204 std::string key_;
205
206 bool allowed_; 193 bool allowed_;
207 const bool fallback_allowed_; 194 const bool fallback_allowed_;
208 bool alt_allowed_; 195 bool alt_allowed_;
209 const bool promo_allowed_; 196 const bool promo_allowed_;
210 197
198 bool configured_on_command_line_;
199
211 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyParams); 200 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyParams);
212 }; 201 };
213 202
214 } // namespace data_reduction_proxy 203 } // namespace data_reduction_proxy
215 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PARAMS_H _ 204 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PARAMS_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698