Chromium Code Reviews| 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 - subject to |
| 195 // Lo-Fi state changes. |request| is used to get the network quality estimator | 195 // proxy server asking for them (via alt-transforms directive). |
|
megjablon
2017/04/25 23:10:36
I thought this didn't support alt-transforms yet a
dougarnett
2017/04/26 19:50:48
True, hadn't backed this comment update out (it wa
| |
| 196 // from the URLRequestContext. | |
| 197 bool ShouldEnableLoFi(const net::URLRequest& request); | 196 bool ShouldEnableLoFi(const net::URLRequest& request); |
| 198 | 197 |
| 199 // Returns true when Lite Page Previews should be activated. |request| is used | 198 // 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); | 199 bool ShouldEnableLitePages(const net::URLRequest& request); |
| 202 | 200 |
| 203 // Returns true if the data saver has been enabled by the user, and the data | 201 // Returns true if the data saver has been enabled by the user, and the data |
| 204 // saver proxy is reachable. | 202 // saver proxy is reachable. |
| 205 bool enabled_by_user_and_reachable() const; | 203 bool enabled_by_user_and_reachable() const; |
| 206 | 204 |
| 207 // Gets the ProxyConfig that would be used ignoring the holdback experiment. | 205 // Gets the ProxyConfig that would be used ignoring the holdback experiment. |
| 208 // This should only be used for logging purposes. | 206 // This should only be used for logging purposes. |
| 209 net::ProxyConfig ProxyConfigIgnoringHoldback() const; | 207 net::ProxyConfig ProxyConfigIgnoringHoldback() const; |
| 210 | 208 |
| 211 bool secure_proxy_allowed() const; | 209 bool secure_proxy_allowed() const; |
| 212 | 210 |
| 213 std::vector<DataReductionProxyServer> GetProxiesForHttp() const; | 211 std::vector<DataReductionProxyServer> GetProxiesForHttp() const; |
| 214 | 212 |
| 215 protected: | 213 protected: |
| 216 // Virtualized for mocking. Returns the list of network interfaces in use. | 214 // Virtualized for mocking. Returns the list of network interfaces in use. |
| 217 // |interfaces| can be null. | 215 // |interfaces| can be null. |
| 218 virtual void GetNetworkList(net::NetworkInterfaceList* interfaces, | 216 virtual void GetNetworkList(net::NetworkInterfaceList* interfaces, |
| 219 int policy); | 217 int policy); |
| 220 | 218 |
| 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; | 219 virtual base::TimeTicks GetTicksNow() const; |
| 227 | 220 |
| 228 // Updates the Data Reduction Proxy configurator with the current config. | 221 // Updates the Data Reduction Proxy configurator with the current config. |
| 229 void UpdateConfigForTesting(bool enabled, bool restricted); | 222 void UpdateConfigForTesting(bool enabled, bool restricted); |
| 230 | 223 |
| 231 private: | 224 private: |
| 232 friend class MockDataReductionProxyConfig; | 225 friend class MockDataReductionProxyConfig; |
| 233 friend class TestDataReductionProxyConfig; | 226 friend class TestDataReductionProxyConfig; |
| 234 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, | 227 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, |
| 235 TestSetProxyConfigsHoldback); | 228 TestSetProxyConfigsHoldback); |
| 236 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, | 229 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, |
| 237 AreProxiesBypassed); | 230 AreProxiesBypassed); |
| 238 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, | 231 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, |
| 239 AreProxiesBypassedRetryDelay); | 232 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); | 233 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, WarmupURL); |
| 248 | 234 |
| 249 // Values of the estimated network quality at the beginning of the most | |
| 250 // recent query of the Network Quality Estimator. | |
| 251 enum NetworkQualityAtLastQuery { | |
| 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: | 235 // NetworkChangeNotifier::IPAddressObserver: |
| 258 void OnIPAddressChanged() override; | 236 void OnIPAddressChanged() override; |
| 259 void OnConnectionTypeChanged( | 237 void OnConnectionTypeChanged( |
| 260 net::NetworkChangeNotifier::ConnectionType type) override; | 238 net::NetworkChangeNotifier::ConnectionType type) override; |
| 261 | 239 |
| 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 | 240 // Requests the given |secure_proxy_check_url|. Upon completion, returns the |
| 267 // results to the caller via the |fetcher_callback|. Virtualized for unit | 241 // results to the caller via the |fetcher_callback|. Virtualized for unit |
| 268 // testing. | 242 // testing. |
| 269 virtual void SecureProxyCheck(const GURL& secure_proxy_check_url, | 243 virtual void SecureProxyCheck(const GURL& secure_proxy_check_url, |
| 270 FetcherResponseCallback fetcher_callback); | 244 FetcherResponseCallback fetcher_callback); |
| 271 | 245 |
| 272 // Parses the secure proxy check responses and appropriately configures the | 246 // Parses the secure proxy check responses and appropriately configures the |
| 273 // Data Reduction Proxy rules. | 247 // Data Reduction Proxy rules. |
| 274 void HandleSecureProxyCheckResponse(const std::string& response, | 248 void HandleSecureProxyCheckResponse(const std::string& response, |
| 275 const net::URLRequestStatus& status, | 249 const net::URLRequestStatus& status, |
| 276 int http_response_code); | 250 int http_response_code); |
| 277 | 251 |
| 278 // Adds the default proxy bypass rules for the Data Reduction Proxy. | 252 // Adds the default proxy bypass rules for the Data Reduction Proxy. |
| 279 void AddDefaultProxyBypassRules(); | 253 void AddDefaultProxyBypassRules(); |
| 280 | 254 |
| 281 // Checks if all configured data reduction proxies are in the retry map. | 255 // 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 | 256 // 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 | 257 // 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 | 258 // 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 | 259 // 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 | 260 // bypassed data reduction proxies for the request scheme, returns false and |
| 287 // does not assign min_retry_delay. | 261 // does not assign min_retry_delay. |
| 288 bool AreProxiesBypassed( | 262 bool AreProxiesBypassed( |
| 289 const net::ProxyRetryInfoMap& retry_map, | 263 const net::ProxyRetryInfoMap& retry_map, |
| 290 const net::ProxyConfig::ProxyRules& proxy_rules, | 264 const net::ProxyConfig::ProxyRules& proxy_rules, |
| 291 bool is_https, | 265 bool is_https, |
| 292 base::TimeDelta* min_retry_delay) const; | 266 base::TimeDelta* min_retry_delay) const; |
| 293 | 267 |
| 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( | 268 virtual bool IsNetworkQualityProhibitivelySlow( |
| 311 const net::NetworkQualityEstimator* network_quality_estimator); | 269 const net::NetworkQualityEstimator* network_quality_estimator); |
| 312 | 270 |
| 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. | 271 // 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 | 272 // If the captive portal probe was blocked on the current network, disables |
| 328 // the use of secure proxies. | 273 // the use of secure proxies. |
| 329 void HandleCaptivePortal(); | 274 void HandleCaptivePortal(); |
| 330 | 275 |
| 331 // Returns true if the current network has captive portal. Virtualized | 276 // Returns true if the current network has captive portal. Virtualized |
| 332 // for testing. | 277 // for testing. |
| 333 virtual bool GetIsCaptivePortal() const; | 278 virtual bool GetIsCaptivePortal() const; |
| 334 | 279 |
| 335 // Fetches the warmup URL. | 280 // Fetches the warmup URL. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 362 | 307 |
| 363 // The caller must ensure that the |configurator_| outlives this instance. | 308 // The caller must ensure that the |configurator_| outlives this instance. |
| 364 DataReductionProxyConfigurator* configurator_; | 309 DataReductionProxyConfigurator* configurator_; |
| 365 | 310 |
| 366 // The caller must ensure that the |event_creator_| outlives this instance. | 311 // The caller must ensure that the |event_creator_| outlives this instance. |
| 367 DataReductionProxyEventCreator* event_creator_; | 312 DataReductionProxyEventCreator* event_creator_; |
| 368 | 313 |
| 369 // Enforce usage on the IO thread. | 314 // Enforce usage on the IO thread. |
| 370 base::ThreadChecker thread_checker_; | 315 base::ThreadChecker thread_checker_; |
| 371 | 316 |
| 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. | 317 // The current connection type. |
| 391 net::NetworkChangeNotifier::ConnectionType connection_type_; | 318 net::NetworkChangeNotifier::ConnectionType connection_type_; |
| 392 | 319 |
| 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 | 320 // 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. | 321 // true if Lo-Fi is disabled via flags or if the user implicitly opts out. |
| 400 bool lofi_off_; | 322 bool lofi_off_; |
| 401 | 323 |
| 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 | 324 // Set to true if the captive portal probe for the current network has been |
| 421 // blocked. | 325 // blocked. |
| 422 bool is_captive_portal_; | 326 bool is_captive_portal_; |
| 423 | 327 |
| 424 base::WeakPtrFactory<DataReductionProxyConfig> weak_factory_; | 328 base::WeakPtrFactory<DataReductionProxyConfig> weak_factory_; |
| 425 | 329 |
| 426 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyConfig); | 330 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyConfig); |
| 427 }; | 331 }; |
| 428 | 332 |
| 429 } // namespace data_reduction_proxy | 333 } // namespace data_reduction_proxy |
| 430 | 334 |
| 431 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_CON FIG_H_ | 335 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_CON FIG_H_ |
| OLD | NEW |