Chromium Code Reviews| Index: components/metrics/net/network_metrics_provider.h |
| diff --git a/components/metrics/net/network_metrics_provider.h b/components/metrics/net/network_metrics_provider.h |
| index da47689d2746187f5e7ba4e874a07c867327139b..98da9a606f3cb11754294d7923fa86c21f635373 100644 |
| --- a/components/metrics/net/network_metrics_provider.h |
| +++ b/components/metrics/net/network_metrics_provider.h |
| @@ -10,11 +10,17 @@ |
| #include "base/macros.h" |
| #include "base/memory/weak_ptr.h" |
| #include "base/metrics/histogram_base.h" |
| +#include "base/threading/thread_checker.h" |
| #include "components/metrics/metrics_provider.h" |
| #include "components/metrics/net/wifi_access_point_info_provider.h" |
| #include "components/metrics/proto/system_profile.pb.h" |
| #include "net/base/network_change_notifier.h" |
| #include "net/base/network_interfaces.h" |
| +#include "net/nqe/effective_connection_type.h" |
| + |
| +namespace net { |
| +class NetworkQualityEstimator; |
| +} |
| namespace metrics { |
| @@ -24,12 +30,43 @@ class NetworkMetricsProvider |
| : public MetricsProvider, |
| public net::NetworkChangeNotifier::ConnectionTypeObserver { |
| public: |
| + // Class that provides |this| with the network quality estimator. |
| + class NetworkQualityEstimatorProvider { |
| + public: |
| + virtual ~NetworkQualityEstimatorProvider() {} |
| + |
| + // Synchronously provides network quality estimator by calling |callback|. |
| + // |callback| is run synchronously on the same task runner on which |
| + // ProvideEstimator() was called. |
| + virtual void ProvideEstimator( |
| + const base::Callback<void(net::NetworkQualityEstimator*)>& |
| + callback) = 0; |
| + |
| + protected: |
| + NetworkQualityEstimatorProvider() {} |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimatorProvider); |
| + }; |
| + |
| // Creates a NetworkMetricsProvider, where |io_task_runner| is used to post |
| - // network info collection tasks. |
| - explicit NetworkMetricsProvider(base::TaskRunner* io_task_runner); |
| + // network info collection tasks. |network_quality_estimator_provider| |
| + // should be used on |network_quality_task_runner|, and should be set |
| + // if it is useful to attach the quality of the network to the metrics report. |
| + NetworkMetricsProvider(const scoped_refptr<base::SequencedTaskRunner>& |
| + network_quality_task_runner, |
|
Alexei Svitkine (slow)
2017/01/04 15:18:59
Can the task runner ctor param be avoided and just
tbansal1
2017/01/04 20:47:54
Good point. Done.
|
| + std::unique_ptr<NetworkQualityEstimatorProvider> |
| + network_quality_estimator_provider, |
| + base::TaskRunner* io_task_runner); |
| + |
| ~NetworkMetricsProvider() override; |
| private: |
| + FRIEND_TEST_ALL_PREFIXES(NetworkMetricsProviderTest, EffectiveConnectionType); |
| + |
| + // Listens to the changes in the effective conection type. |
| + class EffectiveConnectionTypeObserver; |
| + |
| // MetricsProvider: |
| void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override; |
| void ProvideSystemProfileMetrics(SystemProfileProto* system_profile) override; |
| @@ -41,6 +78,8 @@ class NetworkMetricsProvider |
| SystemProfileProto::Network::ConnectionType GetConnectionType() const; |
| SystemProfileProto::Network::WifiPHYLayerProtocol GetWifiPHYLayerProtocol() |
| const; |
| + SystemProfileProto::Network::EffectiveConnectionType |
| + GetEffectiveConnectionType() const; |
| // Posts a call to net::GetWifiPHYLayerProtocol on the blocking pool. |
| void ProbeWifiPHYLayerProtocol(); |
| @@ -57,6 +96,10 @@ class NetworkMetricsProvider |
| // Logs metrics that are functions of other metrics being uploaded. |
| void LogAggregatedMetrics(); |
| + // Notifies |this| that the effective connection type of the current network |
| + // has changed to |type|. |
| + void OnEffectiveConnectionTypeChanged(net::EffectiveConnectionType type); |
| + |
| // Task runner used for blocking file I/O. |
| base::TaskRunner* io_task_runner_; |
| @@ -79,6 +122,28 @@ class NetworkMetricsProvider |
| base::HistogramBase::Count total_aborts_; |
| base::HistogramBase::Count total_codes_; |
| + // Provides the network quality estimator. May be null. |
| + std::unique_ptr<NetworkQualityEstimatorProvider> |
| + network_quality_estimator_provider_; |
| + |
| + // Listens to the changes in the effective connection type. Initialized and |
| + // destroyed using |network_quality_task_runner_|. May be null. |
| + std::unique_ptr<EffectiveConnectionTypeObserver> |
| + effective_connection_type_observer_; |
| + |
| + // Task runner using which |effective_connection_type_observer_| is |
| + // initialized and destroyed. May be null. |
| + scoped_refptr<base::SequencedTaskRunner> network_quality_task_runner_; |
| + |
| + // Last known effective connection type. |
| + net::EffectiveConnectionType effective_connection_type_; |
| + |
| + // True if |effective_connection_type_| changed during the lifetime of the |
| + // log. |
| + bool effective_connection_type_is_ambiguous_; |
| + |
| + base::ThreadChecker thread_checker_; |
| + |
| base::WeakPtrFactory<NetworkMetricsProvider> weak_ptr_factory_; |
| DISALLOW_COPY_AND_ASSIGN(NetworkMetricsProvider); |