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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 97 |
98 protected: | 98 protected: |
99 ThroughputObserver() {} | 99 ThroughputObserver() {} |
100 virtual ~ThroughputObserver() {} | 100 virtual ~ThroughputObserver() {} |
101 | 101 |
102 private: | 102 private: |
103 DISALLOW_COPY_AND_ASSIGN(ThroughputObserver); | 103 DISALLOW_COPY_AND_ASSIGN(ThroughputObserver); |
104 }; | 104 }; |
105 | 105 |
106 // Creates a new NetworkQualityEstimator. | 106 // Creates a new NetworkQualityEstimator. |
107 // |variation_params| is the map containing all field trial parameters | 107 // |external_estimates_provider| may be NULL. |params| contains the |
108 // related to NetworkQualityEstimator field trial. | 108 // configuration parameters relevant to network quality estimator. The caller |
109 // |external_estimates_provider| may be NULL. The caller must guarantee that | 109 // must guarantee that |net_log| outlives |this|. |
110 // |net_log| outlives |this|. | |
111 NetworkQualityEstimator( | 110 NetworkQualityEstimator( |
112 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, | 111 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, |
113 const std::map<std::string, std::string>& variation_params, | 112 std::unique_ptr<NetworkQualityEstimatorParams> params, |
114 NetLog* net_log); | |
115 | |
116 // Construct a NetworkQualityEstimator instance allowing for test | |
117 // configuration. Registers for network type change notifications so estimates | |
118 // can be kept network specific. | |
119 // |external_estimates_provider| may be NULL. | |
120 // |variation_params| is the map containing all field trial parameters for the | |
121 // network quality estimator field trial. | |
122 // |use_local_host_requests_for_tests| should only be true when testing | |
123 // against local HTTP server and allows the requests to local host to be | |
124 // used for network quality estimation. | |
125 // |use_smaller_responses_for_tests| should only be true when testing. | |
126 // Allows the responses smaller than |kMinTransferSizeInBits| to be used for | |
127 // network quality estimation. The caller must guarantee that |net_log| | |
128 // outlives |this|. | |
129 NetworkQualityEstimator( | |
130 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, | |
131 const std::map<std::string, std::string>& variation_params, | |
132 bool use_local_host_requests_for_tests, | |
133 bool use_smaller_responses_for_tests, | |
134 NetLog* net_log); | 113 NetLog* net_log); |
135 | 114 |
136 ~NetworkQualityEstimator() override; | 115 ~NetworkQualityEstimator() override; |
137 | 116 |
138 // Returns the effective type of the current connection based on only the | 117 // Returns the effective type of the current connection based on only the |
139 // samples observed after |start_time|. This should only be used for | 118 // samples observed after |start_time|. This should only be used for |
140 // recording the metrics. Virtualized for testing. | 119 // recording the metrics. Virtualized for testing. |
141 virtual EffectiveConnectionType GetRecentEffectiveConnectionType( | 120 virtual EffectiveConnectionType GetRecentEffectiveConnectionType( |
142 const base::TimeTicks& start_time) const; | 121 const base::TimeTicks& start_time) const; |
143 | 122 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 observer); | 202 observer); |
224 | 203 |
225 // Called when the persistent prefs have been read. |read_prefs| contains the | 204 // Called when the persistent prefs have been read. |read_prefs| contains the |
226 // parsed prefs as a map between NetworkIDs and CachedNetworkQualities. | 205 // parsed prefs as a map between NetworkIDs and CachedNetworkQualities. |
227 void OnPrefsRead( | 206 void OnPrefsRead( |
228 const std::map<nqe::internal::NetworkID, | 207 const std::map<nqe::internal::NetworkID, |
229 nqe::internal::CachedNetworkQuality> read_prefs); | 208 nqe::internal::CachedNetworkQuality> read_prefs); |
230 | 209 |
231 protected: | 210 protected: |
232 // A protected constructor for testing that allows setting the value of | 211 // A protected constructor for testing that allows setting the value of |
233 // |add_default_platform_observations_|. | 212 // configuration params. |
| 213 // |use_local_host_requests_for_tests| should only be true when testing |
| 214 // against local HTTP server and allows the requests to local host to be |
| 215 // used for network quality estimation. |
| 216 // |use_smaller_responses_for_tests| should only be true when testing. |
| 217 // Allows the responses smaller than |kMinTransferSizeInBits| to be used for |
| 218 // network quality estimation. |
| 219 // |add_default_platform_observations_| should be false only if |this| should |
| 220 // not generate observations based on the platform and/or connection type. |
234 NetworkQualityEstimator( | 221 NetworkQualityEstimator( |
235 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, | 222 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, |
236 const std::map<std::string, std::string>& variation_params, | 223 std::unique_ptr<NetworkQualityEstimatorParams> params, |
237 bool use_local_host_requests_for_tests, | 224 bool use_local_host_requests_for_tests, |
238 bool use_smaller_responses_for_tests, | 225 bool use_smaller_responses_for_tests, |
239 bool add_default_platform_observations, | 226 bool add_default_platform_observations, |
240 const NetLogWithSource& net_log); | 227 const NetLogWithSource& net_log); |
241 | 228 |
242 // Different experimental statistic algorithms that can be used for computing | 229 // Different experimental statistic algorithms that can be used for computing |
243 // the predictions. | 230 // the predictions. |
244 enum Statistic { | 231 enum Statistic { |
245 STATISTIC_WEIGHTED_AVERAGE = 0, | 232 STATISTIC_WEIGHTED_AVERAGE = 0, |
246 STATISTIC_UNWEIGHTED_AVERAGE = 1, | 233 STATISTIC_UNWEIGHTED_AVERAGE = 1, |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 // May update the network quality of the current network if |network_id| | 522 // May update the network quality of the current network if |network_id| |
536 // matches the ID of the current network. |cached_network_quality| is the | 523 // matches the ID of the current network. |cached_network_quality| is the |
537 // cached network quality of the network with id |network_id|. | 524 // cached network quality of the network with id |network_id|. |
538 void MaybeUpdateNetworkQualityFromCache( | 525 void MaybeUpdateNetworkQualityFromCache( |
539 const nqe::internal::NetworkID& network_id, | 526 const nqe::internal::NetworkID& network_id, |
540 const nqe::internal::CachedNetworkQuality& cached_network_quality); | 527 const nqe::internal::CachedNetworkQuality& cached_network_quality); |
541 | 528 |
542 const char* GetNameForStatistic(int i) const; | 529 const char* GetNameForStatistic(int i) const; |
543 | 530 |
544 // Params to configure the network quality estimator. | 531 // Params to configure the network quality estimator. |
545 const nqe::internal::NetworkQualityEstimatorParams params_; | 532 const std::unique_ptr<NetworkQualityEstimatorParams> params_; |
546 | 533 |
547 // Determines if the requests to local host can be used in estimating the | 534 // Determines if the requests to local host can be used in estimating the |
548 // network quality. Set to true only for tests. | 535 // network quality. Set to true only for tests. |
549 bool use_localhost_requests_; | 536 bool use_localhost_requests_; |
550 | 537 |
551 // Determines if the responses smaller than |kMinTransferSizeInBytes| | 538 // Determines if the responses smaller than |kMinTransferSizeInBytes| |
552 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the | 539 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the |
553 // network quality. Set to true only for tests. | 540 // network quality. Set to true only for tests. |
554 bool use_small_responses_; | 541 bool use_small_responses_; |
555 | 542 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 disallowed_observation_sources_for_transport_; | 663 disallowed_observation_sources_for_transport_; |
677 | 664 |
678 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; | 665 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; |
679 | 666 |
680 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); | 667 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |
681 }; | 668 }; |
682 | 669 |
683 } // namespace net | 670 } // namespace net |
684 | 671 |
685 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ | 672 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ |
OLD | NEW |