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 // Prevents updates to EffectiveConnectionTypeObservers aside from calls from | |
241 // ReportEffectiveConnectionTypeForTesting. | |
242 void StopReportingEffectiveConnectionTypeForTesting(); | |
tbansal1
2016/07/20 03:32:36
I do not think that this method is necessary. Repo
RyanSturm
2016/07/20 16:36:46
This will definitely be required later; I'll leave
tbansal1
2016/07/20 17:14:18
Acknowledged.
| |
243 | |
244 // Reports |effective_connection_type| to all | |
245 // EffectiveConnectionTypeObservers. | |
246 void ReportEffectiveConnectionTypeForTesting( | |
247 EffectiveConnectionType effective_connection_type); | |
248 | |
240 protected: | 249 protected: |
241 // NetworkID is used to uniquely identify a network. | 250 // NetworkID is used to uniquely identify a network. |
242 // For the purpose of network quality estimation and caching, a network is | 251 // For the purpose of network quality estimation and caching, a network is |
243 // uniquely identified by a combination of |type| and | 252 // uniquely identified by a combination of |type| and |
244 // |id|. This approach is unable to distinguish networks with | 253 // |id|. This approach is unable to distinguish networks with |
245 // same name (e.g., different Wi-Fi networks with same SSID). | 254 // same name (e.g., different Wi-Fi networks with same SSID). |
246 // This is a protected member to expose it to tests. | 255 // This is a protected member to expose it to tests. |
247 struct NET_EXPORT_PRIVATE NetworkID { | 256 struct NET_EXPORT_PRIVATE NetworkID { |
248 NetworkID(NetworkChangeNotifier::ConnectionType type, const std::string& id) | 257 NetworkID(NetworkChangeNotifier::ConnectionType type, const std::string& id) |
249 : type(type), id(id) {} | 258 : type(type), id(id) {} |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
635 // events. It is also updated every time there is network traffic (provided | 644 // events. It is also updated every time there is network traffic (provided |
636 // the last computation was more than | 645 // the last computation was more than |
637 // |effective_connection_type_recomputation_interval_| ago). | 646 // |effective_connection_type_recomputation_interval_| ago). |
638 EffectiveConnectionType effective_connection_type_; | 647 EffectiveConnectionType effective_connection_type_; |
639 | 648 |
640 // Minimum and Maximum signal strength (in dbM) observed since last connection | 649 // Minimum and Maximum signal strength (in dbM) observed since last connection |
641 // change. Updated on connection change and main frame requests. | 650 // change. Updated on connection change and main frame requests. |
642 int32_t min_signal_strength_since_connection_change_; | 651 int32_t min_signal_strength_since_connection_change_; |
643 int32_t max_signal_strength_since_connection_change_; | 652 int32_t max_signal_strength_since_connection_change_; |
644 | 653 |
654 // When true, no updates to EffectiveConnectionTypeObservers will occur aside | |
655 // from calls from ReportEffectiveConnectionTypeForTesting. | |
656 bool stop_reporting_effective_connection_type_; | |
657 | |
645 base::ThreadChecker thread_checker_; | 658 base::ThreadChecker thread_checker_; |
646 | 659 |
647 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; | 660 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; |
648 | 661 |
649 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); | 662 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |
650 }; | 663 }; |
651 | 664 |
652 } // namespace net | 665 } // namespace net |
653 | 666 |
654 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ | 667 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ |
OLD | NEW |