summaryrefslogtreecommitdiffstats
path: root/components/data_reduction_proxy/core/common/data_reduction_proxy_params.h
blob: 05102d60b9302561455b6153f7a866fe4ffb09c7 (plain)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PARAMS_H_
#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PARAMS_H_

#include <string>
#include <vector>

#include "base/macros.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_config_values.h"
#include "net/proxy/proxy_server.h"
#include "url/gurl.h"

namespace base {
class TimeDelta;
}

namespace net {
class HostPortPair;
class ProxyServer;
}

namespace data_reduction_proxy {

// The data_reduction_proxy::params namespace is a collection of methods to
// determine the operating parameters of the Data Reduction Proxy as specified
// by field trials and command line switches.
namespace params {

// Returns true if this client is part of the field trial that should display
// a promotion for the data reduction proxy.
bool IsIncludedInPromoFieldTrial();

// Returns true if this client is part of a field trial that runs a holdback
// experiment. A holdback experiment is one in which a fraction of browser
// instances will not be configured to use the data reduction proxy even if
// users have enabled it to be used. The UI will not indicate that a holdback
// is in effect.
bool IsIncludedInHoldbackFieldTrial();

// Returns the name of the trusted SPDY/HTTP2 proxy field trial.
std::string GetTrustedSpdyProxyFieldTrialName();

// Returns true if this client is part of the enabled group of the trusted
// SPDY/HTTP2 proxy field trial.
bool IsIncludedInTrustedSpdyProxyFieldTrial();

// Returns true if this client is part of the field trial that should display
// a promotion for the data reduction proxy on Android One devices.
bool IsIncludedInAndroidOnePromoFieldTrial(const char* build_fingerprint);

// Returns the name of the Lo-Fi field trial.
std::string GetLoFiFieldTrialName();

// Returns the name of the Lo-Fi field trial that configures LoFi flags when it
// is force enabled through flags.
std::string GetLoFiFlagFieldTrialName();

// Returns true if this client is part of the "Enabled" or "Enabled_Preview"
// group of the Lo-Fi field trial, both of which mean Lo-Fi should be enabled.
bool IsIncludedInLoFiEnabledFieldTrial();

// Returns true if this client is part of the "Control" group of the Lo-Fi field
// trial.
bool IsIncludedInLoFiControlFieldTrial();

// Returns true if this client is part of the "Preview" group of the Lo-Fi field
// trial.
bool IsIncludedInLoFiPreviewFieldTrial();

// Returns true if this client is part of the tamper detection experiment.
bool IsIncludedInTamperDetectionExperiment();

// Returns true if this client has any of the values to enable Lo-Fi mode for
// the "data-reduction-proxy-lo-fi" command line switch. This includes the
// "always-on", "cellular-only", and "slow-connections-only" values.
bool IsLoFiOnViaFlags();

// Returns true if this client has the command line switch to enable Lo-Fi
// mode always on.
bool IsLoFiAlwaysOnViaFlags();

// Returns true if this client has the command line switch to enable Lo-Fi
// mode only on cellular connections.
bool IsLoFiCellularOnlyViaFlags();

// Returns true if this client has the command line switch to enable Lo-Fi
// mode only on slow connections.
bool IsLoFiSlowConnectionsOnlyViaFlags();

// Returns true if this client has the command line switch to disable Lo-Fi
// mode.
bool IsLoFiDisabledViaFlags();

// Returns true if this client has the command line switch to enable Lo-Fi
// previews. This means a preview should be requested instead of placeholders
// whenever Lo-Fi mode is on.
bool AreLoFiPreviewsEnabledViaFlags();

// Returns true if this client has the command line switch to show
// interstitials for data reduction proxy bypasses.
bool WarnIfNoDataReductionProxy();

// Returns true if this client is part of a field trial that sets the origin
// proxy server as quic://proxy.googlezip.net.
bool IsIncludedInQuicFieldTrial();

// Returns true if dev rollout is enabled on this client either through command
// line switch or as a part of field trial.
bool IsDevRolloutEnabled();

std::string GetQuicFieldTrialName();

// Returns the name of the client config field trial.
std::string GetClientConfigFieldTrialName();

// Returns true if the Data Reduction Proxy config client should be used.
bool IsConfigClientEnabled();

// If the Data Reduction Proxy config client is being used, the URL for the
// Data Reduction Proxy config service.
GURL GetConfigServiceURL();

// Returns true if the Data Reduction Proxy is forced to be enabled from the
// command line.
bool ShouldForceEnableDataReductionProxy();

// Returns true if the secure Data Reduction Proxy should be used until the
// secure proxy check fails.
bool ShouldUseSecureProxyByDefault();

// Retrieves the int stored in |param_name| from the field trial group
// |group|. If the value is not present, cannot be parsed, or is less than
// |min_value|, returns |default_value|.
int GetFieldTrialParameterAsInteger(const std::string& group,
                                    const std::string& param_name,
                                    int default_value,
                                    int min_value);

// Returns true if the list of Data Reduction Proxies to use for HTTP requests
// has been overridden on the command line, and if so, returns the override
// proxy list in |override_proxies_for_http|.
bool GetOverrideProxiesForHttpFromCommandLine(
    std::vector<net::ProxyServer>* override_proxies_for_http);

// Returns the name of the server side experiment field trial.
std::string GetServerExperimentsFieldTrialName();

}  // namespace params

// Contains information about a given proxy server. |proxies_for_http| and
// |proxies_for_https| contain the configured data reduction proxy servers.
// |is_fallback| and |is_ssl| note whether the given proxy is a fallback or a
// proxy for ssl; these are not mutually exclusive.
struct DataReductionProxyTypeInfo {
  DataReductionProxyTypeInfo();
  ~DataReductionProxyTypeInfo();
  std::vector<net::ProxyServer> proxy_servers;
  bool is_fallback;
  bool is_ssl;
};

// Provides initialization parameters. Proxy origins, and the secure proxy
// check url are are taken from flags if available and from preprocessor
// constants otherwise. The DataReductionProxySettings class and others use this
// class to determine the necessary DNS names to configure use of the Data
// Reduction Proxy.
class DataReductionProxyParams : public DataReductionProxyConfigValues {
 public:
  // Flags used during construction that specify if the data reduction proxy
  // is allowed to be used, if the fallback proxy is allowed to be used, if the
  // promotion is allowed to be shown, and if this instance is part of a
  // holdback experiment.
  static const unsigned int kAllowed = (1 << 0);
  static const unsigned int kFallbackAllowed = (1 << 1);
  // DEPRECATED. TODO(jeremyim): Remove once changes merged downstream.
  static const unsigned int kAlternativeAllowed = (1 << 2);
  // DEPRECATED. TODO(jeremyim): Remove once changes merged downstream.
  static const unsigned int kAlternativeFallbackAllowed = (1 << 3);
  static const unsigned int kAllowAllProxyConfigurations =
      kAllowed | kFallbackAllowed;
  static const unsigned int kPromoAllowed = (1 << 4);
  static const unsigned int kHoldback = (1 << 5);

