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

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

Issue 286013002: Added alternative configuration for the data reduction proxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DCHECK fix 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_SETTINGS_H_ 5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_SETTINGS_H_
6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_SETTINGS_H_ 6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_SETTINGS_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/prefs/pref_member.h" 14 #include "base/prefs/pref_member.h"
15 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
16 #include "components/data_reduction_proxy/browser/data_reduction_proxy_configura tor.h" 16 #include "components/data_reduction_proxy/browser/data_reduction_proxy_configura tor.h"
17 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
17 #include "net/base/network_change_notifier.h" 18 #include "net/base/network_change_notifier.h"
18 #include "net/url_request/url_fetcher_delegate.h" 19 #include "net/url_request/url_fetcher_delegate.h"
19 20
20 class PrefService; 21 class PrefService;
21 22
22 namespace net { 23 namespace net {
23 class AuthChallengeInfo; 24 class AuthChallengeInfo;
24 class HostPortPair; 25 class HostPortPair;
25 class HttpAuthCache; 26 class HttpAuthCache;
26 class HttpNetworkSession; 27 class HttpNetworkSession;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // Central point for configuring the data reduction proxy. 80 // Central point for configuring the data reduction proxy.
80 // This object lives on the UI thread and all of its methods are expected to 81 // This object lives on the UI thread and all of its methods are expected to
81 // be called from there. 82 // be called from there.
82 // TODO(marq): Convert this to be a KeyedService with an 83 // TODO(marq): Convert this to be a KeyedService with an
83 // associated factory class, and refactor the Java call sites accordingly. 84 // associated factory class, and refactor the Java call sites accordingly.
84 class DataReductionProxySettings 85 class DataReductionProxySettings
85 : public net::URLFetcherDelegate, 86 : public net::URLFetcherDelegate,
86 public net::NetworkChangeNotifier::IPAddressObserver { 87 public net::NetworkChangeNotifier::IPAddressObserver {
87 public: 88 public:
88 typedef std::vector<long long> ContentLengthList; 89 typedef std::vector<long long> ContentLengthList;
89 // TODO(marq): Consider instead using a std::pair instead of a vector.
90 typedef std::vector<GURL> DataReductionProxyList;
91 90
92 // Returns true of the data reduction proxy origin is set on the command line.
93 static bool IsProxyOriginSetOnCommandLine();
94
95 // Returns true if the data reduction proxy key is set on the command line.
96 static bool IsProxyKeySetOnCommandLine(); 91 static bool IsProxyKeySetOnCommandLine();
97 92
98 // Returns true if this application instance is part of the data reduction 93 DataReductionProxySettings(DataReductionProxyParams* params);
99 // proxy field trial, or if it a proxy origin is set in flags. This is a
100 // convenience method for platforms like Chrome on Android and iOS, to
101 // determine if the data reduction proxy is allowed.
102 static bool IsIncludedInFieldTrialOrFlags();
103
104 static void SetAllowed(bool allowed);
105 static void SetPromoAllowed(bool promo_allowed);
106
107 DataReductionProxySettings();
108 virtual ~DataReductionProxySettings(); 94 virtual ~DataReductionProxySettings();
109 95
110 // Set and get the key to be used for data reduction proxy authentication. 96 DataReductionProxyParams* params() const {
111 void set_key(const std::string& key) { 97 return params_.get();
112 key_ = key;
113 }
114
115 const std::string& key() const {
116 return key_;
117 } 98 }
118 99
119 // Initializes the data reduction proxy with profile and local state prefs, 100 // Initializes the data reduction proxy with profile and local state prefs,
120 // and a |UrlRequestContextGetter| for canary probes. The caller must ensure 101 // and a |UrlRequestContextGetter| for canary probes. The caller must ensure
121 // that all parameters remain alive for the lifetime of the 102 // that all parameters remain alive for the lifetime of the
122 // |DataReductionProxySettings| instance. 103 // |DataReductionProxySettings| instance.
123 void InitDataReductionProxySettings( 104 void InitDataReductionProxySettings(
124 PrefService* prefs, 105 PrefService* prefs,
125 PrefService* local_state_prefs, 106 PrefService* local_state_prefs,
126 net::URLRequestContextGetter* url_request_context_getter); 107 net::URLRequestContextGetter* url_request_context_getter);
127 108
128 // Initializes the data reduction proxy with profile and local state prefs, 109 // Initializes the data reduction proxy with profile and local state prefs,
129 // a |UrlRequestContextGetter| for canary probes, and a proxy configurator. 110 // a |UrlRequestContextGetter| for canary probes, and a proxy configurator.
130 // The caller must ensure that all parameters remain alive for the lifetime of 111 // The caller must ensure that all parameters remain alive for the lifetime of
131 // the |DataReductionProxySettings| instance. 112 // the |DataReductionProxySettings| instance.
132 // TODO(marq): Remove when iOS supports the new interface above. 113 // TODO(marq): Remove when iOS supports the new interface above.
133 void InitDataReductionProxySettings( 114 void InitDataReductionProxySettings(
134 PrefService* prefs, 115 PrefService* prefs,
135 PrefService* local_state_prefs, 116 PrefService* local_state_prefs,
136 net::URLRequestContextGetter* url_request_context_getter, 117 net::URLRequestContextGetter* url_request_context_getter,
137 scoped_ptr<DataReductionProxyConfigurator> config); 118 scoped_ptr<DataReductionProxyConfigurator> configurator);
138 119
139 // Sets the logic the embedder uses to set the networking configuration that 120 // Sets the logic the embedder uses to set the networking configuration that
140 // causes traffic to be proxied. 121 // causes traffic to be proxied.
141 void SetProxyConfigurator( 122 void SetProxyConfigurator(
142 scoped_ptr<DataReductionProxyConfigurator> configurator); 123 scoped_ptr<DataReductionProxyConfigurator> configurator);
143 124
144 // If proxy authentication is compiled in, pre-cache an authentication 125 // If proxy authentication is compiled in, pre-cache authentication
145 // |key| for all configured proxies in |session|. 126 // keys for all configured proxies in |session|.
146 static void InitDataReductionProxySession(net::HttpNetworkSession* session, 127 static void InitDataReductionProxySession(
147 const std::string& key); 128 net::HttpNetworkSession* session,
148 129 const DataReductionProxyParams* params);
149 // Returns true if the data reduction proxy is allowed to be used. This could
150 // return false, for example, if this instance is not part of the field trial,
151 // or if the proxy name is not configured via gyp.
152 static bool IsDataReductionProxyAllowed();
153
154 // Returns true if a screen promoting the data reduction proxy is allowed to
155 // be shown. Logic that decides when to show the promo should check its
156 // availability. This would return false if not part of a separate field
157 // trial that governs the use of the promotion.
158 static bool IsDataReductionProxyPromoAllowed();
159
160 // Returns true if preconnect advisory hinting is enabled by command line
161 // flag or Finch trial.
162 static bool IsPreconnectHintingAllowed();
163
164 // Returns the URL of the data reduction proxy.
165 static std::string GetDataReductionProxyOrigin();
166
167 // Returns the URL of the fallback data reduction proxy.
168 static std::string GetDataReductionProxyFallback();
169
170 // Returns a vector of GURLs for all configured proxies.
171 static DataReductionProxyList GetDataReductionProxies();
172 130
173 // Returns true if |auth_info| represents an authentication challenge from 131 // Returns true if |auth_info| represents an authentication challenge from
174 // a compatible, configured proxy. 132 // a compatible, configured proxy.
175 static bool IsAcceptableAuthChallenge(net::AuthChallengeInfo* auth_info); 133 bool IsAcceptableAuthChallenge(net::AuthChallengeInfo* auth_info);
176 134
177 // Returns a UTF16 string suitable for use as an authentication token in 135 // Returns a UTF16 string suitable for use as an authentication token in
178 // response to the challenge represented by |auth_info|. If the token can't 136 // response to the challenge represented by |auth_info|. If the token can't
179 // be correctly generated for |auth_info|, returns an empty UTF16 string. 137 // be correctly generated for |auth_info|, returns an empty UTF16 string.
180 base::string16 GetTokenForAuthChallenge(net::AuthChallengeInfo* auth_info); 138 base::string16 GetTokenForAuthChallenge(net::AuthChallengeInfo* auth_info);
181 139
182 // Returns true if the proxy is enabled. 140 // Returns true if the proxy is enabled.
183 bool IsDataReductionProxyEnabled(); 141 bool IsDataReductionProxyEnabled();
184 142
143 // Returns true if the alternative proxy is enabled.
144 bool IsDataReductionProxyAlternativeEnabled();
145
185 // Returns true if the proxy is managed by an adminstrator's policy. 146 // Returns true if the proxy is managed by an adminstrator's policy.
186 bool IsDataReductionProxyManaged(); 147 bool IsDataReductionProxyManaged();
187 148
188 // Enables or disables the data reduction proxy. If a probe URL is available, 149 // Enables or disables the data reduction proxy. If a probe URL is available,
189 // and a probe request fails at some point, the proxy won't be used until a 150 // and a probe request fails at some point, the proxy won't be used until a
190 // probe succeeds. 151 // probe succeeds.
191 void SetDataReductionProxyEnabled(bool enabled); 152 void SetDataReductionProxyEnabled(bool enabled);
192 153
193 // If |allowed|, the fallback proxy will be included in the proxy 154 // Enables or disables the alternative data reduction proxy configuration.
194 // configuration. 155 void SetDataReductionProxyAlternativeEnabled(bool enabled);
195 void set_fallback_allowed(bool allowed) {
196 fallback_allowed_ = allowed;
197 }
198
199 bool fallback_allowed() const {
200 return fallback_allowed_;
201 }
202 156
203 // Returns the time in microseconds that the last update was made to the 157 // Returns the time in microseconds that the last update was made to the
204 // daily original and received content lengths. 158 // daily original and received content lengths.
205 int64 GetDataReductionLastUpdateTime(); 159 int64 GetDataReductionLastUpdateTime();
206 160
207 // Returns a vector containing the total size of all HTTP content that was 161 // Returns a vector containing the total size of all HTTP content that was
208 // received over the last |kNumDaysInHistory| before any compression by the 162 // received over the last |kNumDaysInHistory| before any compression by the
209 // data reduction proxy. Each element in the vector contains one day of data. 163 // data reduction proxy. Each element in the vector contains one day of data.
210 ContentLengthList GetDailyOriginalContentLengths(); 164 ContentLengthList GetDailyOriginalContentLengths();
211 165
(...skipping 13 matching lines...) Expand all
225 virtual PrefService* GetOriginalProfilePrefs(); 179 virtual PrefService* GetOriginalProfilePrefs();
226 virtual PrefService* GetLocalStatePrefs(); 180 virtual PrefService* GetLocalStatePrefs();
227 181
228 void GetContentLengths(unsigned int days, 182 void GetContentLengths(unsigned int days,
229 int64* original_content_length, 183 int64* original_content_length,
230 int64* received_content_length, 184 int64* received_content_length,
231 int64* last_update_time); 185 int64* last_update_time);
232 ContentLengthList GetDailyContentLengths(const char* pref_name); 186 ContentLengthList GetDailyContentLengths(const char* pref_name);
233 187
234 // Sets the proxy configs, enabling or disabling the proxy according to 188 // Sets the proxy configs, enabling or disabling the proxy according to
235 // the value of |enabled|. If |restricted| is true, only enable the fallback 189 // the value of |enabled| and |alternative_enabled|. Use the alternative
236 // proxy. |at_startup| is true when this method is called from 190 // configuration only if |enabled| and |alternative_enabled| are true. If
237 // InitDataReductionProxySettings. 191 // |restricted| is true, only enable the fallback proxy. |at_startup| is true
238 virtual void SetProxyConfigs(bool enabled, bool restricted, bool at_startup); 192 // when this method is called from InitDataReductionProxySettings.
193 virtual void SetProxyConfigs(bool enabled,
194 bool alternative_enabled,
195 bool restricted,
196 bool at_startup);
239 197
240 // Metrics methods. Subclasses should override if they wish to provide 198 // Metrics method. Subclasses should override if they wish to provide
241 // alternate methods. 199 // alternatives.
242 virtual void RecordDataReductionInit(); 200 virtual void RecordDataReductionInit();
243 201
244 virtual void AddDefaultProxyBypassRules(); 202 virtual void AddDefaultProxyBypassRules();
245 203
246 // Writes a warning to the log that is used in backend processing of 204 // Writes a warning to the log that is used in backend processing of
247 // customer feedback. Virtual so tests can mock it for verification. 205 // customer feedback. Virtual so tests can mock it for verification.
248 virtual void LogProxyState(bool enabled, bool restricted, bool at_startup); 206 virtual void LogProxyState(bool enabled, bool restricted, bool at_startup);
249 207
250 // Virtualized for mocking 208 // Virtualized for mocking
251 virtual void RecordProbeURLFetchResult( 209 virtual void RecordProbeURLFetchResult(
252 data_reduction_proxy::ProbeURLFetchResult result); 210 data_reduction_proxy::ProbeURLFetchResult result);
253 virtual void RecordStartupState( 211 virtual void RecordStartupState(
254 data_reduction_proxy::ProxyStartupState state); 212 data_reduction_proxy::ProxyStartupState state);
255 213
256 DataReductionProxyConfigurator* config() { 214 DataReductionProxyConfigurator* configurator() {
257 return config_.get(); 215 return configurator_.get();
258 } 216 }
259 217
218 // Reset params for tests.
219 void ResetParamsForTest(DataReductionProxyParams* params);
220
260 private: 221 private:
261 friend class DataReductionProxySettingsTestBase; 222 friend class DataReductionProxySettingsTestBase;
262 friend class DataReductionProxySettingsTest; 223 friend class DataReductionProxySettingsTest;
263 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, 224 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
264 TestAuthenticationInit); 225 TestAuthenticationInit);
265 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, 226 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
266 TestAuthHashGeneration); 227 TestAuthHashGeneration);
267 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, 228 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
268 TestAuthHashGenerationWithOriginSetViaSwitch); 229 TestAuthHashGenerationWithOriginSetViaSwitch);
269 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, 230 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
(...skipping 11 matching lines...) Expand all
281 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, 242 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
282 TestOnProxyEnabledPrefChange); 243 TestOnProxyEnabledPrefChange);
283 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, 244 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
284 TestInitDataReductionProxyOn); 245 TestInitDataReductionProxyOn);
285 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, 246 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
286 TestInitDataReductionProxyOff); 247 TestInitDataReductionProxyOff);
287 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, 248 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
288 TestBypassList); 249 TestBypassList);
289 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, 250 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
290 CheckInitMetricsWhenNotAllowed); 251 CheckInitMetricsWhenNotAllowed);
252 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
253 TestSetProxyConfigs);
291 254
292 // NetworkChangeNotifier::IPAddressObserver: 255 // NetworkChangeNotifier::IPAddressObserver:
293 virtual void OnIPAddressChanged() OVERRIDE; 256 virtual void OnIPAddressChanged() OVERRIDE;
294 257
295 // Underlying implementation of InitDataReductionProxySession(), factored 258 // Underlying implementation of InitDataReductionProxySession(), factored
296 // out to be testable without creating a full HttpNetworkSession. 259 // out to be testable without creating a full HttpNetworkSession.
297 static void InitDataReductionAuthentication(net::HttpAuthCache* auth_cache, 260 static void InitDataReductionAuthentication(
298 const std::string& key); 261 net::HttpAuthCache* auth_cache,
262 const DataReductionProxyParams* params);
299 263
300 void OnProxyEnabledPrefChange(); 264 void OnProxyEnabledPrefChange();
265 void OnProxyAlternativeEnabledPrefChange();
301 266
302 void ResetDataReductionStatistics(); 267 void ResetDataReductionStatistics();
303 268
304 void MaybeActivateDataReductionProxy(bool at_startup); 269 void MaybeActivateDataReductionProxy(bool at_startup);
305 270
306 // Requests the proxy probe URL, if one is set. If unable to do so, disables 271 // Requests the proxy probe URL, if one is set. If unable to do so, disables
307 // the proxy, if enabled. Otherwise enables the proxy if disabled by a probe 272 // the proxy, if enabled. Otherwise enables the proxy if disabled by a probe
308 // failure. 273 // failure.
309 void ProbeWhetherDataReductionProxyIsAvailable(); 274 void ProbeWhetherDataReductionProxyIsAvailable();
310 std::string GetProxyCheckURL();
311 275
312 // Returns a UTF16 string that's the hash of the configured authentication 276 // Returns a UTF16 string that's the hash of the configured authentication
313 // |key| and |salt|. Returns an empty UTF16 string if no key is configured or 277 // |key| and |salt|. Returns an empty UTF16 string if no key is configured or
314 // the data reduction proxy feature isn't available. 278 // the data reduction proxy feature isn't available.
315 static base::string16 AuthHashForSalt(int64 salt, const std::string& key); 279 static base::string16 AuthHashForSalt(int64 salt,
316 280 const std::string& key);
317 static bool allowed_;
318 static bool promo_allowed_;
319 281
320 std::string key_; 282 std::string key_;
321 bool restricted_by_carrier_; 283 bool restricted_by_carrier_;
322 bool enabled_by_user_; 284 bool enabled_by_user_;
323 285
324 scoped_ptr<net::URLFetcher> fetcher_; 286 scoped_ptr<net::URLFetcher> fetcher_;
325 BooleanPrefMember spdy_proxy_auth_enabled_; 287 BooleanPrefMember spdy_proxy_auth_enabled_;
288 BooleanPrefMember data_reduction_proxy_alternative_enabled_;
326 289
327 PrefService* prefs_; 290 PrefService* prefs_;
328 PrefService* local_state_prefs_; 291 PrefService* local_state_prefs_;
329 292
330 net::URLRequestContextGetter* url_request_context_getter_; 293 net::URLRequestContextGetter* url_request_context_getter_;
331 294
332 scoped_ptr<DataReductionProxyConfigurator> config_; 295 scoped_ptr<DataReductionProxyConfigurator> configurator_;
333 296
334 base::ThreadChecker thread_checker_; 297 base::ThreadChecker thread_checker_;
335 298
336 bool fallback_allowed_; 299 scoped_ptr<DataReductionProxyParams> params_;
337 300
338 DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettings); 301 DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettings);
339 }; 302 };
340 303
341 } // namespace data_reduction_proxy 304 } // namespace data_reduction_proxy
342 305
343 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_SETTINGS _H_ 306 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_SETTINGS _H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698