blob: d8ec213355acb2c7a3d77595780c56667fcc00b1 [file] [log] [blame]
[email protected]536324e2014-05-22 18:50:191// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
gunsch043f3602014-09-11 21:05:035#ifndef COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_
6#define COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_
[email protected]536324e2014-05-22 18:50:197
dchengd99c42a2016-04-21 21:54:138#include <memory>
9
avi26062922015-12-26 00:14:1810#include "base/macros.h"
[email protected]536324e2014-05-22 18:50:1911#include "base/memory/weak_ptr.h"
csharrison305ab902016-03-17 19:51:2712#include "base/metrics/histogram_base.h"
Gabriel Charette5ff87ce2017-05-16 18:03:4513#include "base/sequenced_task_runner.h"
tbansal9b3dd2bc2017-01-11 06:12:5914#include "base/threading/thread_checker.h"
[email protected]536324e2014-05-22 18:50:1915#include "components/metrics/metrics_provider.h"
gunsch043f3602014-09-11 21:05:0316#include "components/metrics/net/wifi_access_point_info_provider.h"
[email protected]536324e2014-05-22 18:50:1917#include "net/base/network_change_notifier.h"
olli.raula80a44be2015-09-01 07:41:5318#include "net/base/network_interfaces.h"
tbansal9b3dd2bc2017-01-11 06:12:5919#include "net/nqe/effective_connection_type.h"
Steven Holtef9d5ed62017-10-21 02:02:3020#include "third_party/metrics_proto/system_profile.pb.h"
tbansal9b3dd2bc2017-01-11 06:12:5921
22namespace net {
23class NetworkQualityEstimator;
24}
[email protected]536324e2014-05-22 18:50:1925
asvitkinea63d19e2014-10-24 16:19:3926namespace metrics {
27
Bryan McQuadea4aa9d62017-08-01 16:41:2928SystemProfileProto::Network::EffectiveConnectionType
29ConvertEffectiveConnectionType(
30 net::EffectiveConnectionType effective_connection_type);
31
[email protected]536324e2014-05-22 18:50:1932// Registers as observer with net::NetworkChangeNotifier and keeps track of
33// the network environment.
34class NetworkMetricsProvider
asvitkinea63d19e2014-10-24 16:19:3935 : public MetricsProvider,
[email protected]536324e2014-05-22 18:50:1936 public net::NetworkChangeNotifier::ConnectionTypeObserver {
37 public:
tbansal9b3dd2bc2017-01-11 06:12:5938 // Class that provides |this| with the network quality estimator.
39 class NetworkQualityEstimatorProvider {
40 public:
41 virtual ~NetworkQualityEstimatorProvider() {}
42
Tarun Bansal7e299f52017-08-16 20:12:2843 // Returns the network quality estimator by calling |io_callback|. The
44 // returned network quality estimator may be nullptr. |io_callback| must be
45 // called on the IO thread. |io_callback| can be destroyed on IO thread only
46 // after |this| is destroyed.
47 virtual void PostReplyNetworkQualityEstimator(
48 base::Callback<void(net::NetworkQualityEstimator*)> io_callback) = 0;
tbansal9b3dd2bc2017-01-11 06:12:5949
50 // Returns the task runner on which |this| should be used and destroyed.
51 virtual scoped_refptr<base::SequencedTaskRunner> GetTaskRunner() = 0;
52
53 protected:
54 NetworkQualityEstimatorProvider() {}
55
56 private:
57 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimatorProvider);
58 };
59
Alok Priyadarshidedafaa2017-06-21 17:08:5060 // Creates a NetworkMetricsProvider, where
61 // |network_quality_estimator_provider| should be set if it is useful to
62 // attach the quality of the network to the metrics report.
63 explicit NetworkMetricsProvider(
64 std::unique_ptr<NetworkQualityEstimatorProvider>
65 network_quality_estimator_provider = nullptr);
dcheng00ea022b2014-10-21 11:24:5666 ~NetworkMetricsProvider() override;
[email protected]536324e2014-05-22 18:50:1967
asvitkinebbde62b2014-09-03 16:33:2168 private:
tbansal9b3dd2bc2017-01-11 06:12:5969 FRIEND_TEST_ALL_PREFIXES(NetworkMetricsProviderTest, EffectiveConnectionType);
tbansale931fa7d2017-01-29 07:20:3970 FRIEND_TEST_ALL_PREFIXES(NetworkMetricsProviderTest,
71 ECTAmbiguousOnConnectionTypeChange);
Tarun Bansal3d1340e22017-08-09 22:11:3472 FRIEND_TEST_ALL_PREFIXES(NetworkMetricsProviderTest,
73 ECTNotAmbiguousOnOffline);
tbansal9b3dd2bc2017-01-11 06:12:5974
75 // Listens to the changes in the effective conection type.
76 class EffectiveConnectionTypeObserver;
77
asvitkinea63d19e2014-10-24 16:19:3978 // MetricsProvider:
Steven Holte141462ac2017-07-26 01:35:0779 void ProvideCurrentSessionData(
80 ChromeUserMetricsExtension* uma_proto) override;
asvitkinea63d19e2014-10-24 16:19:3981 void ProvideSystemProfileMetrics(SystemProfileProto* system_profile) override;
[email protected]536324e2014-05-22 18:50:1982
83 // ConnectionTypeObserver:
dcheng00ea022b2014-10-21 11:24:5684 void OnConnectionTypeChanged(
mostynbfe59f482014-10-06 15:04:4685 net::NetworkChangeNotifier::ConnectionType type) override;
[email protected]536324e2014-05-22 18:50:1986
asvitkinea63d19e2014-10-24 16:19:3987 SystemProfileProto::Network::ConnectionType GetConnectionType() const;
88 SystemProfileProto::Network::WifiPHYLayerProtocol GetWifiPHYLayerProtocol()
89 const;
[email protected]536324e2014-05-22 18:50:1990
91 // Posts a call to net::GetWifiPHYLayerProtocol on the blocking pool.
92 void ProbeWifiPHYLayerProtocol();
93 // Callback from the blocking pool with the result of
94 // net::GetWifiPHYLayerProtocol.
95 void OnWifiPHYLayerProtocolResult(net::WifiPHYLayerProtocol mode);
96
[email protected]24347892014-08-18 20:12:0797 // Writes info about the wireless access points that this system is
98 // connected to.
99 void WriteWifiAccessPointProto(
100 const WifiAccessPointInfoProvider::WifiAccessPointInfo& info,
asvitkinea63d19e2014-10-24 16:19:39101 SystemProfileProto::Network* network_proto);
[email protected]24347892014-08-18 20:12:07102
csharrison305ab902016-03-17 19:51:27103 // Logs metrics that are functions of other metrics being uploaded.
104 void LogAggregatedMetrics();
105
tbansal9b3dd2bc2017-01-11 06:12:59106 // Notifies |this| that the effective connection type of the current network
107 // has changed to |type|.
108 void OnEffectiveConnectionTypeChanged(net::EffectiveConnectionType type);
109
[email protected]536324e2014-05-22 18:50:19110 // True if |connection_type_| changed during the lifetime of the log.
111 bool connection_type_is_ambiguous_;
112 // The connection type according to net::NetworkChangeNotifier.
113 net::NetworkChangeNotifier::ConnectionType connection_type_;
114
115 // True if |wifi_phy_layer_protocol_| changed during the lifetime of the log.
116 bool wifi_phy_layer_protocol_is_ambiguous_;
117 // The PHY mode of the currently associated access point obtained via
118 // net::GetWifiPHYLayerProtocol.
119 net::WifiPHYLayerProtocol wifi_phy_layer_protocol_;
120
[email protected]24347892014-08-18 20:12:07121 // Helper object for retrieving connected wifi access point information.
dchengd99c42a2016-04-21 21:54:13122 std::unique_ptr<WifiAccessPointInfoProvider> wifi_access_point_info_provider_;
[email protected]24347892014-08-18 20:12:07123
csharrison305ab902016-03-17 19:51:27124 // These metrics track histogram totals for the Net.ErrorCodesForMainFrame3
125 // histogram. They are used to compute deltas at upload time.
126 base::HistogramBase::Count total_aborts_;
127 base::HistogramBase::Count total_codes_;
128
tbansal9b3dd2bc2017-01-11 06:12:59129 // Provides the network quality estimator. May be null.
130 std::unique_ptr<NetworkQualityEstimatorProvider>
131 network_quality_estimator_provider_;
132
133 // Listens to the changes in the effective connection type. Initialized and
Tarun Bansal7e299f52017-08-16 20:12:28134 // destroyed on the IO thread. May be null.
tbansal9b3dd2bc2017-01-11 06:12:59135 std::unique_ptr<EffectiveConnectionTypeObserver>
136 effective_connection_type_observer_;
137
tbansal9b3dd2bc2017-01-11 06:12:59138 // Last known effective connection type.
139 net::EffectiveConnectionType effective_connection_type_;
140
tbansalf71093f2017-06-23 21:29:55141 // Minimum and maximum effective connection type since the metrics were last
142 // provided.
143 net::EffectiveConnectionType min_effective_connection_type_;
144 net::EffectiveConnectionType max_effective_connection_type_;
tbansal9b3dd2bc2017-01-11 06:12:59145
146 base::ThreadChecker thread_checker_;
147
anujk.sharma59b968272014-09-16 16:52:38148 base::WeakPtrFactory<NetworkMetricsProvider> weak_ptr_factory_;
149
[email protected]536324e2014-05-22 18:50:19150 DISALLOW_COPY_AND_ASSIGN(NetworkMetricsProvider);
151};
152
asvitkinea63d19e2014-10-24 16:19:39153} // namespace metrics
154
gunsch043f3602014-09-11 21:05:03155#endif // COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_