OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_CORE_BROWSER_DATA_REDUCTION_PROXY_CONFIG _H_ | 5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_CONFIG _H_ |
6 #define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_CONFIG _H_ | 6 #define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_CONFIG _H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 // Returns true if the Data Reduction Proxy promo may be shown. This is not | 184 // Returns true if the Data Reduction Proxy promo may be shown. This is not |
185 // tied to whether the Data Reduction Proxy is enabled. | 185 // tied to whether the Data Reduction Proxy is enabled. |
186 bool promo_allowed() const; | 186 bool promo_allowed() const; |
187 | 187 |
188 // Sets |lofi_off_| to true. | 188 // Sets |lofi_off_| to true. |
189 void SetLoFiModeOff(); | 189 void SetLoFiModeOff(); |
190 | 190 |
191 // Returns |lofi_off_|. | 191 // Returns |lofi_off_|. |
192 bool lofi_off() const { return lofi_off_; } | 192 bool lofi_off() const { return lofi_off_; } |
193 | 193 |
194 // Returns true when Lo-Fi Previews should be activated. Records metrics for | 194 // Returns true when Lo-Fi Previews are allowed on the client. |
bengr
2017/05/01 16:53:14
previews? case?
| |
195 // Lo-Fi state changes. |request| is used to get the network quality estimator | |
196 // from the URLRequestContext. | |
197 bool ShouldEnableLoFi(const net::URLRequest& request); | 195 bool ShouldEnableLoFi(const net::URLRequest& request); |
198 | 196 |
199 // Returns true when Lite Page Previews should be activated. |request| is used | 197 // Returns true when Lite Page Previews should be activated. |
200 // to get the network quality estimator from the URLRequestContext. | |
201 bool ShouldEnableLitePages(const net::URLRequest& request); | 198 bool ShouldEnableLitePages(const net::URLRequest& request); |
202 | 199 |
203 // Returns true if the data saver has been enabled by the user, and the data | 200 // Returns true if the data saver has been enabled by the user, and the data |
204 // saver proxy is reachable. | 201 // saver proxy is reachable. |
205 bool enabled_by_user_and_reachable() const; | 202 bool enabled_by_user_and_reachable() const; |
206 | 203 |
207 // Gets the ProxyConfig that would be used ignoring the holdback experiment. | 204 // Gets the ProxyConfig that would be used ignoring the holdback experiment. |
208 // This should only be used for logging purposes. | 205 // This should only be used for logging purposes. |
209 net::ProxyConfig ProxyConfigIgnoringHoldback() const; | 206 net::ProxyConfig ProxyConfigIgnoringHoldback() const; |
210 | 207 |
211 bool secure_proxy_allowed() const; | 208 bool secure_proxy_allowed() const; |
212 | 209 |
213 std::vector<DataReductionProxyServer> GetProxiesForHttp() const; | 210 std::vector<DataReductionProxyServer> GetProxiesForHttp() const; |
214 | 211 |
215 protected: | 212 protected: |
216 // Virtualized for mocking. Returns the list of network interfaces in use. | 213 // Virtualized for mocking. Returns the list of network interfaces in use. |
217 // |interfaces| can be null. | 214 // |interfaces| can be null. |
218 virtual void GetNetworkList(net::NetworkInterfaceList* interfaces, | 215 virtual void GetNetworkList(net::NetworkInterfaceList* interfaces, |
219 int policy); | 216 int policy); |
220 | 217 |
221 // Virtualized for testing. Returns the list of intervals at which accuracy of | |
222 // network quality prediction should be recorded. | |
223 virtual const std::vector<base::TimeDelta>& | |
224 GetLofiAccuracyRecordingIntervals() const; | |
225 | |
226 virtual base::TimeTicks GetTicksNow() const; | 218 virtual base::TimeTicks GetTicksNow() const; |
227 | 219 |
228 // Updates the Data Reduction Proxy configurator with the current config. | 220 // Updates the Data Reduction Proxy configurator with the current config. |
229 void UpdateConfigForTesting(bool enabled, bool restricted); | 221 void UpdateConfigForTesting(bool enabled, bool restricted); |
230 | 222 |
231 private: | 223 private: |
232 friend class MockDataReductionProxyConfig; | 224 friend class MockDataReductionProxyConfig; |
233 friend class TestDataReductionProxyConfig; | 225 friend class TestDataReductionProxyConfig; |
234 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, | 226 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, |
235 TestSetProxyConfigsHoldback); | 227 TestSetProxyConfigsHoldback); |
236 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, | 228 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, |
237 AreProxiesBypassed); | 229 AreProxiesBypassed); |
238 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, | 230 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, |
239 AreProxiesBypassedRetryDelay); | 231 AreProxiesBypassedRetryDelay); |
240 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, AutoLoFiParams); | |
241 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, AutoLoFiMissingParams); | |
242 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, | |
243 AutoLoFiParamsSlowConnectionsFlag); | |
244 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, LoFiAccuracy); | |
245 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, | |
246 LoFiAccuracyNonZeroDelay); | |
247 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, WarmupURL); | 232 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, WarmupURL); |
248 | 233 |
249 // Values of the estimated network quality at the beginning of the most | |
250 // recent query of the Network Quality Estimator. | |
251 enum NetworkQualityAtLastQuery { | |
bengr
2017/05/01 16:53:14
Give tbansal@ a heads up that all of this stuff is
| |
252 NETWORK_QUALITY_AT_LAST_QUERY_UNKNOWN, | |
253 NETWORK_QUALITY_AT_LAST_QUERY_SLOW, | |
254 NETWORK_QUALITY_AT_LAST_QUERY_NOT_SLOW | |
255 }; | |
256 | |
257 // NetworkChangeNotifier::IPAddressObserver: | 234 // NetworkChangeNotifier::IPAddressObserver: |
258 void OnIPAddressChanged() override; | 235 void OnIPAddressChanged() override; |
259 void OnConnectionTypeChanged( | 236 void OnConnectionTypeChanged( |
260 net::NetworkChangeNotifier::ConnectionType type) override; | 237 net::NetworkChangeNotifier::ConnectionType type) override; |
261 | 238 |
262 // Populates the parameters for the Lo-Fi field trial if the session is part | |
263 // of either Lo-Fi enabled or Lo-Fi control field trial group. | |
264 void PopulateAutoLoFiParams(); | |
265 | |
266 // Requests the given |secure_proxy_check_url|. Upon completion, returns the | 239 // Requests the given |secure_proxy_check_url|. Upon completion, returns the |
267 // results to the caller via the |fetcher_callback|. Virtualized for unit | 240 // results to the caller via the |fetcher_callback|. Virtualized for unit |
268 // testing. | 241 // testing. |
269 virtual void SecureProxyCheck(const GURL& secure_proxy_check_url, | 242 virtual void SecureProxyCheck(const GURL& secure_proxy_check_url, |
270 FetcherResponseCallback fetcher_callback); | 243 FetcherResponseCallback fetcher_callback); |
271 | 244 |
272 // Parses the secure proxy check responses and appropriately configures the | 245 // Parses the secure proxy check responses and appropriately configures the |
273 // Data Reduction Proxy rules. | 246 // Data Reduction Proxy rules. |
274 void HandleSecureProxyCheckResponse(const std::string& response, | 247 void HandleSecureProxyCheckResponse(const std::string& response, |
275 const net::URLRequestStatus& status, | 248 const net::URLRequestStatus& status, |
276 int http_response_code); | 249 int http_response_code); |
277 | 250 |
278 // Adds the default proxy bypass rules for the Data Reduction Proxy. | 251 // Adds the default proxy bypass rules for the Data Reduction Proxy. |
279 void AddDefaultProxyBypassRules(); | 252 void AddDefaultProxyBypassRules(); |
280 | 253 |
281 // Checks if all configured data reduction proxies are in the retry map. | 254 // Checks if all configured data reduction proxies are in the retry map. |
282 // Returns true if the request is bypassed by all configured data reduction | 255 // Returns true if the request is bypassed by all configured data reduction |
283 // proxies that apply to the request scheme. If all possible data reduction | 256 // proxies that apply to the request scheme. If all possible data reduction |
284 // proxies are bypassed, returns the minimum retry delay of the bypassed data | 257 // proxies are bypassed, returns the minimum retry delay of the bypassed data |
285 // reduction proxies in min_retry_delay (if not NULL). If there are no | 258 // reduction proxies in min_retry_delay (if not NULL). If there are no |
286 // bypassed data reduction proxies for the request scheme, returns false and | 259 // bypassed data reduction proxies for the request scheme, returns false and |
287 // does not assign min_retry_delay. | 260 // does not assign min_retry_delay. |
288 bool AreProxiesBypassed( | 261 bool AreProxiesBypassed( |
289 const net::ProxyRetryInfoMap& retry_map, | 262 const net::ProxyRetryInfoMap& retry_map, |
290 const net::ProxyConfig::ProxyRules& proxy_rules, | 263 const net::ProxyConfig::ProxyRules& proxy_rules, |
291 bool is_https, | 264 bool is_https, |
292 base::TimeDelta* min_retry_delay) const; | 265 base::TimeDelta* min_retry_delay) const; |
293 | 266 |
294 // Returns true when Lo-Fi Previews should be activated. Determines if Lo-Fi | |
295 // Previews should be activated by checking the Lo-Fi flags and if the network | |
296 // quality is prohibitively slow. |network_quality_estimator| may be NULL. | |
297 bool ShouldEnableLoFiInternal( | |
298 const net::NetworkQualityEstimator* network_quality_estimator); | |
299 | |
300 // Returns true when Lite Page Previews should be activated. Determines if | |
301 // Lite Page Previewsmode should be activated by checking the Lite Page | |
302 // Previews flags and if the network quality is prohibitively slow. | |
303 // |network_quality_estimator| may be NULL. | |
304 bool ShouldEnableLitePagesInternal( | |
305 const net::NetworkQualityEstimator* network_quality_estimator); | |
306 | |
307 // Returns true if the network quality is at least as poor as the one | |
308 // specified in the Auto Lo-Fi field trial parameters. | |
309 // |network_quality_estimator| may be NULL. Virtualized for unit testing. | |
310 virtual bool IsNetworkQualityProhibitivelySlow( | 267 virtual bool IsNetworkQualityProhibitivelySlow( |
311 const net::NetworkQualityEstimator* network_quality_estimator); | 268 const net::NetworkQualityEstimator* network_quality_estimator); |
312 | 269 |
313 // Records Lo-Fi accuracy metric. |measuring_duration| should belong to the | |
314 // vector returned by LofiAccuracyRecordingIntervals(). | |
315 // RecordAutoLoFiAccuracyRate should be called |measuring_duration| after a | |
316 // main frame request is observed. | |
317 void RecordAutoLoFiAccuracyRate( | |
318 const net::NetworkQualityEstimator* network_quality_estimator, | |
319 const base::TimeDelta& measuring_duration) const; | |
320 | |
321 // Returns true if |effective_connection_type| is at least as poor as | |
322 // |lofi_effective_connection_type_threshold_|. | |
323 bool IsEffectiveConnectionTypeSlowerThanThreshold( | |
324 net::EffectiveConnectionType effective_connection_type) const; | |
325 | |
326 // Checks if the current network has captive portal, and handles the result. | 270 // Checks if the current network has captive portal, and handles the result. |
327 // If the captive portal probe was blocked on the current network, disables | 271 // If the captive portal probe was blocked on the current network, disables |
328 // the use of secure proxies. | 272 // the use of secure proxies. |
329 void HandleCaptivePortal(); | 273 void HandleCaptivePortal(); |
330 | 274 |
331 // Returns true if the current network has captive portal. Virtualized | 275 // Returns true if the current network has captive portal. Virtualized |
332 // for testing. | 276 // for testing. |
333 virtual bool GetIsCaptivePortal() const; | 277 virtual bool GetIsCaptivePortal() const; |
334 | 278 |
335 // Fetches the warmup URL. | 279 // Fetches the warmup URL. |
(...skipping 26 matching lines...) Expand all Loading... | |
362 | 306 |
363 // The caller must ensure that the |configurator_| outlives this instance. | 307 // The caller must ensure that the |configurator_| outlives this instance. |
364 DataReductionProxyConfigurator* configurator_; | 308 DataReductionProxyConfigurator* configurator_; |
365 | 309 |
366 // The caller must ensure that the |event_creator_| outlives this instance. | 310 // The caller must ensure that the |event_creator_| outlives this instance. |
367 DataReductionProxyEventCreator* event_creator_; | 311 DataReductionProxyEventCreator* event_creator_; |
368 | 312 |
369 // Enforce usage on the IO thread. | 313 // Enforce usage on the IO thread. |
370 base::ThreadChecker thread_checker_; | 314 base::ThreadChecker thread_checker_; |
371 | 315 |
372 // Thresholds from the field trial at which auto Lo-Fi is turned on. | |
373 // If the effective connection type is at least as slow as | |
374 // |lofi_effective_connection_type_threshold_|, Lo-Fi would be turned on. | |
375 net::EffectiveConnectionType lofi_effective_connection_type_threshold_; | |
376 | |
377 // State of auto Lo-Fi is not changed more than once in any period of | |
378 // duration shorter than |auto_lofi_hysteresis_|. | |
379 base::TimeDelta auto_lofi_hysteresis_; | |
380 | |
381 // Time when the network quality was last checked. | |
382 base::TimeTicks network_quality_last_checked_; | |
383 | |
384 // True iff the network was determined to be prohibitively slow when the | |
385 // network quality was last updated. This happens on when the network quality | |
386 // was last checked, and not more than once in any window of duration shorter | |
387 // than |auto_lofi_hysteresis_|. | |
388 bool network_prohibitively_slow_; | |
389 | |
390 // The current connection type. | 316 // The current connection type. |
391 net::NetworkChangeNotifier::ConnectionType connection_type_; | 317 net::NetworkChangeNotifier::ConnectionType connection_type_; |
392 | 318 |
393 // True if the connection type changed since the last call to | |
394 // IsNetworkQualityProhibitivelySlow(). This call happens only on main frame | |
395 // requests. | |
396 bool connection_type_changed_; | |
397 | |
398 // If true, Lo-Fi is turned off for the rest of the session. This is set to | 319 // If true, Lo-Fi is turned off for the rest of the session. This is set to |
399 // true if Lo-Fi is disabled via flags or if the user implicitly opts out. | 320 // true if Lo-Fi is disabled via flags or if the user implicitly opts out. |
400 bool lofi_off_; | 321 bool lofi_off_; |
401 | 322 |
402 // Timestamp when the most recent query of the Network Quality Estimator | |
403 // happened. | |
404 base::TimeTicks last_query_; | |
405 | |
406 // Holds the estimated network quality at the last query of the estimator. | |
407 // This should be used only for the purpose of recording Lo-Fi accuracy UMA. | |
408 NetworkQualityAtLastQuery network_quality_at_last_query_; | |
409 | |
410 // True if the previous state of Lo-Fi was on, so that change in Lo-Fi status | |
411 // can be recorded properly. This is not recorded for the control group, | |
412 // because it is only used to report changes in request headers, and the | |
413 // request headers are never modified in the control group. | |
414 bool previous_state_lofi_on_; | |
415 | |
416 // Intervals after the main frame request arrives at which accuracy of network | |
417 // quality prediction is recorded. | |
418 std::vector<base::TimeDelta> lofi_accuracy_recording_intervals_; | |
419 | |
420 // Set to true if the captive portal probe for the current network has been | 323 // Set to true if the captive portal probe for the current network has been |
421 // blocked. | 324 // blocked. |
422 bool is_captive_portal_; | 325 bool is_captive_portal_; |
423 | 326 |
424 base::WeakPtrFactory<DataReductionProxyConfig> weak_factory_; | 327 base::WeakPtrFactory<DataReductionProxyConfig> weak_factory_; |
425 | 328 |
426 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyConfig); | 329 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyConfig); |
427 }; | 330 }; |
428 | 331 |
429 } // namespace data_reduction_proxy | 332 } // namespace data_reduction_proxy |
430 | 333 |
431 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_CON FIG_H_ | 334 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_CON FIG_H_ |
OLD | NEW |