| 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 NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ | 5 #ifndef NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ |
| 6 #define NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ | 6 #define NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 class URLRequest; | 45 class URLRequest; |
| 46 | 46 |
| 47 // NetworkQualityEstimator provides network quality estimates (quality of the | 47 // NetworkQualityEstimator provides network quality estimates (quality of the |
| 48 // full paths to all origins that have been connected to). | 48 // full paths to all origins that have been connected to). |
| 49 // The estimates are based on the observed organic traffic. | 49 // The estimates are based on the observed organic traffic. |
| 50 // A NetworkQualityEstimator instance is attached to URLRequestContexts and | 50 // A NetworkQualityEstimator instance is attached to URLRequestContexts and |
| 51 // observes the traffic of URLRequests spawned from the URLRequestContexts. | 51 // observes the traffic of URLRequests spawned from the URLRequestContexts. |
| 52 // A single instance of NQE can be attached to multiple URLRequestContexts, | 52 // A single instance of NQE can be attached to multiple URLRequestContexts, |
| 53 // thereby increasing the single NQE instance's accuracy by providing more | 53 // thereby increasing the single NQE instance's accuracy by providing more |
| 54 // observed traffic characteristics. | 54 // observed traffic characteristics. |
| 55 class NET_EXPORT_PRIVATE NetworkQualityEstimator | 55 class NET_EXPORT NetworkQualityEstimator |
| 56 : public NetworkChangeNotifier::ConnectionTypeObserver, | 56 : public NetworkChangeNotifier::ConnectionTypeObserver, |
| 57 public ExternalEstimateProvider::UpdatedEstimateDelegate { | 57 public ExternalEstimateProvider::UpdatedEstimateDelegate { |
| 58 public: | 58 public: |
| 59 // EffectiveConnectionType is the connection type whose typical performance is | 59 // EffectiveConnectionType is the connection type whose typical performance is |
| 60 // most similar to the measured performance of the network in use. In many | 60 // most similar to the measured performance of the network in use. In many |
| 61 // cases, the "effective" connection type and the actual type of connection in | 61 // cases, the "effective" connection type and the actual type of connection in |
| 62 // use are the same, but often a network connection performs significantly | 62 // use are the same, but often a network connection performs significantly |
| 63 // different, usually worse, from its expected capabilities. | 63 // different, usually worse, from its expected capabilities. |
| 64 // EffectiveConnectionType of a network is independent of if the current | 64 // EffectiveConnectionType of a network is independent of if the current |
| 65 // connection is metered or not. For example, an unmetered slow connection may | 65 // connection is metered or not. For example, an unmetered slow connection may |
| 66 // have EFFECTIVE_CONNECTION_TYPE_SLOW_2G as its effective connection type. | 66 // have EFFECTIVE_CONNECTION_TYPE_SLOW_2G as its effective connection type. |
| 67 enum EffectiveConnectionType { | 67 enum EffectiveConnectionType { |
| 68 // The connection types should be in increasing order of quality. | 68 // The connection types should be in increasing order of quality. |
| 69 EFFECTIVE_CONNECTION_TYPE_UNKNOWN = 0, | 69 EFFECTIVE_CONNECTION_TYPE_UNKNOWN = 0, |
| 70 EFFECTIVE_CONNECTION_TYPE_OFFLINE, | 70 EFFECTIVE_CONNECTION_TYPE_OFFLINE, |
| 71 EFFECTIVE_CONNECTION_TYPE_SLOW_2G, | 71 EFFECTIVE_CONNECTION_TYPE_SLOW_2G, |
| 72 EFFECTIVE_CONNECTION_TYPE_2G, | 72 EFFECTIVE_CONNECTION_TYPE_2G, |
| 73 EFFECTIVE_CONNECTION_TYPE_3G, | 73 EFFECTIVE_CONNECTION_TYPE_3G, |
| 74 EFFECTIVE_CONNECTION_TYPE_4G, | 74 EFFECTIVE_CONNECTION_TYPE_4G, |
| 75 EFFECTIVE_CONNECTION_TYPE_BROADBAND, | 75 EFFECTIVE_CONNECTION_TYPE_BROADBAND, |
| 76 EFFECTIVE_CONNECTION_TYPE_LAST, | 76 EFFECTIVE_CONNECTION_TYPE_LAST, |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 // Observes changes in effective connection type. | 79 // Observes changes in effective connection type. |
| 80 class NET_EXPORT_PRIVATE EffectiveConnectionTypeObserver { | 80 class NET_EXPORT EffectiveConnectionTypeObserver { |
| 81 public: | 81 public: |
| 82 // Notifies the observer of a change in the effective connection type. | 82 // Notifies the observer of a change in the effective connection type. |
| 83 // NetworkQualityEstimator computes the effective connection type once in | 83 // NetworkQualityEstimator computes the effective connection type once in |
| 84 // every interval of duration | 84 // every interval of duration |
| 85 // |effective_connection_type_recomputation_interval_|. Additionally, when | 85 // |effective_connection_type_recomputation_interval_|. Additionally, when |
| 86 // there is a change in the connection type of the device, then the | 86 // there is a change in the connection type of the device, then the |
| 87 // effective connection type is immediately recomputed. The observer must | 87 // effective connection type is immediately recomputed. The observer must |
| 88 // register and unregister itself on the IO thread. All the observers would | 88 // register and unregister itself on the IO thread. All the observers would |
| 89 // be notified on the IO thread. | 89 // be notified on the IO thread. |
| 90 // | 90 // |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 // |use_localhost_requests| should only be true when testing against local | 230 // |use_localhost_requests| should only be true when testing against local |
| 231 // HTTP server and allows the requests to local host to be used for network | 231 // HTTP server and allows the requests to local host to be used for network |
| 232 // quality estimation. | 232 // quality estimation. |
| 233 void SetUseLocalHostRequestsForTesting(bool use_localhost_requests); | 233 void SetUseLocalHostRequestsForTesting(bool use_localhost_requests); |
| 234 | 234 |
| 235 // |use_smaller_responses_for_tests| should only be true when testing. | 235 // |use_smaller_responses_for_tests| should only be true when testing. |
| 236 // Allows the responses smaller than |kMinTransferSizeInBits| to be used for | 236 // Allows the responses smaller than |kMinTransferSizeInBits| to be used for |
| 237 // network quality estimation. | 237 // network quality estimation. |
| 238 void SetUseSmallResponsesForTesting(bool use_small_responses); | 238 void SetUseSmallResponsesForTesting(bool use_small_responses); |
| 239 | 239 |
| 240 base::WeakPtr<NetworkQualityEstimator> GetWeakPtr() { |
| 241 return weak_ptr_factory_.GetWeakPtr(); |
| 242 } |
| 243 |
| 240 protected: | 244 protected: |
| 241 // NetworkID is used to uniquely identify a network. | 245 // NetworkID is used to uniquely identify a network. |
| 242 // For the purpose of network quality estimation and caching, a network is | 246 // For the purpose of network quality estimation and caching, a network is |
| 243 // uniquely identified by a combination of |type| and | 247 // uniquely identified by a combination of |type| and |
| 244 // |id|. This approach is unable to distinguish networks with | 248 // |id|. This approach is unable to distinguish networks with |
| 245 // same name (e.g., different Wi-Fi networks with same SSID). | 249 // same name (e.g., different Wi-Fi networks with same SSID). |
| 246 // This is a protected member to expose it to tests. | 250 // This is a protected member to expose it to tests. |
| 247 struct NET_EXPORT_PRIVATE NetworkID { | 251 struct NET_EXPORT_PRIVATE NetworkID { |
| 248 NetworkID(NetworkChangeNotifier::ConnectionType type, const std::string& id) | 252 NetworkID(NetworkChangeNotifier::ConnectionType type, const std::string& id) |
| 249 : type(type), id(id) {} | 253 : type(type), id(id) {} |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 base::ThreadChecker thread_checker_; | 613 base::ThreadChecker thread_checker_; |
| 610 | 614 |
| 611 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; | 615 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; |
| 612 | 616 |
| 613 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); | 617 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |
| 614 }; | 618 }; |
| 615 | 619 |
| 616 } // namespace net | 620 } // namespace net |
| 617 | 621 |
| 618 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ | 622 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ |
| OLD | NEW |