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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 RTTAndThroughputEstimatesObserver* observer) = 0; | 197 RTTAndThroughputEstimatesObserver* observer) = 0; |
198 | 198 |
199 protected: | 199 protected: |
200 NetworkQualityProvider() {} | 200 NetworkQualityProvider() {} |
201 | 201 |
202 private: | 202 private: |
203 DISALLOW_COPY_AND_ASSIGN(NetworkQualityProvider); | 203 DISALLOW_COPY_AND_ASSIGN(NetworkQualityProvider); |
204 }; | 204 }; |
205 | 205 |
206 // Creates a new NetworkQualityEstimator. | 206 // Creates a new NetworkQualityEstimator. |
207 // |variation_params| is the map containing all field trial parameters | 207 // |external_estimates_provider| may be NULL. |params| contains the |
208 // related to NetworkQualityEstimator field trial. | 208 // configuration parameters relevant to network quality estimator. The caller |
209 // |external_estimates_provider| may be NULL. The caller must guarantee that | 209 // must guarantee that |net_log| outlives |this|. |
210 // |net_log| outlives |this|. | |
211 NetworkQualityEstimator( | 210 NetworkQualityEstimator( |
212 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, | 211 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, |
213 const std::map<std::string, std::string>& variation_params, | 212 std::unique_ptr<NetworkQualityEstimatorParams> params, |
214 NetLog* net_log); | |
215 | |
216 // Construct a NetworkQualityEstimator instance allowing for test | |
217 // configuration. Registers for network type change notifications so estimates | |
218 // can be kept network specific. | |
219 // |external_estimates_provider| may be NULL. | |
220 // |variation_params| is the map containing all field trial parameters for the | |
221 // network quality estimator field trial. | |
222 // |use_local_host_requests_for_tests| should only be true when testing | |
223 // against local HTTP server and allows the requests to local host to be | |
224 // used for network quality estimation. | |
225 // |use_smaller_responses_for_tests| should only be true when testing. | |
226 // Allows the responses smaller than |kMinTransferSizeInBits| to be used for | |
227 // network quality estimation. The caller must guarantee that |net_log| | |
228 // outlives |this|. | |
229 NetworkQualityEstimator( | |
230 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, | |
231 const std::map<std::string, std::string>& variation_params, | |
232 bool use_local_host_requests_for_tests, | |
233 bool use_smaller_responses_for_tests, | |
234 NetLog* net_log); | 213 NetLog* net_log); |
235 | 214 |
236 ~NetworkQualityEstimator() override; | 215 ~NetworkQualityEstimator() override; |
237 | 216 |
238 // Returns the last computed effective type of the current connection. The | 217 // Returns the last computed effective type of the current connection. The |
239 // effective connection type is computed by the network quality estimator at | 218 // effective connection type is computed by the network quality estimator at |
240 // regular intervals and at certain events (e.g., connection change). | 219 // regular intervals and at certain events (e.g., connection change). |
241 // Virtualized for testing. | 220 // Virtualized for testing. |
242 virtual EffectiveConnectionType GetEffectiveConnectionType() const; | 221 virtual EffectiveConnectionType GetEffectiveConnectionType() const; |
243 | 222 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 observer); | 315 observer); |
337 | 316 |
338 // Called when the persistent prefs have been read. |read_prefs| contains the | 317 // Called when the persistent prefs have been read. |read_prefs| contains the |
339 // parsed prefs as a map between NetworkIDs and CachedNetworkQualities. | 318 // parsed prefs as a map between NetworkIDs and CachedNetworkQualities. |
340 void OnPrefsRead( | 319 void OnPrefsRead( |
341 const std::map<nqe::internal::NetworkID, | 320 const std::map<nqe::internal::NetworkID, |
342 nqe::internal::CachedNetworkQuality> read_prefs); | 321 nqe::internal::CachedNetworkQuality> read_prefs); |
343 | 322 |
344 protected: | 323 protected: |
345 // A protected constructor for testing that allows setting the value of | 324 // A protected constructor for testing that allows setting the value of |
346 // |add_default_platform_observations_|. | 325 // configuration params. |
| 326 // |use_local_host_requests_for_tests| should only be true when testing |
| 327 // against local HTTP server and allows the requests to local host to be |
| 328 // used for network quality estimation. |
| 329 // |use_smaller_responses_for_tests| should only be true when testing. |
| 330 // Allows the responses smaller than |kMinTransferSizeInBits| to be used for |
| 331 // network quality estimation. |
| 332 // |add_default_platform_observations_| should be false only if |this| should |
| 333 // not generate observations based on the platform and/or connection type. |
347 NetworkQualityEstimator( | 334 NetworkQualityEstimator( |
348 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, | 335 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, |
349 const std::map<std::string, std::string>& variation_params, | 336 std::unique_ptr<NetworkQualityEstimatorParams> params, |
350 bool use_local_host_requests_for_tests, | 337 bool use_local_host_requests_for_tests, |
351 bool use_smaller_responses_for_tests, | 338 bool use_smaller_responses_for_tests, |
352 bool add_default_platform_observations, | 339 bool add_default_platform_observations, |
353 const NetLogWithSource& net_log); | 340 const NetLogWithSource& net_log); |
354 | 341 |
355 // Different experimental statistic algorithms that can be used for computing | 342 // Different experimental statistic algorithms that can be used for computing |
356 // the predictions. | 343 // the predictions. |
357 enum Statistic { | 344 enum Statistic { |
358 STATISTIC_WEIGHTED_AVERAGE = 0, | 345 STATISTIC_WEIGHTED_AVERAGE = 0, |
359 STATISTIC_UNWEIGHTED_AVERAGE = 1, | 346 STATISTIC_UNWEIGHTED_AVERAGE = 1, |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 // May update the network quality of the current network if |network_id| | 631 // May update the network quality of the current network if |network_id| |
645 // matches the ID of the current network. |cached_network_quality| is the | 632 // matches the ID of the current network. |cached_network_quality| is the |
646 // cached network quality of the network with id |network_id|. | 633 // cached network quality of the network with id |network_id|. |
647 void MaybeUpdateNetworkQualityFromCache( | 634 void MaybeUpdateNetworkQualityFromCache( |
648 const nqe::internal::NetworkID& network_id, | 635 const nqe::internal::NetworkID& network_id, |
649 const nqe::internal::CachedNetworkQuality& cached_network_quality); | 636 const nqe::internal::CachedNetworkQuality& cached_network_quality); |
650 | 637 |
651 const char* GetNameForStatistic(int i) const; | 638 const char* GetNameForStatistic(int i) const; |
652 | 639 |
653 // Params to configure the network quality estimator. | 640 // Params to configure the network quality estimator. |
654 const nqe::internal::NetworkQualityEstimatorParams params_; | 641 const std::unique_ptr<NetworkQualityEstimatorParams> params_; |
655 | 642 |
656 // Determines if the requests to local host can be used in estimating the | 643 // Determines if the requests to local host can be used in estimating the |
657 // network quality. Set to true only for tests. | 644 // network quality. Set to true only for tests. |
658 bool use_localhost_requests_; | 645 bool use_localhost_requests_; |
659 | 646 |
660 // Determines if the responses smaller than |kMinTransferSizeInBytes| | 647 // Determines if the responses smaller than |kMinTransferSizeInBytes| |
661 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the | 648 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the |
662 // network quality. Set to true only for tests. | 649 // network quality. Set to true only for tests. |
663 bool use_small_responses_; | 650 bool use_small_responses_; |
664 | 651 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 disallowed_observation_sources_for_transport_; | 776 disallowed_observation_sources_for_transport_; |
790 | 777 |
791 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; | 778 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; |
792 | 779 |
793 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); | 780 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |
794 }; | 781 }; |
795 | 782 |
796 } // namespace net | 783 } // namespace net |
797 | 784 |
798 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ | 785 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ |
OLD | NEW |