Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_ | 5 #ifndef COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_ |
| 6 #define COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_ | 6 #define COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/metrics/histogram_base.h" | 12 #include "base/metrics/histogram_base.h" |
| 13 #include "base/threading/thread_checker.h" | |
| 13 #include "components/metrics/metrics_provider.h" | 14 #include "components/metrics/metrics_provider.h" |
| 14 #include "components/metrics/net/wifi_access_point_info_provider.h" | 15 #include "components/metrics/net/wifi_access_point_info_provider.h" |
| 15 #include "components/metrics/proto/system_profile.pb.h" | 16 #include "components/metrics/proto/system_profile.pb.h" |
| 16 #include "net/base/network_change_notifier.h" | 17 #include "net/base/network_change_notifier.h" |
| 17 #include "net/base/network_interfaces.h" | 18 #include "net/base/network_interfaces.h" |
| 19 #include "net/nqe/effective_connection_type.h" | |
| 20 | |
| 21 namespace net { | |
| 22 class NetworkQualityEstimator; | |
| 23 } | |
| 18 | 24 |
| 19 namespace metrics { | 25 namespace metrics { |
| 20 | 26 |
| 21 // Registers as observer with net::NetworkChangeNotifier and keeps track of | 27 // Registers as observer with net::NetworkChangeNotifier and keeps track of |
| 22 // the network environment. | 28 // the network environment. |
| 23 class NetworkMetricsProvider | 29 class NetworkMetricsProvider |
| 24 : public MetricsProvider, | 30 : public MetricsProvider, |
| 25 public net::NetworkChangeNotifier::ConnectionTypeObserver { | 31 public net::NetworkChangeNotifier::ConnectionTypeObserver { |
| 26 public: | 32 public: |
| 33 // Class that provides |this| with the network quality estimator. | |
| 34 class NetworkQualityEstimatorProvider { | |
| 35 public: | |
| 36 virtual ~NetworkQualityEstimatorProvider() {} | |
| 37 | |
| 38 // Synchronously provides network quality estimator by calling |callback|. | |
| 39 // |callback| is run synchronously on the same task runner on which | |
| 40 // ProvideEstimator() was called. | |
| 41 virtual void ProvideEstimator( | |
| 42 const base::Callback<void(net::NetworkQualityEstimator*)>& | |
| 43 callback) = 0; | |
| 44 | |
| 45 protected: | |
| 46 NetworkQualityEstimatorProvider() {} | |
| 47 | |
| 48 private: | |
| 49 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimatorProvider); | |
| 50 }; | |
| 51 | |
| 27 // Creates a NetworkMetricsProvider, where |io_task_runner| is used to post | 52 // Creates a NetworkMetricsProvider, where |io_task_runner| is used to post |
| 28 // network info collection tasks. | 53 // network info collection tasks. |network_quality_estimator_provider| |
| 29 explicit NetworkMetricsProvider(base::TaskRunner* io_task_runner); | 54 // should be used on |network_quality_task_runner|, and should be set |
| 55 // if it is useful to attach the quality of the network to the metrics report. | |
| 56 NetworkMetricsProvider(const scoped_refptr<base::SequencedTaskRunner>& | |
| 57 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.
| |
| 58 std::unique_ptr<NetworkQualityEstimatorProvider> | |
| 59 network_quality_estimator_provider, | |
| 60 base::TaskRunner* io_task_runner); | |
| 61 | |
| 30 ~NetworkMetricsProvider() override; | 62 ~NetworkMetricsProvider() override; |
| 31 | 63 |
| 32 private: | 64 private: |
| 65 FRIEND_TEST_ALL_PREFIXES(NetworkMetricsProviderTest, EffectiveConnectionType); | |
| 66 | |
| 67 // Listens to the changes in the effective conection type. | |
| 68 class EffectiveConnectionTypeObserver; | |
| 69 | |
| 33 // MetricsProvider: | 70 // MetricsProvider: |
| 34 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override; | 71 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override; |
| 35 void ProvideSystemProfileMetrics(SystemProfileProto* system_profile) override; | 72 void ProvideSystemProfileMetrics(SystemProfileProto* system_profile) override; |
| 36 | 73 |
| 37 // ConnectionTypeObserver: | 74 // ConnectionTypeObserver: |
| 38 void OnConnectionTypeChanged( | 75 void OnConnectionTypeChanged( |
| 39 net::NetworkChangeNotifier::ConnectionType type) override; | 76 net::NetworkChangeNotifier::ConnectionType type) override; |
| 40 | 77 |
| 41 SystemProfileProto::Network::ConnectionType GetConnectionType() const; | 78 SystemProfileProto::Network::ConnectionType GetConnectionType() const; |
| 42 SystemProfileProto::Network::WifiPHYLayerProtocol GetWifiPHYLayerProtocol() | 79 SystemProfileProto::Network::WifiPHYLayerProtocol GetWifiPHYLayerProtocol() |
| 43 const; | 80 const; |
| 81 SystemProfileProto::Network::EffectiveConnectionType | |
| 82 GetEffectiveConnectionType() const; | |
| 44 | 83 |
| 45 // Posts a call to net::GetWifiPHYLayerProtocol on the blocking pool. | 84 // Posts a call to net::GetWifiPHYLayerProtocol on the blocking pool. |
| 46 void ProbeWifiPHYLayerProtocol(); | 85 void ProbeWifiPHYLayerProtocol(); |
| 47 // Callback from the blocking pool with the result of | 86 // Callback from the blocking pool with the result of |
| 48 // net::GetWifiPHYLayerProtocol. | 87 // net::GetWifiPHYLayerProtocol. |
| 49 void OnWifiPHYLayerProtocolResult(net::WifiPHYLayerProtocol mode); | 88 void OnWifiPHYLayerProtocolResult(net::WifiPHYLayerProtocol mode); |
| 50 | 89 |
| 51 // Writes info about the wireless access points that this system is | 90 // Writes info about the wireless access points that this system is |
| 52 // connected to. | 91 // connected to. |
| 53 void WriteWifiAccessPointProto( | 92 void WriteWifiAccessPointProto( |
| 54 const WifiAccessPointInfoProvider::WifiAccessPointInfo& info, | 93 const WifiAccessPointInfoProvider::WifiAccessPointInfo& info, |
| 55 SystemProfileProto::Network* network_proto); | 94 SystemProfileProto::Network* network_proto); |
| 56 | 95 |
| 57 // Logs metrics that are functions of other metrics being uploaded. | 96 // Logs metrics that are functions of other metrics being uploaded. |
| 58 void LogAggregatedMetrics(); | 97 void LogAggregatedMetrics(); |
| 59 | 98 |
| 99 // Notifies |this| that the effective connection type of the current network | |
| 100 // has changed to |type|. | |
| 101 void OnEffectiveConnectionTypeChanged(net::EffectiveConnectionType type); | |
| 102 | |
| 60 // Task runner used for blocking file I/O. | 103 // Task runner used for blocking file I/O. |
| 61 base::TaskRunner* io_task_runner_; | 104 base::TaskRunner* io_task_runner_; |
| 62 | 105 |
| 63 // True if |connection_type_| changed during the lifetime of the log. | 106 // True if |connection_type_| changed during the lifetime of the log. |
| 64 bool connection_type_is_ambiguous_; | 107 bool connection_type_is_ambiguous_; |
| 65 // The connection type according to net::NetworkChangeNotifier. | 108 // The connection type according to net::NetworkChangeNotifier. |
| 66 net::NetworkChangeNotifier::ConnectionType connection_type_; | 109 net::NetworkChangeNotifier::ConnectionType connection_type_; |
| 67 | 110 |
| 68 // True if |wifi_phy_layer_protocol_| changed during the lifetime of the log. | 111 // True if |wifi_phy_layer_protocol_| changed during the lifetime of the log. |
| 69 bool wifi_phy_layer_protocol_is_ambiguous_; | 112 bool wifi_phy_layer_protocol_is_ambiguous_; |
| 70 // The PHY mode of the currently associated access point obtained via | 113 // The PHY mode of the currently associated access point obtained via |
| 71 // net::GetWifiPHYLayerProtocol. | 114 // net::GetWifiPHYLayerProtocol. |
| 72 net::WifiPHYLayerProtocol wifi_phy_layer_protocol_; | 115 net::WifiPHYLayerProtocol wifi_phy_layer_protocol_; |
| 73 | 116 |
| 74 // Helper object for retrieving connected wifi access point information. | 117 // Helper object for retrieving connected wifi access point information. |
| 75 std::unique_ptr<WifiAccessPointInfoProvider> wifi_access_point_info_provider_; | 118 std::unique_ptr<WifiAccessPointInfoProvider> wifi_access_point_info_provider_; |
| 76 | 119 |
| 77 // These metrics track histogram totals for the Net.ErrorCodesForMainFrame3 | 120 // These metrics track histogram totals for the Net.ErrorCodesForMainFrame3 |
| 78 // histogram. They are used to compute deltas at upload time. | 121 // histogram. They are used to compute deltas at upload time. |
| 79 base::HistogramBase::Count total_aborts_; | 122 base::HistogramBase::Count total_aborts_; |
| 80 base::HistogramBase::Count total_codes_; | 123 base::HistogramBase::Count total_codes_; |
| 81 | 124 |
| 125 // Provides the network quality estimator. May be null. | |
| 126 std::unique_ptr<NetworkQualityEstimatorProvider> | |
| 127 network_quality_estimator_provider_; | |
| 128 | |
| 129 // Listens to the changes in the effective connection type. Initialized and | |
| 130 // destroyed using |network_quality_task_runner_|. May be null. | |
| 131 std::unique_ptr<EffectiveConnectionTypeObserver> | |
| 132 effective_connection_type_observer_; | |
| 133 | |
| 134 // Task runner using which |effective_connection_type_observer_| is | |
| 135 // initialized and destroyed. May be null. | |
| 136 scoped_refptr<base::SequencedTaskRunner> network_quality_task_runner_; | |
| 137 | |
| 138 // Last known effective connection type. | |
| 139 net::EffectiveConnectionType effective_connection_type_; | |
| 140 | |
| 141 // True if |effective_connection_type_| changed during the lifetime of the | |
| 142 // log. | |
| 143 bool effective_connection_type_is_ambiguous_; | |
| 144 | |
| 145 base::ThreadChecker thread_checker_; | |
| 146 | |
| 82 base::WeakPtrFactory<NetworkMetricsProvider> weak_ptr_factory_; | 147 base::WeakPtrFactory<NetworkMetricsProvider> weak_ptr_factory_; |
| 83 | 148 |
| 84 DISALLOW_COPY_AND_ASSIGN(NetworkMetricsProvider); | 149 DISALLOW_COPY_AND_ASSIGN(NetworkMetricsProvider); |
| 85 }; | 150 }; |
| 86 | 151 |
| 87 } // namespace metrics | 152 } // namespace metrics |
| 88 | 153 |
| 89 #endif // COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_ | 154 #endif // COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_ |
| OLD | NEW |