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