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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 void NetworkMetricsProvider::ProvideSystemProfileMetrics( | 43 void NetworkMetricsProvider::ProvideSystemProfileMetrics( |
44 SystemProfileProto* system_profile) { | 44 SystemProfileProto* system_profile) { |
45 SystemProfileProto::Network* network = system_profile->mutable_network(); | 45 SystemProfileProto::Network* network = system_profile->mutable_network(); |
46 network->set_connection_type_is_ambiguous(connection_type_is_ambiguous_); | 46 network->set_connection_type_is_ambiguous(connection_type_is_ambiguous_); |
47 network->set_connection_type(GetConnectionType()); | 47 network->set_connection_type(GetConnectionType()); |
48 network->set_wifi_phy_layer_protocol_is_ambiguous( | 48 network->set_wifi_phy_layer_protocol_is_ambiguous( |
49 wifi_phy_layer_protocol_is_ambiguous_); | 49 wifi_phy_layer_protocol_is_ambiguous_); |
50 network->set_wifi_phy_layer_protocol(GetWifiPHYLayerProtocol()); | 50 network->set_wifi_phy_layer_protocol(GetWifiPHYLayerProtocol()); |
51 | 51 |
52 // Resets the "ambiguous" flags, since a new metrics log session has started. | 52 // Update the connection type. Note that this is necessary to set the network |
| 53 // type to "none" if there is no network connection for an entire UMA logging |
| 54 // window, since OnConnectionTypeChanged() ignores transitions to the "none" |
| 55 // state. |
| 56 connection_type_ = net::NetworkChangeNotifier::GetConnectionType(); |
| 57 // Reset the "ambiguous" flags, since a new metrics log session has started. |
53 connection_type_is_ambiguous_ = false; | 58 connection_type_is_ambiguous_ = false; |
54 // TODO(isherman): This line seems unnecessary. | |
55 connection_type_ = net::NetworkChangeNotifier::GetConnectionType(); | |
56 wifi_phy_layer_protocol_is_ambiguous_ = false; | 59 wifi_phy_layer_protocol_is_ambiguous_ = false; |
57 | 60 |
58 if (!wifi_access_point_info_provider_.get()) { | 61 if (!wifi_access_point_info_provider_.get()) { |
59 #if defined(OS_CHROMEOS) | 62 #if defined(OS_CHROMEOS) |
60 wifi_access_point_info_provider_.reset( | 63 wifi_access_point_info_provider_.reset( |
61 new WifiAccessPointInfoProviderChromeos()); | 64 new WifiAccessPointInfoProviderChromeos()); |
62 #else | 65 #else |
63 wifi_access_point_info_provider_.reset( | 66 wifi_access_point_info_provider_.reset( |
64 new WifiAccessPointInfoProvider()); | 67 new WifiAccessPointInfoProvider()); |
65 #endif // OS_CHROMEOS | 68 #endif // OS_CHROMEOS |
66 } | 69 } |
67 | 70 |
68 // Connected wifi access point information. | 71 // Connected wifi access point information. |
69 WifiAccessPointInfoProvider::WifiAccessPointInfo info; | 72 WifiAccessPointInfoProvider::WifiAccessPointInfo info; |
70 if (wifi_access_point_info_provider_->GetInfo(&info)) | 73 if (wifi_access_point_info_provider_->GetInfo(&info)) |
71 WriteWifiAccessPointProto(info, network); | 74 WriteWifiAccessPointProto(info, network); |
72 } | 75 } |
73 | 76 |
74 void NetworkMetricsProvider::OnConnectionTypeChanged( | 77 void NetworkMetricsProvider::OnConnectionTypeChanged( |
75 net::NetworkChangeNotifier::ConnectionType type) { | 78 net::NetworkChangeNotifier::ConnectionType type) { |
| 79 // To avoid reporting an ambiguous connection type for users on flaky |
| 80 // connections, ignore transitions to the "none" state. Note that the |
| 81 // connection type is refreshed in ProvideSystemProfileMetrics() each time a |
| 82 // new UMA logging window begins, so users who genuinely transition to offline |
| 83 // mode for an extended duration will still be at least partially represented |
| 84 // in the metrics logs. |
76 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) | 85 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) |
77 return; | 86 return; |
| 87 |
78 if (type != connection_type_ && | 88 if (type != connection_type_ && |
79 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) { | 89 connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE) { |
80 connection_type_is_ambiguous_ = true; | 90 connection_type_is_ambiguous_ = true; |
81 } | 91 } |
82 connection_type_ = type; | 92 connection_type_ = type; |
83 | 93 |
84 ProbeWifiPHYLayerProtocol(); | 94 ProbeWifiPHYLayerProtocol(); |
85 } | 95 } |
86 | 96 |
87 SystemProfileProto::Network::ConnectionType | 97 SystemProfileProto::Network::ConnectionType |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 void NetworkMetricsProvider::GetIsCellularConnection(bool* is_cellular_out) { | 251 void NetworkMetricsProvider::GetIsCellularConnection(bool* is_cellular_out) { |
242 *is_cellular_out = IsCellularConnection(); | 252 *is_cellular_out = IsCellularConnection(); |
243 } | 253 } |
244 | 254 |
245 base::Callback<void(bool*)> NetworkMetricsProvider::GetConnectionCallback() { | 255 base::Callback<void(bool*)> NetworkMetricsProvider::GetConnectionCallback() { |
246 return base::Bind(&NetworkMetricsProvider::GetIsCellularConnection, | 256 return base::Bind(&NetworkMetricsProvider::GetIsCellularConnection, |
247 weak_ptr_factory_.GetWeakPtr()); | 257 weak_ptr_factory_.GetWeakPtr()); |
248 } | 258 } |
249 | 259 |
250 } // namespace metrics | 260 } // namespace metrics |
OLD | NEW |