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

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

Issue 2605553002: Add EffectiveConnectionType enum to the system profile proto (Closed)
Patch Set: Update proto, Use interface, pass in ctor 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 #include "components/metrics/net/network_metrics_provider.h" 5 #include "components/metrics/net/network_metrics_provider.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind_helpers.h"
13 #include "base/callback_forward.h"
12 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
13 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
14 #include "base/metrics/sparse_histogram.h" 16 #include "base/metrics/sparse_histogram.h"
15 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_split.h" 18 #include "base/strings/string_split.h"
17 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
18 #include "base/task_runner_util.h" 20 #include "base/task_runner_util.h"
19 #include "build/build_config.h" 21 #include "build/build_config.h"
20 #include "net/base/net_errors.h" 22 #include "net/base/net_errors.h"
23 #include "net/nqe/network_quality_estimator.h"
21 24
22 #if defined(OS_CHROMEOS) 25 #if defined(OS_CHROMEOS)
23 #include "components/metrics/net/wifi_access_point_info_provider_chromeos.h" 26 #include "components/metrics/net/wifi_access_point_info_provider_chromeos.h"
24 #endif // OS_CHROMEOS 27 #endif // OS_CHROMEOS
25 28
26 namespace metrics { 29 namespace metrics {
27 30
28 NetworkMetricsProvider::NetworkMetricsProvider(base::TaskRunner* io_task_runner) 31 // Listens to the changes in the effective conection type.
32 class NetworkMetricsProvider::EffectiveConnectionTypeObserver
33 : public net::NetworkQualityEstimator::EffectiveConnectionTypeObserver {
34 public:
35 // |network_quality_estimator| is used to provide the network quality
36 // estimates. Guaranteed to be non-null. |callback| is run on
37 // |callback_task_runner|, and provides notifications about the changes in the
38 // effective connection type.
39 EffectiveConnectionTypeObserver(
40 base::Callback<void(net::EffectiveConnectionType)> callback,
41 const scoped_refptr<base::SequencedTaskRunner>& callback_task_runner)
42 : network_quality_estimator_(nullptr),
43 callback_(callback),
44 callback_task_runner_(callback_task_runner) {
45 DCHECK(callback_);
46 DCHECK(callback_task_runner_);
47 // |this| is initialized and used on the IO thread using
48 // |network_quality_task_runner_|.
49 thread_checker_.DetachFromThread();
50 }
51
52 ~EffectiveConnectionTypeObserver() override {
53 DCHECK(thread_checker_.CalledOnValidThread());
54 if (network_quality_estimator_)
55 network_quality_estimator_->RemoveEffectiveConnectionTypeObserver(this);
56 }
57
58 // Initializes |this| on IO thread using |network_quality_task_runner_|. This
59 // is the same thread on which |network_quality_estimator| lives.
60 void Init(net::NetworkQualityEstimator* network_quality_estimator) {
61 network_quality_estimator_ = network_quality_estimator;
62 if (network_quality_estimator_)
63 network_quality_estimator_->AddEffectiveConnectionTypeObserver(this);
64 }
65
66 private:
67 // net::EffectiveConnectionTypeObserver implementation:
68 void OnEffectiveConnectionTypeChanged(
69 net::EffectiveConnectionType type) override {
70 DCHECK(thread_checker_.CalledOnValidThread());
71 callback_task_runner_->PostTask(FROM_HERE, base::Bind(callback_, type));
72 }
73
74 // Notifies |this| when there is a change in the effective connection type.
75 net::NetworkQualityEstimator* network_quality_estimator_;
76
77 // Called when the effective connection type is changed.
78 base::Callback<void(net::EffectiveConnectionType)> callback_;
79
80 // Task runner on which |callback_| is run.
81 scoped_refptr<base::SequencedTaskRunner> callback_task_runner_;
82
83 base::ThreadChecker thread_checker_;
84
85 DISALLOW_COPY_AND_ASSIGN(EffectiveConnectionTypeObserver);
86 };
87
88 NetworkMetricsProvider::NetworkMetricsProvider(
89 const scoped_refptr<base::SequencedTaskRunner>& network_quality_task_runner,
90 std::unique_ptr<NetworkQualityEstimatorProvider>
91 network_quality_estimator_provider,
92 base::TaskRunner* io_task_runner)
29 : io_task_runner_(io_task_runner), 93 : io_task_runner_(io_task_runner),
30 connection_type_is_ambiguous_(false), 94 connection_type_is_ambiguous_(false),
31 wifi_phy_layer_protocol_is_ambiguous_(false), 95 wifi_phy_layer_protocol_is_ambiguous_(false),
32 wifi_phy_layer_protocol_(net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN), 96 wifi_phy_layer_protocol_(net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN),
33 total_aborts_(0), 97 total_aborts_(0),
34 total_codes_(0), 98 total_codes_(0),
99 network_quality_estimator_provider_(
100 std::move(network_quality_estimator_provider)),
101 network_quality_task_runner_(network_quality_task_runner),
102 effective_connection_type_(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
103 effective_connection_type_is_ambiguous_(false),
35 weak_ptr_factory_(this) { 104 weak_ptr_factory_(this) {
36 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); 105 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
37 connection_type_ = net::NetworkChangeNotifier::GetConnectionType(); 106 connection_type_ = net::NetworkChangeNotifier::GetConnectionType();
38 ProbeWifiPHYLayerProtocol(); 107 ProbeWifiPHYLayerProtocol();
108
109 if (network_quality_estimator_provider_ && network_quality_task_runner_) {
110 effective_connection_type_observer_.reset(
111 new EffectiveConnectionTypeObserver(
112 base::Bind(
113 &NetworkMetricsProvider::OnEffectiveConnectionTypeChanged,
114 base::Unretained(this)),
115 base::ThreadTaskRunnerHandle::Get()));
116
117 // Get the network quality estimator and initialize
118 // |effective_connection_type_observer_| on the same task runner on which
119 // the network quality estimator lives. It is safe to use base::Unretained
120 // here since both |network_quality_estimator_provider_| and
121 // |effective_connection_type_observer_| are owned by |this|, and are
122 // deleted on the |network_quality_task_runner_|.
123 network_quality_task_runner_->PostTask(
124 FROM_HERE,
125 base::Bind(&NetworkQualityEstimatorProvider::ProvideEstimator,
126 base::Unretained(network_quality_estimator_provider_.get()),
127 base::Bind(&EffectiveConnectionTypeObserver::Init,
128 base::Unretained(
129 effective_connection_type_observer_.get()))));
130 }
39 } 131 }
40 132
41 NetworkMetricsProvider::~NetworkMetricsProvider() { 133 NetworkMetricsProvider::~NetworkMetricsProvider() {
134 DCHECK(thread_checker_.CalledOnValidThread());
42 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); 135 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
136 if (effective_connection_type_observer_ &&
137 !network_quality_task_runner_->DeleteSoon(
138 FROM_HERE, effective_connection_type_observer_.release())) {
139 NOTREACHED() << " ECT observer was not deleted successfully";
140 }
141 if (network_quality_estimator_provider_ &&
142 !network_quality_task_runner_->DeleteSoon(
143 FROM_HERE, network_quality_estimator_provider_.release())) {
144 NOTREACHED()
145 << " Network quality estimate provider was not deleted successfully";
146 }
43 } 147 }
44 148
45 void NetworkMetricsProvider::ProvideGeneralMetrics( 149 void NetworkMetricsProvider::ProvideGeneralMetrics(
46 ChromeUserMetricsExtension*) { 150 ChromeUserMetricsExtension*) {
151 DCHECK(thread_checker_.CalledOnValidThread());
47 // ProvideGeneralMetrics is called on the main thread, at the time a metrics 152 // ProvideGeneralMetrics is called on the main thread, at the time a metrics
48 // record is being finalized. 153 // record is being finalized.
49 net::NetworkChangeNotifier::FinalizingMetricsLogRecord(); 154 net::NetworkChangeNotifier::FinalizingMetricsLogRecord();
50 LogAggregatedMetrics(); 155 LogAggregatedMetrics();
51 } 156 }
52 157
53 void NetworkMetricsProvider::ProvideSystemProfileMetrics( 158 void NetworkMetricsProvider::ProvideSystemProfileMetrics(
54 SystemProfileProto* system_profile) { 159 SystemProfileProto* system_profile) {
160 DCHECK(thread_checker_.CalledOnValidThread());
55 SystemProfileProto::Network* network = system_profile->mutable_network(); 161 SystemProfileProto::Network* network = system_profile->mutable_network();
56 network->set_connection_type_is_ambiguous(connection_type_is_ambiguous_); 162 network->set_connection_type_is_ambiguous(connection_type_is_ambiguous_);
57 network->set_connection_type(GetConnectionType()); 163 network->set_connection_type(GetConnectionType());
58 network->set_wifi_phy_layer_protocol_is_ambiguous( 164 network->set_wifi_phy_layer_protocol_is_ambiguous(
59 wifi_phy_layer_protocol_is_ambiguous_); 165 wifi_phy_layer_protocol_is_ambiguous_);
60 network->set_wifi_phy_layer_protocol(GetWifiPHYLayerProtocol()); 166 network->set_wifi_phy_layer_protocol(GetWifiPHYLayerProtocol());
167 network->set_effective_connection_type(GetEffectiveConnectionType());
61 168
62 // Update the connection type. Note that this is necessary to set the network 169 // Update the connection type. Note that this is necessary to set the network
63 // type to "none" if there is no network connection for an entire UMA logging 170 // type to "none" if there is no network connection for an entire UMA logging
64 // window, since OnConnectionTypeChanged() ignores transitions to the "none" 171 // window, since OnConnectionTypeChanged() ignores transitions to the "none"
65 // state. 172 // state.
66 connection_type_ = net::NetworkChangeNotifier::GetConnectionType(); 173 connection_type_ = net::NetworkChangeNotifier::GetConnectionType();
67 // Reset the "ambiguous" flags, since a new metrics log session has started. 174 // Reset the "ambiguous" flags, since a new metrics log session has started.
68 connection_type_is_ambiguous_ = false; 175 connection_type_is_ambiguous_ = false;
69 wifi_phy_layer_protocol_is_ambiguous_ = false; 176 wifi_phy_layer_protocol_is_ambiguous_ = false;
177 effective_connection_type_is_ambiguous_ = false;
70 178
71 if (!wifi_access_point_info_provider_.get()) { 179 if (!wifi_access_point_info_provider_.get()) {
72 #if defined(OS_CHROMEOS) 180 #if defined(OS_CHROMEOS)
73 wifi_access_point_info_provider_.reset( 181 wifi_access_point_info_provider_.reset(
74 new WifiAccessPointInfoProviderChromeos()); 182 new WifiAccessPointInfoProviderChromeos());
75 #else 183 #else
76 wifi_access_point_info_provider_.reset( 184 wifi_access_point_info_provider_.reset(
77 new WifiAccessPointInfoProvider()); 185 new WifiAccessPointInfoProvider());
78 #endif // OS_CHROMEOS 186 #endif // OS_CHROMEOS
79 } 187 }
80 188
81 // Connected wifi access point information. 189 // Connected wifi access point information.
82 WifiAccessPointInfoProvider::WifiAccessPointInfo info; 190 WifiAccessPointInfoProvider::WifiAccessPointInfo info;
83 if (wifi_access_point_info_provider_->GetInfo(&info)) 191 if (wifi_access_point_info_provider_->GetInfo(&info))
84 WriteWifiAccessPointProto(info, network); 192 WriteWifiAccessPointProto(info, network);
85 } 193 }
86 194
87 void NetworkMetricsProvider::OnConnectionTypeChanged( 195 void NetworkMetricsProvider::OnConnectionTypeChanged(
88 net::NetworkChangeNotifier::ConnectionType type) { 196 net::NetworkChangeNotifier::ConnectionType type) {
197 DCHECK(thread_checker_.CalledOnValidThread());
89 // To avoid reporting an ambiguous connection type for users on flaky 198 // To avoid reporting an ambiguous connection type for users on flaky
90 // connections, ignore transitions to the "none" state. Note that the 199 // connections, ignore transitions to the "none" state. Note that the
91 // connection type is refreshed in ProvideSystemProfileMetrics() each time a 200 // connection type is refreshed in ProvideSystemProfileMetrics() each time a
92 // new UMA logging window begins, so users who genuinely transition to offline 201 // new UMA logging window begins, so users who genuinely transition to offline
93 // mode for an extended duration will still be at least partially represented 202 // mode for an extended duration will still be at least partially represented
94 // in the metrics logs. 203 // in the metrics logs.
95 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) 204 if (type == net::NetworkChangeNotifier::CONNECTION_NONE)
96 return; 205 return;
97 206
98 if (type != connection_type_ && 207 if (type != connection_type_ &&
99 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) { 208 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) {
100 connection_type_is_ambiguous_ = true; 209 connection_type_is_ambiguous_ = true;
101 } 210 }
102 connection_type_ = type; 211 connection_type_ = type;
103 212
104 ProbeWifiPHYLayerProtocol(); 213 ProbeWifiPHYLayerProtocol();
105 } 214 }
106 215
107 SystemProfileProto::Network::ConnectionType 216 SystemProfileProto::Network::ConnectionType
108 NetworkMetricsProvider::GetConnectionType() const { 217 NetworkMetricsProvider::GetConnectionType() const {
218 DCHECK(thread_checker_.CalledOnValidThread());
109 switch (connection_type_) { 219 switch (connection_type_) {
110 case net::NetworkChangeNotifier::CONNECTION_NONE: 220 case net::NetworkChangeNotifier::CONNECTION_NONE:
111 return SystemProfileProto::Network::CONNECTION_NONE; 221 return SystemProfileProto::Network::CONNECTION_NONE;
112 case net::NetworkChangeNotifier::CONNECTION_UNKNOWN: 222 case net::NetworkChangeNotifier::CONNECTION_UNKNOWN:
113 return SystemProfileProto::Network::CONNECTION_UNKNOWN; 223 return SystemProfileProto::Network::CONNECTION_UNKNOWN;
114 case net::NetworkChangeNotifier::CONNECTION_ETHERNET: 224 case net::NetworkChangeNotifier::CONNECTION_ETHERNET:
115 return SystemProfileProto::Network::CONNECTION_ETHERNET; 225 return SystemProfileProto::Network::CONNECTION_ETHERNET;
116 case net::NetworkChangeNotifier::CONNECTION_WIFI: 226 case net::NetworkChangeNotifier::CONNECTION_WIFI:
117 return SystemProfileProto::Network::CONNECTION_WIFI; 227 return SystemProfileProto::Network::CONNECTION_WIFI;
118 case net::NetworkChangeNotifier::CONNECTION_2G: 228 case net::NetworkChangeNotifier::CONNECTION_2G:
119 return SystemProfileProto::Network::CONNECTION_2G; 229 return SystemProfileProto::Network::CONNECTION_2G;
120 case net::NetworkChangeNotifier::CONNECTION_3G: 230 case net::NetworkChangeNotifier::CONNECTION_3G:
121 return SystemProfileProto::Network::CONNECTION_3G; 231 return SystemProfileProto::Network::CONNECTION_3G;
122 case net::NetworkChangeNotifier::CONNECTION_4G: 232 case net::NetworkChangeNotifier::CONNECTION_4G:
123 return SystemProfileProto::Network::CONNECTION_4G; 233 return SystemProfileProto::Network::CONNECTION_4G;
124 case net::NetworkChangeNotifier::CONNECTION_BLUETOOTH: 234 case net::NetworkChangeNotifier::CONNECTION_BLUETOOTH:
125 return SystemProfileProto::Network::CONNECTION_BLUETOOTH; 235 return SystemProfileProto::Network::CONNECTION_BLUETOOTH;
126 } 236 }
127 NOTREACHED(); 237 NOTREACHED();
128 return SystemProfileProto::Network::CONNECTION_UNKNOWN; 238 return SystemProfileProto::Network::CONNECTION_UNKNOWN;
129 } 239 }
130 240
131 SystemProfileProto::Network::WifiPHYLayerProtocol 241 SystemProfileProto::Network::WifiPHYLayerProtocol
132 NetworkMetricsProvider::GetWifiPHYLayerProtocol() const { 242 NetworkMetricsProvider::GetWifiPHYLayerProtocol() const {
243 DCHECK(thread_checker_.CalledOnValidThread());
133 switch (wifi_phy_layer_protocol_) { 244 switch (wifi_phy_layer_protocol_) {
134 case net::WIFI_PHY_LAYER_PROTOCOL_NONE: 245 case net::WIFI_PHY_LAYER_PROTOCOL_NONE:
135 return SystemProfileProto::Network::WIFI_PHY_LAYER_PROTOCOL_NONE; 246 return SystemProfileProto::Network::WIFI_PHY_LAYER_PROTOCOL_NONE;
136 case net::WIFI_PHY_LAYER_PROTOCOL_ANCIENT: 247 case net::WIFI_PHY_LAYER_PROTOCOL_ANCIENT:
137 return SystemProfileProto::Network::WIFI_PHY_LAYER_PROTOCOL_ANCIENT; 248 return SystemProfileProto::Network::WIFI_PHY_LAYER_PROTOCOL_ANCIENT;
138 case net::WIFI_PHY_LAYER_PROTOCOL_A: 249 case net::WIFI_PHY_LAYER_PROTOCOL_A:
139 return SystemProfileProto::Network::WIFI_PHY_LAYER_PROTOCOL_A; 250 return SystemProfileProto::Network::WIFI_PHY_LAYER_PROTOCOL_A;
140 case net::WIFI_PHY_LAYER_PROTOCOL_B: 251 case net::WIFI_PHY_LAYER_PROTOCOL_B:
141 return SystemProfileProto::Network::WIFI_PHY_LAYER_PROTOCOL_B; 252 return SystemProfileProto::Network::WIFI_PHY_LAYER_PROTOCOL_B;
142 case net::WIFI_PHY_LAYER_PROTOCOL_G: 253 case net::WIFI_PHY_LAYER_PROTOCOL_G:
143 return SystemProfileProto::Network::WIFI_PHY_LAYER_PROTOCOL_G; 254 return SystemProfileProto::Network::WIFI_PHY_LAYER_PROTOCOL_G;
144 case net::WIFI_PHY_LAYER_PROTOCOL_N: 255 case net::WIFI_PHY_LAYER_PROTOCOL_N:
145 return SystemProfileProto::Network::WIFI_PHY_LAYER_PROTOCOL_N; 256 return SystemProfileProto::Network::WIFI_PHY_LAYER_PROTOCOL_N;
146 case net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN: 257 case net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN:
147 return SystemProfileProto::Network::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN; 258 return SystemProfileProto::Network::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN;
148 } 259 }
149 NOTREACHED(); 260 NOTREACHED();
150 return SystemProfileProto::Network::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN; 261 return SystemProfileProto::Network::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN;
151 } 262 }
152 263
264 SystemProfileProto::Network::EffectiveConnectionType
265 NetworkMetricsProvider::GetEffectiveConnectionType() const {
266 DCHECK(thread_checker_.CalledOnValidThread());
267
268 if (effective_connection_type_is_ambiguous_)
269 return SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_AMBIGUOUS;
270
271 switch (effective_connection_type_) {
272 case net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN:
273 return SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
274 case net::EFFECTIVE_CONNECTION_TYPE_OFFLINE:
275 return SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_OFFLINE;
276 case net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G:
277 return SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_SLOW_2G;
278 case net::EFFECTIVE_CONNECTION_TYPE_2G:
279 return SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_2G;
280 case net::EFFECTIVE_CONNECTION_TYPE_3G:
281 return SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_3G;
282 case net::EFFECTIVE_CONNECTION_TYPE_4G:
283 return SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_4G;
284 case net::EFFECTIVE_CONNECTION_TYPE_LAST:
285 NOTREACHED();
286 return SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
287 }
288 NOTREACHED();
289 return SystemProfileProto::Network::EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
290 }
291
153 void NetworkMetricsProvider::ProbeWifiPHYLayerProtocol() { 292 void NetworkMetricsProvider::ProbeWifiPHYLayerProtocol() {
293 DCHECK(thread_checker_.CalledOnValidThread());
154 PostTaskAndReplyWithResult( 294 PostTaskAndReplyWithResult(
155 io_task_runner_, 295 io_task_runner_,
156 FROM_HERE, 296 FROM_HERE,
157 base::Bind(&net::GetWifiPHYLayerProtocol), 297 base::Bind(&net::GetWifiPHYLayerProtocol),
158 base::Bind(&NetworkMetricsProvider::OnWifiPHYLayerProtocolResult, 298 base::Bind(&NetworkMetricsProvider::OnWifiPHYLayerProtocolResult,
159 weak_ptr_factory_.GetWeakPtr())); 299 weak_ptr_factory_.GetWeakPtr()));
160 } 300 }
161 301
162 void NetworkMetricsProvider::OnWifiPHYLayerProtocolResult( 302 void NetworkMetricsProvider::OnWifiPHYLayerProtocolResult(
163 net::WifiPHYLayerProtocol mode) { 303 net::WifiPHYLayerProtocol mode) {
304 DCHECK(thread_checker_.CalledOnValidThread());
164 if (wifi_phy_layer_protocol_ != net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN && 305 if (wifi_phy_layer_protocol_ != net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN &&
165 mode != wifi_phy_layer_protocol_) { 306 mode != wifi_phy_layer_protocol_) {
166 wifi_phy_layer_protocol_is_ambiguous_ = true; 307 wifi_phy_layer_protocol_is_ambiguous_ = true;
167 } 308 }
168 wifi_phy_layer_protocol_ = mode; 309 wifi_phy_layer_protocol_ = mode;
169 } 310 }
170 311
171 void NetworkMetricsProvider::WriteWifiAccessPointProto( 312 void NetworkMetricsProvider::WriteWifiAccessPointProto(
172 const WifiAccessPointInfoProvider::WifiAccessPointInfo& info, 313 const WifiAccessPointInfoProvider::WifiAccessPointInfo& info,
173 SystemProfileProto::Network* network_proto) { 314 SystemProfileProto::Network* network_proto) {
315 DCHECK(thread_checker_.CalledOnValidThread());
174 SystemProfileProto::Network::WifiAccessPoint* access_point_info = 316 SystemProfileProto::Network::WifiAccessPoint* access_point_info =
175 network_proto->mutable_access_point_info(); 317 network_proto->mutable_access_point_info();
176 SystemProfileProto::Network::WifiAccessPoint::SecurityMode security = 318 SystemProfileProto::Network::WifiAccessPoint::SecurityMode security =
177 SystemProfileProto::Network::WifiAccessPoint::SECURITY_UNKNOWN; 319 SystemProfileProto::Network::WifiAccessPoint::SECURITY_UNKNOWN;
178 switch (info.security) { 320 switch (info.security) {
179 case WifiAccessPointInfoProvider::WIFI_SECURITY_NONE: 321 case WifiAccessPointInfoProvider::WIFI_SECURITY_NONE:
180 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_NONE; 322 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_NONE;
181 break; 323 break;
182 case WifiAccessPointInfoProvider::WIFI_SECURITY_WPA: 324 case WifiAccessPointInfoProvider::WIFI_SECURITY_WPA:
183 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_WPA; 325 security = SystemProfileProto::Network::WifiAccessPoint::SECURITY_WPA;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 info.oui_list, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { 381 info.oui_list, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
240 uint32_t oui; 382 uint32_t oui;
241 if (base::HexStringToUInt(oui_str, &oui)) 383 if (base::HexStringToUInt(oui_str, &oui))
242 vendor->add_element_identifier(oui); 384 vendor->add_element_identifier(oui);
243 else 385 else
244 NOTREACHED(); 386 NOTREACHED();
245 } 387 }
246 } 388 }
247 389
248 void NetworkMetricsProvider::LogAggregatedMetrics() { 390 void NetworkMetricsProvider::LogAggregatedMetrics() {
391 DCHECK(thread_checker_.CalledOnValidThread());
249 base::HistogramBase* error_codes = base::SparseHistogram::FactoryGet( 392 base::HistogramBase* error_codes = base::SparseHistogram::FactoryGet(
250 "Net.ErrorCodesForMainFrame3", 393 "Net.ErrorCodesForMainFrame3",
251 base::HistogramBase::kUmaTargetedHistogramFlag); 394 base::HistogramBase::kUmaTargetedHistogramFlag);
252 std::unique_ptr<base::HistogramSamples> samples = 395 std::unique_ptr<base::HistogramSamples> samples =
253 error_codes->SnapshotSamples(); 396 error_codes->SnapshotSamples();
254 base::HistogramBase::Count new_aborts = 397 base::HistogramBase::Count new_aborts =
255 samples->GetCount(-net::ERR_ABORTED) - total_aborts_; 398 samples->GetCount(-net::ERR_ABORTED) - total_aborts_;
256 base::HistogramBase::Count new_codes = samples->TotalCount() - total_codes_; 399 base::HistogramBase::Count new_codes = samples->TotalCount() - total_codes_;
257 if (new_codes > 0) { 400 if (new_codes > 0) {
258 UMA_HISTOGRAM_COUNTS("Net.ErrAborted.CountPerUpload", new_aborts); 401 UMA_HISTOGRAM_COUNTS("Net.ErrAborted.CountPerUpload", new_aborts);
259 UMA_HISTOGRAM_PERCENTAGE("Net.ErrAborted.ProportionPerUpload", 402 UMA_HISTOGRAM_PERCENTAGE("Net.ErrAborted.ProportionPerUpload",
260 (100 * new_aborts) / new_codes); 403 (100 * new_aborts) / new_codes);
261 total_codes_ += new_codes; 404 total_codes_ += new_codes;
262 total_aborts_ += new_aborts; 405 total_aborts_ += new_aborts;
263 } 406 }
264 } 407 }
265 408
409 void NetworkMetricsProvider::OnEffectiveConnectionTypeChanged(
410 net::EffectiveConnectionType type) {
411 DCHECK(thread_checker_.CalledOnValidThread());
412 if (effective_connection_type_ != type &&
413 type != net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN &&
414 effective_connection_type_ != net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {
415 effective_connection_type_is_ambiguous_ = true;
416 }
417 effective_connection_type_ = type;
418 }
419
266 } // namespace metrics 420 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698