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