blob: 1c23bea907ef9b31b39a35d36d43e5e03bb9edb6 [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"
tbansal9b3dd2bc2017-01-11 06:12:5913#include "base/threading/thread_checker.h"
[email protected]536324e2014-05-22 18:50:1914#include "components/metrics/metrics_provider.h"
gunsch043f3602014-09-11 21:05:0315#include "components/metrics/net/wifi_access_point_info_provider.h"
[email protected]536324e2014-05-22 18:50:1916#include "components/metrics/proto/system_profile.pb.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"
20
21namespace net {
22class NetworkQualityEstimator;
23}
[email protected]536324e2014-05-22 18:50:1924
asvitkinea63d19e2014-10-24 16:19:3925namespace metrics {
26
[email protected]536324e2014-05-22 18:50:1927// Registers as observer with net::NetworkChangeNotifier and keeps track of
28// the network environment.
29class NetworkMetricsProvider
asvitkinea63d19e2014-10-24 16:19:3930 : public MetricsProvider,
[email protected]536324e2014-05-22 18:50:1931 public net::NetworkChangeNotifier::ConnectionTypeObserver {
32 public:
tbansal9b3dd2bc2017-01-11 06:12:5933 // Class that provides |this| with the network quality estimator.
34 class NetworkQualityEstimatorProvider {
35 public:
36 virtual ~NetworkQualityEstimatorProvider() {}
37
38 // Returns the network quality estimator. May be nullptr.
39 virtual net::NetworkQualityEstimator* GetNetworkQualityEstimator() = 0;
40
41 // Returns the task runner on which |this| should be used and destroyed.
42 virtual scoped_refptr<base::SequencedTaskRunner> GetTaskRunner() = 0;
43
44 protected:
45 NetworkQualityEstimatorProvider() {}
46
47 private:
48 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimatorProvider);
49 };
50
gunsch043f3602014-09-11 21:05:0351 // Creates a NetworkMetricsProvider, where |io_task_runner| is used to post
52 // network info collection tasks.
53 explicit NetworkMetricsProvider(base::TaskRunner* io_task_runner);
tbansal9b3dd2bc2017-01-11 06:12:5954
55 // Creates a NetworkMetricsProvider, where |io_task_runner| is used to post
56 // network info collection tasks. |network_quality_estimator_provider|
57 // should be set if it is useful to attach the quality of the network to the
58 // metrics report.
59 NetworkMetricsProvider(std::unique_ptr<NetworkQualityEstimatorProvider>
60 network_quality_estimator_provider,
61 base::TaskRunner* io_task_runner);
62
dcheng00ea022b2014-10-21 11:24:5663 ~NetworkMetricsProvider() override;
[email protected]536324e2014-05-22 18:50:1964
asvitkinebbde62b2014-09-03 16:33:2165 private:
tbansal9b3dd2bc2017-01-11 06:12:5966 FRIEND_TEST_ALL_PREFIXES(NetworkMetricsProviderTest, EffectiveConnectionType);
tbansale931fa7d2017-01-29 07:20:3967 FRIEND_TEST_ALL_PREFIXES(NetworkMetricsProviderTest,
68 ECTAmbiguousOnConnectionTypeChange);
tbansal9b3dd2bc2017-01-11 06:12:5969
70 // Listens to the changes in the effective conection type.
71 class EffectiveConnectionTypeObserver;
72
asvitkinea63d19e2014-10-24 16:19:3973 // MetricsProvider:
bmcquade3f55de792016-02-26 22:10:3774 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override;
asvitkinea63d19e2014-10-24 16:19:3975 void ProvideSystemProfileMetrics(SystemProfileProto* system_profile) override;
[email protected]536324e2014-05-22 18:50:1976
77 // ConnectionTypeObserver:
dcheng00ea022b2014-10-21 11:24:5678 void OnConnectionTypeChanged(
mostynbfe59f482014-10-06 15:04:4679 net::NetworkChangeNotifier::ConnectionType type) override;
[email protected]536324e2014-05-22 18:50:1980
asvitkinea63d19e2014-10-24 16:19:3981 SystemProfileProto::Network::ConnectionType GetConnectionType() const;
82 SystemProfileProto::Network::WifiPHYLayerProtocol GetWifiPHYLayerProtocol()
83 const;
tbansal9b3dd2bc2017-01-11 06:12:5984 SystemProfileProto::Network::EffectiveConnectionType
85 GetEffectiveConnectionType() const;
[email protected]536324e2014-05-22 18:50:1986
87 // Posts a call to net::GetWifiPHYLayerProtocol on the blocking pool.
88 void ProbeWifiPHYLayerProtocol();
89 // Callback from the blocking pool with the result of
90 // net::GetWifiPHYLayerProtocol.
91 void OnWifiPHYLayerProtocolResult(net::WifiPHYLayerProtocol mode);
92
[email protected]24347892014-08-18 20:12:0793 // Writes info about the wireless access points that this system is
94 // connected to.
95 void WriteWifiAccessPointProto(
96 const WifiAccessPointInfoProvider::WifiAccessPointInfo& info,
asvitkinea63d19e2014-10-24 16:19:3997 SystemProfileProto::Network* network_proto);
[email protected]24347892014-08-18 20:12:0798
csharrison305ab902016-03-17 19:51:2799 // Logs metrics that are functions of other metrics being uploaded.
100 void LogAggregatedMetrics();
101
tbansal9b3dd2bc2017-01-11 06:12:59102 // Notifies |this| that the effective connection type of the current network
103 // has changed to |type|.
104 void OnEffectiveConnectionTypeChanged(net::EffectiveConnectionType type);
105
gunsch043f3602014-09-11 21:05:03106 // Task runner used for blocking file I/O.
107 base::TaskRunner* io_task_runner_;
108
[email protected]536324e2014-05-22 18:50:19109 // True if |connection_type_| changed during the lifetime of the log.
110 bool connection_type_is_ambiguous_;
111 // The connection type according to net::NetworkChangeNotifier.
112 net::NetworkChangeNotifier::ConnectionType connection_type_;
113
114 // True if |wifi_phy_layer_protocol_| changed during the lifetime of the log.
115 bool wifi_phy_layer_protocol_is_ambiguous_;
116 // The PHY mode of the currently associated access point obtained via
117 // net::GetWifiPHYLayerProtocol.
118 net::WifiPHYLayerProtocol wifi_phy_layer_protocol_;
119
[email protected]24347892014-08-18 20:12:07120 // Helper object for retrieving connected wifi access point information.
dchengd99c42a2016-04-21 21:54:13121 std::unique_ptr<WifiAccessPointInfoProvider> wifi_access_point_info_provider_;
[email protected]24347892014-08-18 20:12:07122
csharrison305ab902016-03-17 19:51:27123 // These metrics track histogram totals for the Net.ErrorCodesForMainFrame3
124 // histogram. They are used to compute deltas at upload time.
125 base::HistogramBase::Count total_aborts_;
126 base::HistogramBase::Count total_codes_;
127
tbansal9b3dd2bc2017-01-11 06:12:59128 // Provides the network quality estimator. May be null.
129 std::unique_ptr<NetworkQualityEstimatorProvider>
130 network_quality_estimator_provider_;
131
132 // Listens to the changes in the effective connection type. Initialized and
133 // destroyed using |network_quality_task_runner_|. May be null.
134 std::unique_ptr<EffectiveConnectionTypeObserver>
135 effective_connection_type_observer_;
136
137 // Task runner using which |effective_connection_type_observer_| is
138 // initialized and destroyed. May be null.
139 scoped_refptr<base::SequencedTaskRunner> network_quality_task_runner_;
140
141 // Last known effective connection type.
142 net::EffectiveConnectionType effective_connection_type_;
143
144 // True if |effective_connection_type_| changed during the lifetime of the
145 // log.
146 bool effective_connection_type_is_ambiguous_;
147
148 base::ThreadChecker thread_checker_;
149
anujk.sharma59b968272014-09-16 16:52:38150 base::WeakPtrFactory<NetworkMetricsProvider> weak_ptr_factory_;
151
[email protected]536324e2014-05-22 18:50:19152 DISALLOW_COPY_AND_ASSIGN(NetworkMetricsProvider);
153};
154
asvitkinea63d19e2014-10-24 16:19:39155} // namespace metrics
156
gunsch043f3602014-09-11 21:05:03157#endif // COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_