Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(506)

Side by Side Diff: components/metrics/net/network_metrics_provider.h

Issue 2605553002: Add EffectiveConnectionType enum to the system profile proto (Closed)
Patch Set: Rebased, ryansturm comments, fix failing chromeos test Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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:
27 // Creates a NetworkMetricsProvider, where |io_task_runner| is used to post 33 // Creates a NetworkMetricsProvider, where |io_task_runner| is used to post
28 // network info collection tasks. 34 // network info collection tasks.
29 explicit NetworkMetricsProvider(base::TaskRunner* io_task_runner); 35 explicit NetworkMetricsProvider(base::TaskRunner* io_task_runner);
36
37 // Sets the network quality estimator which can be accessed via |task_runner|.
38 void ProvideNetworkQualityEstimator(
39 net::NetworkQualityEstimator* network_quality_estimator,
Alexei Svitkine (slow) 2017/01/03 17:48:48 Non-const params should be last.
tbansal1 2017/01/03 18:55:43 Done.
40 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
41
30 ~NetworkMetricsProvider() override; 42 ~NetworkMetricsProvider() override;
31 43
32 private: 44 private:
45 FRIEND_TEST_ALL_PREFIXES(NetworkMetricsProviderTest, EffectiveConnectionType);
46
47 // Listens to the changes in the effective conection type.
48 class EffectiveConnectionTypeObserver;
49
33 // MetricsProvider: 50 // MetricsProvider:
34 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override; 51 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override;
35 void ProvideSystemProfileMetrics(SystemProfileProto* system_profile) override; 52 void ProvideSystemProfileMetrics(SystemProfileProto* system_profile) override;
36 53
37 // ConnectionTypeObserver: 54 // ConnectionTypeObserver:
38 void OnConnectionTypeChanged( 55 void OnConnectionTypeChanged(
39 net::NetworkChangeNotifier::ConnectionType type) override; 56 net::NetworkChangeNotifier::ConnectionType type) override;
40 57
41 SystemProfileProto::Network::ConnectionType GetConnectionType() const; 58 SystemProfileProto::Network::ConnectionType GetConnectionType() const;
42 SystemProfileProto::Network::WifiPHYLayerProtocol GetWifiPHYLayerProtocol() 59 SystemProfileProto::Network::WifiPHYLayerProtocol GetWifiPHYLayerProtocol()
43 const; 60 const;
61 SystemProfileProto::Network::EffectiveConnectionType
62 GetEffectiveConnectionType() const;
44 63
45 // Posts a call to net::GetWifiPHYLayerProtocol on the blocking pool. 64 // Posts a call to net::GetWifiPHYLayerProtocol on the blocking pool.
46 void ProbeWifiPHYLayerProtocol(); 65 void ProbeWifiPHYLayerProtocol();
47 // Callback from the blocking pool with the result of 66 // Callback from the blocking pool with the result of
48 // net::GetWifiPHYLayerProtocol. 67 // net::GetWifiPHYLayerProtocol.
49 void OnWifiPHYLayerProtocolResult(net::WifiPHYLayerProtocol mode); 68 void OnWifiPHYLayerProtocolResult(net::WifiPHYLayerProtocol mode);
50 69
51 // Writes info about the wireless access points that this system is 70 // Writes info about the wireless access points that this system is
52 // connected to. 71 // connected to.
53 void WriteWifiAccessPointProto( 72 void WriteWifiAccessPointProto(
54 const WifiAccessPointInfoProvider::WifiAccessPointInfo& info, 73 const WifiAccessPointInfoProvider::WifiAccessPointInfo& info,
55 SystemProfileProto::Network* network_proto); 74 SystemProfileProto::Network* network_proto);
56 75
57 // Logs metrics that are functions of other metrics being uploaded. 76 // Logs metrics that are functions of other metrics being uploaded.
58 void LogAggregatedMetrics(); 77 void LogAggregatedMetrics();
59 78
79 // Notifies |this| that the effective connection type of the current network
80 // has changed to |type|.
81 void OnEffectiveConnectionTypeChanged(net::EffectiveConnectionType type);
82
60 // Task runner used for blocking file I/O. 83 // Task runner used for blocking file I/O.
61 base::TaskRunner* io_task_runner_; 84 base::TaskRunner* io_task_runner_;
62 85
63 // True if |connection_type_| changed during the lifetime of the log. 86 // True if |connection_type_| changed during the lifetime of the log.
64 bool connection_type_is_ambiguous_; 87 bool connection_type_is_ambiguous_;
65 // The connection type according to net::NetworkChangeNotifier. 88 // The connection type according to net::NetworkChangeNotifier.
66 net::NetworkChangeNotifier::ConnectionType connection_type_; 89 net::NetworkChangeNotifier::ConnectionType connection_type_;
67 90
68 // True if |wifi_phy_layer_protocol_| changed during the lifetime of the log. 91 // True if |wifi_phy_layer_protocol_| changed during the lifetime of the log.
69 bool wifi_phy_layer_protocol_is_ambiguous_; 92 bool wifi_phy_layer_protocol_is_ambiguous_;
70 // The PHY mode of the currently associated access point obtained via 93 // The PHY mode of the currently associated access point obtained via
71 // net::GetWifiPHYLayerProtocol. 94 // net::GetWifiPHYLayerProtocol.
72 net::WifiPHYLayerProtocol wifi_phy_layer_protocol_; 95 net::WifiPHYLayerProtocol wifi_phy_layer_protocol_;
73 96
74 // Helper object for retrieving connected wifi access point information. 97 // Helper object for retrieving connected wifi access point information.
75 std::unique_ptr<WifiAccessPointInfoProvider> wifi_access_point_info_provider_; 98 std::unique_ptr<WifiAccessPointInfoProvider> wifi_access_point_info_provider_;
76 99
77 // These metrics track histogram totals for the Net.ErrorCodesForMainFrame3 100 // These metrics track histogram totals for the Net.ErrorCodesForMainFrame3
78 // histogram. They are used to compute deltas at upload time. 101 // histogram. They are used to compute deltas at upload time.
79 base::HistogramBase::Count total_aborts_; 102 base::HistogramBase::Count total_aborts_;
80 base::HistogramBase::Count total_codes_; 103 base::HistogramBase::Count total_codes_;
81 104
105 // Listens to the changes in the effective connection type. Initialized and
106 // destroyed using |network_quality_task_runner_|.
107 std::unique_ptr<EffectiveConnectionTypeObserver>
108 effective_connection_type_observer_;
109
110 // Task runner using which |effective_connection_type_observer_| is
111 // initialized and destroyed.
112 scoped_refptr<base::SequencedTaskRunner> network_quality_task_runner_;
113
114 // Last known effective connection type.
115 net::EffectiveConnectionType effective_connection_type_;
116
117 // True if |effective_connection_type_| changed during the lifetime of the
118 // log.
119 bool effective_connection_type_is_ambiguous_;
120
121 base::ThreadChecker thread_checker_;
122
82 base::WeakPtrFactory<NetworkMetricsProvider> weak_ptr_factory_; 123 base::WeakPtrFactory<NetworkMetricsProvider> weak_ptr_factory_;
83 124
84 DISALLOW_COPY_AND_ASSIGN(NetworkMetricsProvider); 125 DISALLOW_COPY_AND_ASSIGN(NetworkMetricsProvider);
85 }; 126 };
86 127
87 } // namespace metrics 128 } // namespace metrics
88 129
89 #endif // COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_ 130 #endif // COMPONENTS_METRICS_NET_NETWORK_METRICS_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698