  // Constructs configuration parameters. If |kAllowed|, then the standard
  // data reduction proxy configuration is allowed to be used. If
  // |kfallbackAllowed| a fallback proxy can be used if the primary proxy is
  // bypassed or disabled. Finally if |kPromoAllowed|, the client may show a
  // promotion for the data reduction proxy.
  //
  // A standard configuration has a primary proxy, and a fallback proxy for
  // HTTP traffic.
  explicit DataReductionProxyParams(int flags);

  ~DataReductionProxyParams() override;

  // If true, uses QUIC instead of SPDY to connect to proxies that use TLS.
  void EnableQuic(bool enable);

  // Overrides of |DataReductionProxyConfigValues|
  bool UsingHTTPTunnel(const net::HostPortPair& proxy_server) const override;

  const std::vector<net::ProxyServer>& proxies_for_http() const override;

  const std::vector<net::ProxyServer>& proxies_for_https() const override;

  const GURL& secure_proxy_check_url() const override;

  bool allowed() const override;

  bool fallback_allowed() const override;

  bool promo_allowed() const override;

  bool holdback() const override;

  bool quic_enabled() const { return quic_enabled_; }

  // Returns the corresponding string from preprocessor constants if defined,
  // and an empty string otherwise.
  virtual std::string GetDefaultDevOrigin() const;
  virtual std::string GetDefaultDevFallbackOrigin() const;

 protected:
  // Test constructor that optionally won't call Init();
  DataReductionProxyParams(int flags,
                           bool should_call_init);

  // Initialize the values of the proxies, and secure proxy check URL, from
  // command line flags and preprocessor constants, and check that there are
  // corresponding definitions for the allowed configurations.
  bool Init(bool allowed, bool fallback_allowed);

  // Initialize the values of the proxies, and secure proxy check URL from
  // command line flags and preprocessor constants.
  void InitWithoutChecks();

  // Returns the corresponding string from preprocessor constants if defined,
  // and an empty string otherwise.
  virtual std::string GetDefaultOrigin() const;
  virtual std::string GetDefaultFallbackOrigin() const;
  virtual std::string GetDefaultSSLOrigin() const;
  virtual std::string GetDefaultSecureProxyCheckURL() const;
  virtual std::string GetDefaultWarmupURL() const;

  std::vector<net::ProxyServer> proxies_for_http_;
  std::vector<net::ProxyServer> proxies_for_https_;

 private:
  net::ProxyServer origin_;
  net::ProxyServer fallback_origin_;
  net::ProxyServer ssl_origin_;

  GURL secure_proxy_check_url_;
  GURL warmup_url_;

  bool allowed_;
  bool fallback_allowed_;
  bool promo_allowed_;
  bool holdback_;
  bool quic_enabled_;
  std::string override_quic_origin_;

  bool configured_on_command_line_;

  bool use_override_proxies_for_http_;
  std::vector<net::ProxyServer> override_proxies_for_http_;

  DISALLOW_COPY_AND_ASSIGN(DataReductionProxyParams);
};

}  // namespace data_reduction_proxy
#endif  // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PARAMS_H_