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..5bbad86b60316b3bc8af9bcf1583791a8672d2c7 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,48 @@ 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; |
|
Alexei Svitkine (slow)
2017/01/04 20:54:21
Can it simply return the NetworkQualityEstimator*
tbansal1
2017/01/04 21:24:19
Done.
|
| + |
| + // Returns the task runner on which |this| should be used and destroyed. |
| + virtual scoped_refptr<base::SequencedTaskRunner> GetTaskRunner() = 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); |
| + |
| + // Creates a NetworkMetricsProvider, where |io_task_runner| is used to post |
| + // network info collection tasks. |network_quality_estimator_provider| |
| + // should be set if it is useful to attach the quality of the network to the |
| + // metrics report. |
| + NetworkMetricsProvider(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 +83,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 +101,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 +127,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); |