summaryrefslogtreecommitdiffstats
path: root/chromium/net/base/network_change_notifier.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/net/base/network_change_notifier.cc')
-rw-r--r--chromium/net/base/network_change_notifier.cc93
1 files changed, 87 insertions, 6 deletions
diff --git a/chromium/net/base/network_change_notifier.cc b/chromium/net/base/network_change_notifier.cc
index fad9440c5bf..c55be07d731 100644
--- a/chromium/net/base/network_change_notifier.cc
+++ b/chromium/net/base/network_change_notifier.cc
@@ -6,6 +6,7 @@
#include "base/metrics/histogram.h"
#include "base/synchronization/lock.h"
+#include "base/threading/thread_checker.h"
#include "build/build_config.h"
#include "net/base/net_util.h"
#include "net/base/network_change_notifier_factory.h"
@@ -13,6 +14,12 @@
#include "net/url_request/url_request.h"
#include "url/gurl.h"
+#if defined(OS_ANDROID)
+#include "base/metrics/sparse_histogram.h"
+#include "base/strings/string_number_conversions.h"
+#include "net/android/network_library.h"
+#endif
+
#if defined(OS_WIN)
#include "net/base/network_change_notifier_win.h"
#elif defined(OS_LINUX) && !defined(OS_CHROMEOS)
@@ -66,16 +73,26 @@ class HistogramWatcher
// because the only other interface, |NotifyDataReceived| is also
// only called from the network thread.
void Init() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(g_network_change_notifier);
NetworkChangeNotifier::AddConnectionTypeObserver(this);
NetworkChangeNotifier::AddIPAddressObserver(this);
NetworkChangeNotifier::AddDNSObserver(this);
NetworkChangeNotifier::AddNetworkChangeObserver(this);
}
- virtual ~HistogramWatcher() {}
+ virtual ~HistogramWatcher() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(g_network_change_notifier);
+ NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
+ NetworkChangeNotifier::RemoveIPAddressObserver(this);
+ NetworkChangeNotifier::RemoveDNSObserver(this);
+ NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
+ }
// NetworkChangeNotifier::IPAddressObserver implementation.
virtual void OnIPAddressChanged() OVERRIDE {
+ DCHECK(thread_checker_.CalledOnValidThread());
UMA_HISTOGRAM_MEDIUM_TIMES("NCN.IPAddressChange",
SinceLast(&last_ip_address_change_));
UMA_HISTOGRAM_MEDIUM_TIMES(
@@ -86,6 +103,7 @@ class HistogramWatcher
// NetworkChangeNotifier::ConnectionTypeObserver implementation.
virtual void OnConnectionTypeChanged(
NetworkChangeNotifier::ConnectionType type) OVERRIDE {
+ DCHECK(thread_checker_.CalledOnValidThread());
base::TimeTicks now = base::TimeTicks::Now();
int32 kilobytes_read = bytes_read_since_last_connection_change_ / 1000;
base::TimeDelta state_duration = SinceLast(&last_connection_change_);
@@ -133,6 +151,11 @@ class HistogramWatcher
UMA_HISTOGRAM_TIMES("NCN.CM.FastestRTTOnNone",
fastest_RTT_since_last_connection_change_);
break;
+ case NetworkChangeNotifier::CONNECTION_BLUETOOTH:
+ UMA_HISTOGRAM_TIMES("NCN.CM.FirstReadOnBluetooth",
+ first_byte_after_connection_change_);
+ UMA_HISTOGRAM_TIMES("NCN.CM.FastestRTTOnBluetooth",
+ fastest_RTT_since_last_connection_change_);
}
}
if (peak_kbps_since_last_connection_change_) {
@@ -165,6 +188,10 @@ class HistogramWatcher
UMA_HISTOGRAM_COUNTS("NCN.CM.PeakKbpsOnNone",
peak_kbps_since_last_connection_change_);
break;
+ case NetworkChangeNotifier::CONNECTION_BLUETOOTH:
+ UMA_HISTOGRAM_COUNTS("NCN.CM.PeakKbpsOnBluetooth",
+ peak_kbps_since_last_connection_change_);
+ break;
}
}
switch (last_connection_type_) {
@@ -196,6 +223,10 @@ class HistogramWatcher
UMA_HISTOGRAM_LONG_TIMES("NCN.CM.TimeOnNone", state_duration);
UMA_HISTOGRAM_COUNTS("NCN.CM.KBTransferedOnNone", kilobytes_read);
break;
+ case NetworkChangeNotifier::CONNECTION_BLUETOOTH:
+ UMA_HISTOGRAM_LONG_TIMES("NCN.CM.TimeOnBluetooth", state_duration);
+ UMA_HISTOGRAM_COUNTS("NCN.CM.KBTransferedOnBluetooth", kilobytes_read);
+ break;
}
if (type != NetworkChangeNotifier::CONNECTION_NONE) {
@@ -216,6 +247,9 @@ class HistogramWatcher
} else {
UMA_HISTOGRAM_MEDIUM_TIMES("NCN.OfflineChange", state_duration);
}
+
+ NetworkChangeNotifier::LogOperatorCodeHistogram(type);
+
UMA_HISTOGRAM_MEDIUM_TIMES(
"NCN.IPAddressChangeToConnectionTypeChange",
now - last_ip_address_change_);
@@ -229,6 +263,7 @@ class HistogramWatcher
// NetworkChangeNotifier::DNSObserver implementation.
virtual void OnDNSChanged() OVERRIDE {
+ DCHECK(thread_checker_.CalledOnValidThread());
UMA_HISTOGRAM_MEDIUM_TIMES("NCN.DNSConfigChange",
SinceLast(&last_dns_change_));
}
@@ -236,6 +271,7 @@ class HistogramWatcher
// NetworkChangeNotifier::NetworkChangeObserver implementation.
virtual void OnNetworkChanged(
NetworkChangeNotifier::ConnectionType type) OVERRIDE {
+ DCHECK(thread_checker_.CalledOnValidThread());
if (type != NetworkChangeNotifier::CONNECTION_NONE) {
UMA_HISTOGRAM_MEDIUM_TIMES("NCN.NetworkOnlineChange",
SinceLast(&last_network_change_));
@@ -248,6 +284,7 @@ class HistogramWatcher
// Record histogram data whenever we receive a packet. Should only be called
// from the network thread.
void NotifyDataReceived(const URLRequest& request, int bytes_read) {
+ DCHECK(thread_checker_.CalledOnValidThread());
if (IsLocalhost(request.url().host()) ||
!request.url().SchemeIsHTTPOrHTTPS()) {
return;
@@ -337,6 +374,8 @@ class HistogramWatcher
// Erring on the conservative side is hopefully offset by taking the maximum.
int32 peak_kbps_since_last_connection_change_;
+ base::ThreadChecker thread_checker_;
+
DISALLOW_COPY_AND_ASSIGN(HistogramWatcher);
};
@@ -377,17 +416,22 @@ class NetworkChangeNotifier::NetworkChangeCalculator
pending_connection_type_(CONNECTION_NONE) {}
void Init() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(g_network_change_notifier);
AddConnectionTypeObserver(this);
AddIPAddressObserver(this);
}
virtual ~NetworkChangeCalculator() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(g_network_change_notifier);
RemoveConnectionTypeObserver(this);
RemoveIPAddressObserver(this);
}
// NetworkChangeNotifier::IPAddressObserver implementation.
virtual void OnIPAddressChanged() OVERRIDE {
+ DCHECK(thread_checker_.CalledOnValidThread());
base::TimeDelta delay = last_announced_connection_type_ == CONNECTION_NONE
? params_.ip_address_offline_delay_ : params_.ip_address_online_delay_;
// Cancels any previous timer.
@@ -396,6 +440,7 @@ class NetworkChangeNotifier::NetworkChangeCalculator
// NetworkChangeNotifier::ConnectionTypeObserver implementation.
virtual void OnConnectionTypeChanged(ConnectionType type) OVERRIDE {
+ DCHECK(thread_checker_.CalledOnValidThread());
pending_connection_type_ = type;
base::TimeDelta delay = last_announced_connection_type_ == CONNECTION_NONE
? params_.connection_type_offline_delay_
@@ -406,6 +451,7 @@ class NetworkChangeNotifier::NetworkChangeCalculator
private:
void Notify() {
+ DCHECK(thread_checker_.CalledOnValidThread());
// Don't bother signaling about dead connections.
if (have_announced_ &&
(last_announced_connection_type_ == CONNECTION_NONE) &&
@@ -432,9 +478,14 @@ class NetworkChangeNotifier::NetworkChangeCalculator
ConnectionType pending_connection_type_;
// Used to delay notifications so duplicates can be combined.
base::OneShotTimer<NetworkChangeCalculator> timer_;
+
+ base::ThreadChecker thread_checker_;
+
+ DISALLOW_COPY_AND_ASSIGN(NetworkChangeCalculator);
};
NetworkChangeNotifier::~NetworkChangeNotifier() {
+ network_change_calculator_.reset();
DCHECK_EQ(this, g_network_change_notifier);
g_network_change_notifier = NULL;
}
@@ -502,13 +553,14 @@ const char* NetworkChangeNotifier::ConnectionTypeToString(
"CONNECTION_2G",
"CONNECTION_3G",
"CONNECTION_4G",
- "CONNECTION_NONE"
+ "CONNECTION_NONE",
+ "CONNECTION_BLUETOOTH"
};
COMPILE_ASSERT(
arraysize(kConnectionTypeNames) ==
- NetworkChangeNotifier::CONNECTION_NONE + 1,
+ NetworkChangeNotifier::CONNECTION_LAST + 1,
ConnectionType_name_count_mismatch);
- if (type < CONNECTION_UNKNOWN || type > CONNECTION_NONE) {
+ if (type < CONNECTION_UNKNOWN || type > CONNECTION_LAST) {
NOTREACHED();
return "CONNECTION_INVALID";
}
@@ -518,8 +570,10 @@ const char* NetworkChangeNotifier::ConnectionTypeToString(
// static
void NetworkChangeNotifier::NotifyDataReceived(const URLRequest& request,
int bytes_read) {
- if (!g_network_change_notifier)
+ if (!g_network_change_notifier ||
+ !g_network_change_notifier->histogram_watcher_) {
return;
+ }
g_network_change_notifier->histogram_watcher_->NotifyDataReceived(request,
bytes_read);
}
@@ -528,9 +582,36 @@ void NetworkChangeNotifier::NotifyDataReceived(const URLRequest& request,
void NetworkChangeNotifier::InitHistogramWatcher() {
if (!g_network_change_notifier)
return;
+ g_network_change_notifier->histogram_watcher_.reset(new HistogramWatcher());
g_network_change_notifier->histogram_watcher_->Init();
}
+// static
+void NetworkChangeNotifier::ShutdownHistogramWatcher() {
+ if (!g_network_change_notifier)
+ return;
+ g_network_change_notifier->histogram_watcher_.reset();
+}
+
+// static
+void NetworkChangeNotifier::LogOperatorCodeHistogram(ConnectionType type) {
+#if defined(OS_ANDROID)
+ // On a connection type change to 2/3/4G, log the network operator MCC/MNC.
+ // Log zero in other cases.
+ unsigned mcc_mnc = 0;
+ if (type == NetworkChangeNotifier::CONNECTION_2G ||
+ type == NetworkChangeNotifier::CONNECTION_3G ||
+ type == NetworkChangeNotifier::CONNECTION_4G) {
+ // Log zero if not perfectly converted.
+ if (!base::StringToUint(
+ net::android::GetTelephonyNetworkOperator(), &mcc_mnc)) {
+ mcc_mnc = 0;
+ }
+ }
+ UMA_HISTOGRAM_SPARSE_SLOWLY("NCN.NetworkOperatorMCCMNC", mcc_mnc);
+#endif
+}
+
#if defined(OS_LINUX)
// static
const internal::AddressTrackerLinux*
@@ -558,6 +639,7 @@ bool NetworkChangeNotifier::IsConnectionCellular(ConnectionType type) {
case CONNECTION_ETHERNET:
case CONNECTION_WIFI:
case CONNECTION_NONE:
+ case CONNECTION_BLUETOOTH:
is_cellular = false;
break;
}
@@ -644,7 +726,6 @@ NetworkChangeNotifier::NetworkChangeNotifier(
new ObserverListThreadSafe<NetworkChangeObserver>(
ObserverListBase<NetworkChangeObserver>::NOTIFY_EXISTING_ONLY)),
network_state_(new NetworkState()),
- histogram_watcher_(new HistogramWatcher()),
network_change_calculator_(new NetworkChangeCalculator(params)) {
DCHECK(!g_network_change_notifier);
g_network_change_notifier = this;