| 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> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
| 20 #include "base/threading/thread_checker.h" | 20 #include "base/threading/thread_checker.h" |
| 21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "net/base/net_export.h" | 22 #include "net/base/net_export.h" |
| 23 #include "net/base/network_change_notifier.h" | 23 #include "net/base/network_change_notifier.h" |
| 24 #include "net/log/net_log_with_source.h" |
| 24 #include "net/nqe/cached_network_quality.h" | 25 #include "net/nqe/cached_network_quality.h" |
| 25 #include "net/nqe/effective_connection_type.h" | 26 #include "net/nqe/effective_connection_type.h" |
| 26 #include "net/nqe/external_estimate_provider.h" | 27 #include "net/nqe/external_estimate_provider.h" |
| 27 #include "net/nqe/network_id.h" | 28 #include "net/nqe/network_id.h" |
| 28 #include "net/nqe/network_quality.h" | 29 #include "net/nqe/network_quality.h" |
| 29 #include "net/nqe/network_quality_observation.h" | 30 #include "net/nqe/network_quality_observation.h" |
| 30 #include "net/nqe/network_quality_observation_source.h" | 31 #include "net/nqe/network_quality_observation_source.h" |
| 31 #include "net/nqe/network_quality_store.h" | 32 #include "net/nqe/network_quality_store.h" |
| 32 #include "net/nqe/observation_buffer.h" | 33 #include "net/nqe/observation_buffer.h" |
| 33 #include "net/socket/socket_performance_watcher_factory.h" | 34 #include "net/socket/socket_performance_watcher_factory.h" |
| 34 | 35 |
| 35 namespace base { | 36 namespace base { |
| 36 class TickClock; | 37 class TickClock; |
| 37 } // namespace base | 38 } // namespace base |
| 38 | 39 |
| 39 namespace net { | 40 namespace net { |
| 40 | 41 |
| 42 class NetLog; |
| 43 |
| 41 namespace nqe { | 44 namespace nqe { |
| 42 namespace internal { | 45 namespace internal { |
| 43 class ThroughputAnalyzer; | 46 class ThroughputAnalyzer; |
| 44 } | 47 } |
| 45 } | 48 } |
| 46 | 49 |
| 47 class URLRequest; | 50 class URLRequest; |
| 48 | 51 |
| 49 // NetworkQualityEstimator provides network quality estimates (quality of the | 52 // NetworkQualityEstimator provides network quality estimates (quality of the |
| 50 // full paths to all origins that have been connected to). | 53 // full paths to all origins that have been connected to). |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 protected: | 172 protected: |
| 170 NetworkQualityProvider() {} | 173 NetworkQualityProvider() {} |
| 171 | 174 |
| 172 private: | 175 private: |
| 173 DISALLOW_COPY_AND_ASSIGN(NetworkQualityProvider); | 176 DISALLOW_COPY_AND_ASSIGN(NetworkQualityProvider); |
| 174 }; | 177 }; |
| 175 | 178 |
| 176 // Creates a new NetworkQualityEstimator. | 179 // Creates a new NetworkQualityEstimator. |
| 177 // |variation_params| is the map containing all field trial parameters | 180 // |variation_params| is the map containing all field trial parameters |
| 178 // related to NetworkQualityEstimator field trial. | 181 // related to NetworkQualityEstimator field trial. |
| 179 // |external_estimates_provider| may be NULL. | 182 // |external_estimates_provider| may be NULL. The caller must guarantee that |
| 183 // |net_log| outlives |this|. |
| 180 NetworkQualityEstimator( | 184 NetworkQualityEstimator( |
| 181 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, | 185 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, |
| 182 const std::map<std::string, std::string>& variation_params); | 186 const std::map<std::string, std::string>& variation_params, |
| 187 NetLog* net_log); |
| 183 | 188 |
| 184 // Construct a NetworkQualityEstimator instance allowing for test | 189 // Construct a NetworkQualityEstimator instance allowing for test |
| 185 // configuration. Registers for network type change notifications so estimates | 190 // configuration. Registers for network type change notifications so estimates |
| 186 // can be kept network specific. | 191 // can be kept network specific. |
| 187 // |external_estimates_provider| may be NULL. | 192 // |external_estimates_provider| may be NULL. |
| 188 // |variation_params| is the map containing all field trial parameters for the | 193 // |variation_params| is the map containing all field trial parameters for the |
| 189 // network quality estimator field trial. | 194 // network quality estimator field trial. |
| 190 // |use_local_host_requests_for_tests| should only be true when testing | 195 // |use_local_host_requests_for_tests| should only be true when testing |
| 191 // against local HTTP server and allows the requests to local host to be | 196 // against local HTTP server and allows the requests to local host to be |
| 192 // used for network quality estimation. | 197 // used for network quality estimation. |
| 193 // |use_smaller_responses_for_tests| should only be true when testing. | 198 // |use_smaller_responses_for_tests| should only be true when testing. |
| 194 // Allows the responses smaller than |kMinTransferSizeInBits| to be used for | 199 // Allows the responses smaller than |kMinTransferSizeInBits| to be used for |
| 195 // network quality estimation. | 200 // network quality estimation. The caller must guarantee that |net_log| |
| 201 // outlives |this|. |
| 196 NetworkQualityEstimator( | 202 NetworkQualityEstimator( |
| 197 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, | 203 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, |
| 198 const std::map<std::string, std::string>& variation_params, | 204 const std::map<std::string, std::string>& variation_params, |
| 199 bool use_local_host_requests_for_tests, | 205 bool use_local_host_requests_for_tests, |
| 200 bool use_smaller_responses_for_tests); | 206 bool use_smaller_responses_for_tests, |
| 207 NetLog* net_log); |
| 201 | 208 |
| 202 ~NetworkQualityEstimator() override; | 209 ~NetworkQualityEstimator() override; |
| 203 | 210 |
| 204 // Returns the last computed effective type of the current connection. The | 211 // Returns the last computed effective type of the current connection. The |
| 205 // effective connection type is computed by the network quality estimator at | 212 // effective connection type is computed by the network quality estimator at |
| 206 // regular intervals and at certain events (e.g., connection change). | 213 // regular intervals and at certain events (e.g., connection change). |
| 207 // Virtualized for testing. | 214 // Virtualized for testing. |
| 208 virtual EffectiveConnectionType GetEffectiveConnectionType() const; | 215 virtual EffectiveConnectionType GetEffectiveConnectionType() const; |
| 209 | 216 |
| 210 // Returns the effective type of the current connection based on only the | 217 // Returns the effective type of the current connection based on only the |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 nqe::internal::CachedNetworkQuality> read_prefs); | 310 nqe::internal::CachedNetworkQuality> read_prefs); |
| 304 | 311 |
| 305 protected: | 312 protected: |
| 306 // A protected constructor for testing that allows setting the value of | 313 // A protected constructor for testing that allows setting the value of |
| 307 // |add_default_platform_observations_|. | 314 // |add_default_platform_observations_|. |
| 308 NetworkQualityEstimator( | 315 NetworkQualityEstimator( |
| 309 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, | 316 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, |
| 310 const std::map<std::string, std::string>& variation_params, | 317 const std::map<std::string, std::string>& variation_params, |
| 311 bool use_local_host_requests_for_tests, | 318 bool use_local_host_requests_for_tests, |
| 312 bool use_smaller_responses_for_tests, | 319 bool use_smaller_responses_for_tests, |
| 313 bool add_default_platform_observations); | 320 bool add_default_platform_observations, |
| 321 const NetLogWithSource& net_log); |
| 314 | 322 |
| 315 // NetworkChangeNotifier::ConnectionTypeObserver implementation: | 323 // NetworkChangeNotifier::ConnectionTypeObserver implementation: |
| 316 void OnConnectionTypeChanged( | 324 void OnConnectionTypeChanged( |
| 317 NetworkChangeNotifier::ConnectionType type) override; | 325 NetworkChangeNotifier::ConnectionType type) override; |
| 318 | 326 |
| 319 // ExternalEstimateProvider::UpdatedEstimateObserver implementation. | 327 // ExternalEstimateProvider::UpdatedEstimateObserver implementation. |
| 320 void OnUpdatedEstimateAvailable(const base::TimeDelta& rtt, | 328 void OnUpdatedEstimateAvailable(const base::TimeDelta& rtt, |
| 321 int32_t downstream_throughput_kbps, | 329 int32_t downstream_throughput_kbps, |
| 322 int32_t upstream_throughput_kbps) override; | 330 int32_t upstream_throughput_kbps) override; |
| 323 | 331 |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 std::unique_ptr<nqe::internal::NetworkQualityStore> network_quality_store_; | 756 std::unique_ptr<nqe::internal::NetworkQualityStore> network_quality_store_; |
| 749 | 757 |
| 750 // True if effective connection type value has been forced via variation | 758 // True if effective connection type value has been forced via variation |
| 751 // parameters. If set to true, GetEffectiveConnectionType() will always return | 759 // parameters. If set to true, GetEffectiveConnectionType() will always return |
| 752 // |forced_effective_connection_type_|. | 760 // |forced_effective_connection_type_|. |
| 753 const bool forced_effective_connection_type_set_; | 761 const bool forced_effective_connection_type_set_; |
| 754 const EffectiveConnectionType forced_effective_connection_type_; | 762 const EffectiveConnectionType forced_effective_connection_type_; |
| 755 | 763 |
| 756 base::ThreadChecker thread_checker_; | 764 base::ThreadChecker thread_checker_; |
| 757 | 765 |
| 766 NetLogWithSource net_log_; |
| 767 |
| 758 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; | 768 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; |
| 759 | 769 |
| 760 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); | 770 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); |
| 761 }; | 771 }; |
| 762 | 772 |
| 763 } // namespace net | 773 } // namespace net |
| 764 | 774 |
| 765 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ | 775 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ |
| OLD | NEW |